001 package net.minecraft.src;
002
003 import cpw.mods.fml.common.Side;
004 import cpw.mods.fml.common.asm.SideOnly;
005
006 public class EntityTNTPrimed extends Entity
007 {
008 /** How long the fuse is */
009 public int fuse;
010
011 public EntityTNTPrimed(World par1World)
012 {
013 super(par1World);
014 this.fuse = 0;
015 this.preventEntitySpawning = true;
016 this.setSize(0.98F, 0.98F);
017 this.yOffset = this.height / 2.0F;
018 }
019
020 public EntityTNTPrimed(World par1World, double par2, double par4, double par6)
021 {
022 this(par1World);
023 this.setPosition(par2, par4, par6);
024 float var8 = (float)(Math.random() * Math.PI * 2.0D);
025 this.motionX = (double)(-((float)Math.sin((double)var8)) * 0.02F);
026 this.motionY = 0.20000000298023224D;
027 this.motionZ = (double)(-((float)Math.cos((double)var8)) * 0.02F);
028 this.fuse = 80;
029 this.prevPosX = par2;
030 this.prevPosY = par4;
031 this.prevPosZ = par6;
032 }
033
034 protected void entityInit() {}
035
036 /**
037 * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
038 * prevent them from trampling crops
039 */
040 protected boolean canTriggerWalking()
041 {
042 return false;
043 }
044
045 /**
046 * Returns true if other Entities should be prevented from moving through this Entity.
047 */
048 public boolean canBeCollidedWith()
049 {
050 return !this.isDead;
051 }
052
053 /**
054 * Called to update the entity's position/logic.
055 */
056 public void onUpdate()
057 {
058 this.prevPosX = this.posX;
059 this.prevPosY = this.posY;
060 this.prevPosZ = this.posZ;
061 this.motionY -= 0.03999999910593033D;
062 this.moveEntity(this.motionX, this.motionY, this.motionZ);
063 this.motionX *= 0.9800000190734863D;
064 this.motionY *= 0.9800000190734863D;
065 this.motionZ *= 0.9800000190734863D;
066
067 if (this.onGround)
068 {
069 this.motionX *= 0.699999988079071D;
070 this.motionZ *= 0.699999988079071D;
071 this.motionY *= -0.5D;
072 }
073
074 if (this.fuse-- <= 0)
075 {
076 this.setDead();
077
078 if (!this.worldObj.isRemote)
079 {
080 this.explode();
081 }
082 }
083 else
084 {
085 this.worldObj.spawnParticle("smoke", this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D);
086 }
087 }
088
089 private void explode()
090 {
091 float var1 = 4.0F;
092 this.worldObj.createExplosion((Entity)null, this.posX, this.posY, this.posZ, var1);
093 }
094
095 /**
096 * (abstract) Protected helper method to write subclass entity data to NBT.
097 */
098 protected void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
099 {
100 par1NBTTagCompound.setByte("Fuse", (byte)this.fuse);
101 }
102
103 /**
104 * (abstract) Protected helper method to read subclass entity data from NBT.
105 */
106 protected void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
107 {
108 this.fuse = par1NBTTagCompound.getByte("Fuse");
109 }
110
111 @SideOnly(Side.CLIENT)
112 public float getShadowSize()
113 {
114 return 0.0F;
115 }
116 }