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)
114                        {
115                            if (var11 > 0)
116                            {
117                                ItemStack var12 = new ItemStack(Item.potion, 1, 0);
118    
119                                if (!par5EntityPlayer.inventory.addItemStackToInventory(var12))
120                                {
121                                    par1World.spawnEntityInWorld(new EntityItem(par1World, (double)par2 + 0.5D, (double)par3 + 1.5D, (double)par4 + 0.5D, var12));
122                                }
123                                else if (par5EntityPlayer instanceof EntityPlayerMP)
124                                {
125                                    ((EntityPlayerMP)par5EntityPlayer).sendContainerToPlayer(par5EntityPlayer.inventoryContainer);
126                                }
127    
128                                --var10.stackSize;
129    
130                                if (var10.stackSize <= 0)
131                                {
132                                    par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, (ItemStack)null);
133                                }
134    
135                                par1World.setBlockMetadataWithNotify(par2, par3, par4, var11 - 1);
136                            }
137                        }
138                        else if (var11 > 0 && var10.getItem() instanceof ItemArmor && ((ItemArmor)var10.getItem()).getArmorMaterial() == EnumArmorMaterial.CLOTH)
139                        {
140                            ItemArmor var13 = (ItemArmor)var10.getItem();
141                            var13.removeColor(var10);
142                            par1World.setBlockMetadataWithNotify(par2, par3, par4, var11 - 1);
143                            return true;
144                        }
145    
146                        return true;
147                    }
148                }
149            }
150        }
151    
152        /**
153         * currently only used by BlockCauldron to incrament meta-data during rain
154         */
155        public void fillWithRain(World par1World, int par2, int par3, int par4)
156        {
157            if (par1World.rand.nextInt(20) == 1)
158            {
159                int var5 = par1World.getBlockMetadata(par2, par3, par4);
160    
161                if (var5 < 3)
162                {
163                    par1World.setBlockMetadataWithNotify(par2, par3, par4, var5 + 1);
164                }
165            }
166        }
167    
168        /**
169         * Returns the ID of the items to drop on destruction.
170         */
171        public int idDropped(int par1, Random par2Random, int par3)
172        {
173            return Item.cauldron.shiftedIndex;
174        }
175    
176        @SideOnly(Side.CLIENT)
177    
178        /**
179         * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
180         */
181        public int idPicked(World par1World, int par2, int par3, int par4)
182        {
183            return Item.cauldron.shiftedIndex;
184        }
185    }