java 小fire_Java Material.fire方法代码示例

import net.minecraft.block.material.Material; //导入方法依赖的package包/类

@Override

public void onImpact(MovingObjectPosition target)

{

if (target.entityHit != null) // hit a entity

{

target.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.shootingEntity), (float) 0);// No dmg, but knockback

target.entityHit.hurtResistantTime = 0;

target.entityHit.setFire(fireDuration); // Some minor fire, for flavor

}

else // hit the terrain

{

int plusX = 0;

int plusY = 0;

int plusZ = 0;

int posiX = target.blockX;

int posiY = target.blockY;

int posiZ = target.blockZ;

//Block targetBlock = this.worldObj.getBlock(posiX, posiY, posiZ);

// Is the attached block a valid material?

boolean canPlace = false;

if ( Helper.hasValidMaterial(this.worldObj, posiX, posiY, posiZ) ) { canPlace = true; }

// Glass breaking

if ( Helper.tryBlockBreak(this.worldObj, this, target, 0)) { canPlace = false; }

if (target.sideHit == 0) { plusY = -1; } // Bottom

else if (target.sideHit == 1) { plusY = 1; } // Top

else if (target.sideHit == 2) { plusZ = -1; } // East

else if (target.sideHit == 3){ plusZ = 1; } // West

else if (target.sideHit == 4){ plusX = -1; } // North

else if (target.sideHit == 5) { plusX = 1; } // South

// Is the space free?

if (this.worldObj.getBlock( (int)posiX + plusX, (int)posiY + plusY, (int)posiZ + plusZ).getMaterial() == Material.air ||

this.worldObj.getBlock( (int)posiX + plusX, (int)posiY + plusY, (int)posiZ + plusZ).getMaterial() == Material.fire ||

this.worldObj.getBlock( (int)posiX + plusX, (int)posiY + plusY, (int)posiZ + plusZ).getMaterial() == Material.grass ||

this.worldObj.getBlock( (int)posiX + plusX, (int)posiY + plusY, (int)posiZ + plusZ).getMaterial() == Material.snow ||

this.worldObj.getBlock( (int)posiX + plusX, (int)posiY + plusY, (int)posiZ + plusZ).getMaterial() == Material.water)

{

// Putting light there (if we can)

if (canPlace)

{

this.worldObj.setBlock(posiX + plusX, posiY + plusY, posiZ + plusZ, Main.fenLight, 0, 3);

this.worldObj.setBlockMetadataWithNotify(posiX + plusX, posiY + plusY, posiZ + plusZ, target.sideHit, 3);

if (this.lightTick != 0)

{

this.worldObj.scheduleBlockUpdate(posiX + plusX, posiY + plusY, posiZ + plusZ, Main.fenLight, this.lightTick);

}

// else, stays on indefinitely

}

// else, can't place. The block isn't of a valid material

}

// else, none of the allowed materials

}

// SFX

for (int i = 0; i < 8; ++i) { this.worldObj.spawnParticle("slime", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D); }

this.worldObj.playSoundAtEntity(this, Block.soundTypeGlass.getBreakSound(), 1.0F, 1.0F);

this.setDead();// We've hit something, so begone with the projectile

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值