001    package net.minecraft.src;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    import java.util.Random;
006    
007    public class BlockFlowerPot extends Block
008    {
009        public BlockFlowerPot(int par1)
010        {
011            super(par1, Material.circuits);
012            this.blockIndexInTexture = 186;
013            this.setBlockBoundsForItemRender();
014            this.setRequiresSelfNotify();
015        }
016    
017        /**
018         * Sets the block's bounds for rendering it as an item
019         */
020        public void setBlockBoundsForItemRender()
021        {
022            float var1 = 0.375F;
023            float var2 = var1 / 2.0F;
024            this.setBlockBounds(0.5F - var2, 0.0F, 0.5F - var2, 0.5F + var2, var1, 0.5F + var2);
025        }
026    
027        /**
028         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
029         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
030         */
031        public boolean isOpaqueCube()
032        {
033            return false;
034        }
035    
036        /**
037         * The type of render function that is called for this block
038         */
039        public int getRenderType()
040        {
041            return 33;
042        }
043    
044        /**
045         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
046         */
047        public boolean renderAsNormalBlock()
048        {
049            return false;
050        }
051    
052        /**
053         * Called upon block activation (right click on the block.)
054         */
055        public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
056        {
057            ItemStack var10 = par5EntityPlayer.inventory.getCurrentItem();
058    
059            if (var10 == null)
060            {
061                return false;
062            }
063            else if (par1World.getBlockMetadata(par2, par3, par4) != 0)
064            {
065                return false;
066            }
067            else
068            {
069                int var11 = func_82530_a(var10);
070    
071                if (var11 > 0)
072                {
073                    par1World.setBlockMetadataWithNotify(par2, par3, par4, var11);
074    
075                    if (!par5EntityPlayer.capabilities.isCreativeMode && --var10.stackSize <= 0)
076                    {
077                        par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, (ItemStack)null);
078                    }
079    
080                    return true;
081                }
082                else
083                {
084                    return false;
085                }
086            }
087        }
088    
089        @SideOnly(Side.CLIENT)
090    
091        /**
092         * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
093         */
094        public int idPicked(World par1World, int par2, int par3, int par4)
095        {
096            ItemStack var5 = func_82531_c(par1World.getBlockMetadata(par2, par3, par4));
097            return var5 == null ? Item.field_82796_bJ.shiftedIndex : var5.itemID;
098        }
099    
100        /**
101         * Get the block's damage value (for use with pick block).
102         */
103        public int getDamageValue(World par1World, int par2, int par3, int par4)
104        {
105            ItemStack var5 = func_82531_c(par1World.getBlockMetadata(par2, par3, par4));
106            return var5 == null ? Item.field_82796_bJ.shiftedIndex : var5.getItemDamage();
107        }
108    
109        @SideOnly(Side.CLIENT)
110        public boolean func_82505_u_()
111        {
112            return true;
113        }
114    
115        /**
116         * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
117         */
118        public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
119        {
120            return super.canPlaceBlockAt(par1World, par2, par3, par4) && par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4);
121        }
122    
123        /**
124         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
125         * their own) Args: x, y, z, neighbor blockID
126         */
127        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
128        {
129            if (!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4))
130            {
131                this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
132                par1World.setBlockWithNotify(par2, par3, par4, 0);
133            }
134        }
135    
136        /**
137         * Drops the block items with a specified chance of dropping the specified items
138         */
139        public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
140        {
141            super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, par7);
142    
143            if (par5 > 0)
144            {
145                ItemStack var8 = func_82531_c(par5);
146    
147                if (var8 != null)
148                {
149                    this.dropBlockAsItem_do(par1World, par2, par3, par4, var8);
150                }
151            }
152        }
153    
154        /**
155         * Returns the ID of the items to drop on destruction.
156         */
157        public int idDropped(int par1, Random par2Random, int par3)
158        {
159            return Item.field_82796_bJ.shiftedIndex;
160        }
161    
162        public static ItemStack func_82531_c(int par0)
163        {
164            switch (par0)
165            {
166                case 1:
167                    return new ItemStack(Block.plantRed);
168                case 2:
169                    return new ItemStack(Block.plantYellow);
170                case 3:
171                    return new ItemStack(Block.sapling, 1, 0);
172                case 4:
173                    return new ItemStack(Block.sapling, 1, 1);
174                case 5:
175                    return new ItemStack(Block.sapling, 1, 2);
176                case 6:
177                    return new ItemStack(Block.sapling, 1, 3);
178                case 7:
179                    return new ItemStack(Block.mushroomRed);
180                case 8:
181                    return new ItemStack(Block.mushroomBrown);
182                case 9:
183                    return new ItemStack(Block.cactus);
184                case 10:
185                    return new ItemStack(Block.deadBush);
186                case 11:
187                    return new ItemStack(Block.tallGrass, 1, 2);
188                default:
189                    return null;
190            }
191        }
192    
193        public static int func_82530_a(ItemStack par0ItemStack)
194        {
195            int var1 = par0ItemStack.getItem().shiftedIndex;
196    
197            if (var1 == Block.plantRed.blockID)
198            {
199                return 1;
200            }
201            else if (var1 == Block.plantYellow.blockID)
202            {
203                return 2;
204            }
205            else if (var1 == Block.cactus.blockID)
206            {
207                return 9;
208            }
209            else if (var1 == Block.mushroomBrown.blockID)
210            {
211                return 8;
212            }
213            else if (var1 == Block.mushroomRed.blockID)
214            {
215                return 7;
216            }
217            else if (var1 == Block.deadBush.blockID)
218            {
219                return 10;
220            }
221            else
222            {
223                if (var1 == Block.sapling.blockID)
224                {
225                    switch (par0ItemStack.getItemDamage())
226                    {
227                        case 0:
228                            return 3;
229                        case 1:
230                            return 4;
231                        case 2:
232                            return 5;
233                        case 3:
234                            return 6;
235                    }
236                }
237    
238                if (var1 == Block.tallGrass.blockID)
239                {
240                    switch (par0ItemStack.getItemDamage())
241                    {
242                        case 2:
243                            return 11;
244                    }
245                }
246    
247                return 0;
248            }
249        }
250    }