001package net.minecraft.block;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005
006import java.util.ArrayList;
007import java.util.Random;
008import net.minecraft.client.renderer.texture.IconRegister;
009import net.minecraft.creativetab.CreativeTabs;
010import net.minecraft.item.Item;
011import net.minecraft.item.ItemStack;
012import net.minecraft.util.Icon;
013import net.minecraft.world.World;
014import net.minecraftforge.common.ForgeDirection;
015
016public class BlockNetherStalk extends BlockFlower
017{
018    private static final String[] field_94373_a = new String[] {"netherStalk_0", "netherStalk_1", "netherStalk_2"};
019    @SideOnly(Side.CLIENT)
020    private Icon[] iconArray;
021
022    protected BlockNetherStalk(int par1)
023    {
024        super(par1);
025        this.setTickRandomly(true);
026        float f = 0.5F;
027        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f);
028        this.setCreativeTab((CreativeTabs)null);
029    }
030
031    /**
032     * Gets passed in the blockID of the block below and supposed to return true if its allowed to grow on the type of
033     * blockID passed in. Args: blockID
034     */
035    protected boolean canThisPlantGrowOnThisBlockID(int par1)
036    {
037        return par1 == Block.slowSand.blockID;
038    }
039
040    /**
041     * Can this block stay at this position.  Similar to canPlaceBlockAt except gets checked often with plants.
042     */
043    public boolean canBlockStay(World par1World, int par2, int par3, int par4)
044    {
045        Block block = Block.blocksList[par1World.getBlockId(par2, par3 - 1, par4)];
046        return (block != null && block.canSustainPlant(par1World, par2, par3 - 1, par4, ForgeDirection.UP, this));
047    }
048
049    /**
050     * Ticks the block if it's been scheduled
051     */
052    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
053    {
054        int l = par1World.getBlockMetadata(par2, par3, par4);
055
056        if (l < 3 && par5Random.nextInt(10) == 0)
057        {
058            ++l;
059            par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
060        }
061
062        super.updateTick(par1World, par2, par3, par4, par5Random);
063    }
064
065    @SideOnly(Side.CLIENT)
066
067    /**
068     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
069     */
070    public Icon getBlockTextureFromSideAndMetadata(int par1, int par2)
071    {
072        return par2 >= 3 ? this.iconArray[2] : (par2 > 0 ? this.iconArray[1] : this.iconArray[0]);
073    }
074
075    /**
076     * The type of render function that is called for this block
077     */
078    public int getRenderType()
079    {
080        return 6;
081    }
082
083    /**
084     * Drops the block items with a specified chance of dropping the specified items
085     */
086    public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
087    {
088        super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, par7);
089    }
090
091    /**
092     * Returns the ID of the items to drop on destruction.
093     */
094    public int idDropped(int par1, Random par2Random, int par3)
095    {
096        return 0;
097    }
098
099    /**
100     * Returns the quantity of items to drop on block destruction.
101     */
102    public int quantityDropped(Random par1Random)
103    {
104        return 0;
105    }
106
107    @SideOnly(Side.CLIENT)
108
109    /**
110     * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
111     */
112    public int idPicked(World par1World, int par2, int par3, int par4)
113    {
114        return Item.netherStalkSeeds.itemID;
115    }
116
117    @SideOnly(Side.CLIENT)
118
119    /**
120     * When this method is called, your block should register all the icons it needs with the given IconRegister. This
121     * is the only chance you get to register icons.
122     */
123    public void registerIcons(IconRegister par1IconRegister)
124    {
125        this.iconArray = new Icon[field_94373_a.length];
126
127        for (int i = 0; i < this.iconArray.length; ++i)
128        {
129            this.iconArray[i] = par1IconRegister.registerIcon(field_94373_a[i]);
130        }
131    }
132
133    @Override
134    public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune)
135    {
136        ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
137        int count = 1;
138
139        if (metadata >= 3)
140        {
141            count = 2 + world.rand.nextInt(3) + (fortune > 0 ? world.rand.nextInt(fortune + 1) : 0);
142        }
143
144        for (int i = 0; i < count; i++)
145        {
146            ret.add(new ItemStack(Item.netherStalkSeeds));
147        }
148
149        return ret;
150    }
151}