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