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