    001    package net.minecraft.block;
    002
    003    import cpw.mods.fml.relauncher.Side;
    004    import cpw.mods.fml.relauncher.SideOnly;
    005    import java.util.List;
    006    import java.util.Random;
    007    import net.minecraft.block.material.Material;
    008    import net.minecraft.creativetab.CreativeTabs;
    009    import net.minecraft.entity.monster.EntitySilverfish;
    010    import net.minecraft.item.ItemStack;
    011    import net.minecraft.world.World;
    012
    013    public class BlockSilverfish extends Block
    014    {
    015        /** Block names that can be a silverfish stone. */
    016        public static final String[] silverfishStoneTypes = new String[] {"stone", "cobble", "brick"};
    017
    018        public BlockSilverfish(int par1)
    019        {
    020            super(par1, 1, Material.clay);
    021            this.setHardness(0.0F);
    022            this.setCreativeTab(CreativeTabs.tabDecorations);
    023        }
    024
    025        /**
    026         * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
    027         */
    028        public int getBlockTextureFromSideAndMetadata(int par1, int par2)
    029        {
    030            return par2 == 1 ? Block.cobblestone.blockIndexInTexture : (par2 == 2 ? Block.stoneBrick.blockIndexInTexture : Block.stone.blockIndexInTexture);
    031        }
    032
    033        /**
    034         * Called right before the block is destroyed by a player.  Args: world, x, y, z, metaData
    035         */
    036        public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5)
    037        {
    038            if (!par1World.isRemote)
    039            {
    040                EntitySilverfish var6 = new EntitySilverfish(par1World);
    041                var6.setLocationAndAngles((double)par2 + 0.5D, (double)par3, (double)par4 + 0.5D, 0.0F, 0.0F);
    042                par1World.spawnEntityInWorld(var6);
    043                var6.spawnExplosionParticle();
    044            }
    045
    046            super.onBlockDestroyedByPlayer(par1World, par2, par3, par4, par5);
    047        }
    048
    049        /**
    050         * Returns the quantity of items to drop on block destruction.
    051         */
    052        public int quantityDropped(Random par1Random)
    053        {
    054            return 0;
    055        }
    056
    057        /**
    058         * Gets the blockID of the block this block is pretending to be according to this block's metadata.
    059         */
    060        public static boolean getPosingIdByMetadata(int par0)
    061        {
    062            return par0 == Block.stone.blockID || par0 == Block.cobblestone.blockID || par0 == Block.stoneBrick.blockID;
    063        }
    064
    065        /**
    066         * Returns the metadata to use when a Silverfish hides in the block. Sets the block to BlockSilverfish with this
    067         * metadata. It changes the displayed texture client side to look like a normal block.
    068         */
    069        public static int getMetadataForBlockType(int par0)
    070        {
    071            return par0 == Block.cobblestone.blockID ? 1 : (par0 == Block.stoneBrick.blockID ? 2 : 0);
    072        }
    073
    074        /**
    075         * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
    076         * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
    077         */
    078        protected ItemStack createStackedBlock(int par1)
    079        {
    080            Block var2 = Block.stone;
    081
    082            if (par1 == 1)
    083            {
    084                var2 = Block.cobblestone;
    085            }
    086
    087            if (par1 == 2)
    088            {
    089                var2 = Block.stoneBrick;
    090            }
    091
    092            return new ItemStack(var2);
    093        }
    094
    095        /**
    096         * Get the block's damage value (for use with pick block).
    097         */
    098        public int getDamageValue(World par1World, int par2, int par3, int par4)
    099        {
    100            return par1World.getBlockMetadata(par2, par3, par4);
    101        }
    102
    103        @SideOnly(Side.CLIENT)
    104
    105        /**
    106         * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
    107         */
    108        public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
    109        {
    110            for (int var4 = 0; var4 < 3; ++var4)
    111            {
    112                par3List.add(new ItemStack(par1, 1, var4));
    113            }
    114        }
    115    }