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.List;
006    import java.util.Random;
007    
008    public class BlockCauldron extends Block
009    {
010        public BlockCauldron(int par1)
011        {
012            super(par1, Material.iron);
013            this.blockIndexInTexture = 154;
014        }
015    
016        /**
017         * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
018         */
019        public int getBlockTextureFromSideAndMetadata(int par1, int par2)
020        {
021            return par1 == 1 ? 138 : (par1 == 0 ? 155 : 154);
022        }
023    
024        /**
025         * if the specified block is in the given AABB, add its collision bounding box to the given list
026         */
027        public void addCollidingBlockToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
028        {
029            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.3125F, 1.0F);
030            super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
031            float var8 = 0.125F;
032            this.setBlockBounds(0.0F, 0.0F, 0.0F, var8, 1.0F, 1.0F);
033            super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
034            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, var8);
035            super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
036            this.setBlockBounds(1.0F - var8, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
037            super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
038            this.setBlockBounds(0.0F, 0.0F, 1.0F - var8, 1.0F, 1.0F, 1.0F);
039            super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
040            this.setBlockBoundsForItemRender();
041        }
042    
043        /**
044         * Sets the block's bounds for rendering it as an item
045         */
046        public void setBlockBoundsForItemRender()
047        {
048            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
049        }
050    
051        /**
052         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
053         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
054         */
055        public boolean isOpaqueCube()
056        {
057            return false;
058        }
059    
060        /**
061         * The type of render function that is called for this block
062         */
063        public int getRenderType()
064        {
065            return 24;
066        }
067    
068        /**
069         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
070         */
071        public boolean renderAsNormalBlock()
072        {
073            return false;
074        }
075    
076        /**
077         * Called upon block activation (right click on the block.)
078         */
079        public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
080        {
081            if (par1World.isRemote)
082            {
083                return true;
084            }
085            else
086            {
087                ItemStack var10 = par5EntityPlayer.inventory.getCurrentItem();
088    
089                if (var10 == null)
090                {
091                    return true;
092                }
093                else
094                {
095                    int var11 = par1World.getBlockMetadata(par2, par3, par4);
096    
097                    if (var10.itemID == Item.bucketWater.shiftedIndex)
098                    {
099                        if (var11 < 3)
100                        {
101                            if (!par5EntityPlayer.capabilities.isCreativeMode)
102                            {
103                                par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketEmpty));
104                            }
105    
106                            par1World.setBlockMetadataWithNotify(par2, par3, par4, 3);
107                        }
108    
109                        return true;
110                    }
111                    else
112                    {
113                        if (var10.itemID == Item.glassBottle.shiftedIndex && var11 > 0)
114                        {
115                            ItemStack var12 = new ItemStack(Item.potion, 1, 0);
116    
117                            if (!par5EntityPlayer.inventory.addItemStackToInventory(var12))
118                            {
119                                par1World.spawnEntityInWorld(new EntityItem(par1World, (double)par2 + 0.5D, (double)par3 + 1.5D, (double)par4 + 0.5D, var12));
120                            }
121                            else if (par5EntityPlayer instanceof EntityPlayerMP)
122                            {
123                                ((EntityPlayerMP)par5EntityPlayer).sendContainerToPlayer(par5EntityPlayer.inventorySlots);
124                            }
125    
126                            --var10.stackSize;
127    
128                            if (var10.stackSize <= 0)
129                            {
130                                par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, (ItemStack)null);
131                            }
132    
133                            par1World.setBlockMetadataWithNotify(par2, par3, par4, var11 - 1);
134                        }
135    
136                        return true;
137                    }
138                }
139            }
140        }
141    
142        /**
143         * currently only used by BlockCauldron to incrament meta-data during rain
144         */
145        public void fillWithRain(World par1World, int par2, int par3, int par4)
146        {
147            if (par1World.rand.nextInt(20) == 1)
148            {
149                int var5 = par1World.getBlockMetadata(par2, par3, par4);
150    
151                if (var5 < 3)
152                {
153                    par1World.setBlockMetadataWithNotify(par2, par3, par4, var5 + 1);
154                }
155            }
156        }
157    
158        /**
159         * Returns the ID of the items to drop on destruction.
160         */
161        public int idDropped(int par1, Random par2Random, int par3)
162        {
163            return Item.cauldron.shiftedIndex;
164        }
165    
166        @SideOnly(Side.CLIENT)
167    
168        /**
169         * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
170         */
171        public int idPicked(World par1World, int par2, int par3, int par4)
172        {
173            return Item.cauldron.shiftedIndex;
174        }
175    }