    001    package net.minecraft.src;
    002
    003    import java.util.Random;
    004
    005    public class BlockTNT extends Block
    006    {
    007        public BlockTNT(int par1, int par2)
    008        {
    009            super(par1, par2, Material.tnt);
    010            this.setCreativeTab(CreativeTabs.tabRedstone);
    011        }
    012
    013        /**
    014         * Returns the block texture based on the side being looked at.  Args: side
    015         */
    016        public int getBlockTextureFromSide(int par1)
    017        {
    018            return par1 == 0 ? this.blockIndexInTexture + 2 : (par1 == 1 ? this.blockIndexInTexture + 1 : this.blockIndexInTexture);
    019        }
    020
    021        /**
    022         * Called whenever the block is added into the world. Args: world, x, y, z
    023         */
    024        public void onBlockAdded(World par1World, int par2, int par3, int par4)
    025        {
    026            super.onBlockAdded(par1World, par2, par3, par4);
    027
    028            if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
    029            {
    030                this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
    031                par1World.setBlockWithNotify(par2, par3, par4, 0);
    032            }
    033        }
    034
    035        /**
    036         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    037         * their own) Args: x, y, z, neighbor blockID
    038         */
    039        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    040        {
    041            if (par5 > 0 && Block.blocksList[par5].canProvidePower() && par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
    042            {
    043                this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
    044                par1World.setBlockWithNotify(par2, par3, par4, 0);
    045            }
    046        }
    047
    048        /**
    049         * Returns the quantity of items to drop on block destruction.
    050         */
    051        public int quantityDropped(Random par1Random)
    052        {
    053            return 1;
    054        }
    055
    056        /**
    057         * Called upon the block being destroyed by an explosion
    058         */
    059        public void onBlockDestroyedByExplosion(World par1World, int par2, int par3, int par4)
    060        {
    061            if (!par1World.isRemote)
    062            {
    063                EntityTNTPrimed var5 = new EntityTNTPrimed(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F));
    064                var5.fuse = par1World.rand.nextInt(var5.fuse / 4) + var5.fuse / 8;
    065                par1World.spawnEntityInWorld(var5);
    066            }
    067        }
    068
    069        /**
    070         * Called right before the block is destroyed by a player.  Args: world, x, y, z, metaData
    071         */
    072        public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5)
    073        {
    074            if (!par1World.isRemote)
    075            {
    076                if ((par5 & 1) == 1)
    077                {
    078                    EntityTNTPrimed var6 = new EntityTNTPrimed(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F));
    079                    par1World.spawnEntityInWorld(var6);
    080                    par1World.playSoundAtEntity(var6, "random.fuse", 1.0F, 1.0F);
    081                }
    082            }
    083        }
    084
    085        /**
    086         * Called upon block activation (right click on the block.)
    087         */
    088        public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    089        {
    090            if (par5EntityPlayer.getCurrentEquippedItem() != null && par5EntityPlayer.getCurrentEquippedItem().itemID == Item.flintAndSteel.shiftedIndex)
    091            {
    092                this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
    093                par1World.setBlockWithNotify(par2, par3, par4, 0);
    094                return true;
    095            }
    096            else
    097            {
    098                return super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9);
    099            }
    100        }
    101
    102        /**
    103         * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
    104         */
    105        public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity)
    106        {
    107            if (par5Entity instanceof EntityArrow && !par1World.isRemote)
    108            {
    109                EntityArrow var6 = (EntityArrow)par5Entity;
    110
    111                if (var6.isBurning())
    112                {
    113                    this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
    114                    par1World.setBlockWithNotify(par2, par3, par4, 0);
    115                }
    116            }
    117        }
    118
    119        public boolean func_85103_a(Explosion par1Explosion)
    120        {
    121            return false;
    122        }
    123    }