JAVA刷TNT_Java Blocks.tnt方法代码示例
import net.minecraft.init.Blocks; //導入方法依賴的package包/類
@Override
public void onImpact(MovingObjectPosition target)// Server-side
{
if (target.entityHit != null) // Hit a entity
{
// Damage
target.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.shootingEntity), (float)this.damage);
target.entityHit.hurtResistantTime = 0; // No immunity frames
// Knockback
double f3 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
if (f3 > 0.0F)
{
target.entityHit.addVelocity(
this.motionX * (double)this.knockbackStrength * 0.6000000238418579D / (double)f3,
0.1D,
this.motionZ * (double)this.knockbackStrength * 0.6000000238418579D / (double)f3
);
}
// Effect
if ( !(target.entityHit instanceof EntityEnderman) ) { target.entityHit.setFire(this.fireDuration); }
this.setDead();
}
else // Hit a block
{
Block block = this.worldObj.getBlock(target.blockX, target.blockY, target.blockZ);
// Glass breaking, once
if (Helper.tryBlockBreak(this.worldObj, this, target, 1) && this.targetsHit < 1) { this.targetsHit += 1; }
else { this.setDead(); }// else, either we didn't break that block or we already hit one entity
// Let's ignite TNT explicitly here.
if (block == Blocks.tnt)
{
this.worldObj.setBlockToAir(target.blockX, target.blockY, target.blockZ); // setBlockToAir
EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(this.worldObj,
(double)((float)target.blockX + 0.5F),
(double)((float)target.blockY + 0.5F),
(double)((float)target.blockZ + 0.5F),
this.shootingEntity);
this.worldObj.spawnEntityInWorld(entitytntprimed);// This is TNT, so begone with that block and replace it with primed TNT
this.worldObj.playSoundAtEntity(entitytntprimed, "random.fuse", 1.0F, 1.0F);
}
// else, block is not TNT
}
if (!this.isInWater()) // Only explode if we're not in water
{
boolean griefing = true;// Allowed by default
if (this.shootingEntity instanceof EntityPlayer)
{
griefing = this.dmgTerrain;// It's up to player settings to allow/forbid this
}
else
{
griefing = this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing");// Are we allowed to break things?
}
this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, (float) this.explosionSize, griefing);
// 4.0F is TNT, false is for "not flaming"
// Editchevsky: Actually, false is double-used for "don't damage terrain"
}
}
總結
以上是生活随笔為你收集整理的JAVA刷TNT_Java Blocks.tnt方法代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 花呗可以转账吗
- 下一篇: 中国海军陆战队喜提15式坦克