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.entity.Entity;
010import net.minecraft.entity.item.EntityItem;
011import net.minecraft.entity.player.EntityPlayer;
012import net.minecraft.entity.player.EntityPlayerMP;
013import net.minecraft.item.EnumArmorMaterial;
014import net.minecraft.item.Item;
015import net.minecraft.item.ItemArmor;
016import net.minecraft.item.ItemStack;
017import net.minecraft.util.AxisAlignedBB;
018import net.minecraft.util.Icon;
019import net.minecraft.world.World;
020
021public class BlockCauldron extends Block
022{
023    @SideOnly(Side.CLIENT)
024    private Icon field_94378_a;
025    @SideOnly(Side.CLIENT)
026    private Icon field_94376_b;
027    @SideOnly(Side.CLIENT)
028    private Icon field_94377_c;
029
030    public BlockCauldron(int par1)
031    {
032        super(par1, Material.iron);
033    }
034
035    @SideOnly(Side.CLIENT)
036
037    /**
038     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
039     */
040    public Icon getBlockTextureFromSideAndMetadata(int par1, int par2)
041    {
042        return par1 == 1 ? this.field_94376_b : (par1 == 0 ? this.field_94377_c : this.blockIcon);
043    }
044
045    @SideOnly(Side.CLIENT)
046
047    /**
048     * When this method is called, your block should register all the icons it needs with the given IconRegister. This
049     * is the only chance you get to register icons.
050     */
051    public void registerIcons(IconRegister par1IconRegister)
052    {
053        this.field_94378_a = par1IconRegister.registerIcon("cauldron_inner");
054        this.field_94376_b = par1IconRegister.registerIcon("cauldron_top");
055        this.field_94377_c = par1IconRegister.registerIcon("cauldron_bottom");
056        this.blockIcon = par1IconRegister.registerIcon("cauldron_side");
057    }
058
059    /**
060     * Adds all intersecting collision boxes to a list. (Be sure to only add boxes to the list if they intersect the
061     * mask.) Parameters: World, X, Y, Z, mask, list, colliding entity
062     */
063    public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
064    {
065        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.3125F, 1.0F);
066        super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
067        float f = 0.125F;
068        this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
069        super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
070        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
071        super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
072        this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
073        super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
074        this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
075        super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
076        this.setBlockBoundsForItemRender();
077    }
078
079    @SideOnly(Side.CLIENT)
080    public static Icon func_94375_b(String par0Str)
081    {
082        return par0Str == "cauldron_inner" ? Block.cauldron.field_94378_a : (par0Str == "cauldron_bottom" ? Block.cauldron.field_94377_c : null);
083    }
084
085    /**
086     * Sets the block's bounds for rendering it as an item
087     */
088    public void setBlockBoundsForItemRender()
089    {
090        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
091    }
092
093    /**
094     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
095     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
096     */
097    public boolean isOpaqueCube()
098    {
099        return false;
100    }
101
102    /**
103     * The type of render function that is called for this block
104     */
105    public int getRenderType()
106    {
107        return 24;
108    }
109
110    /**
111     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
112     */
113    public boolean renderAsNormalBlock()
114    {
115        return false;
116    }
117
118    /**
119     * Called upon block activation (right click on the block.)
120     */
121    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
122    {
123        if (par1World.isRemote)
124        {
125            return true;
126        }
127        else
128        {
129            ItemStack itemstack = par5EntityPlayer.inventory.getCurrentItem();
130
131            if (itemstack == null)
132            {
133                return true;
134            }
135            else
136            {
137                int i1 = par1World.getBlockMetadata(par2, par3, par4);
138
139                if (itemstack.itemID == Item.bucketWater.itemID)
140                {
141                    if (i1 < 3)
142                    {
143                        if (!par5EntityPlayer.capabilities.isCreativeMode)
144                        {
145                            par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketEmpty));
146                        }
147
148                        par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
149                    }
150
151                    return true;
152                }
153                else
154                {
155                    if (itemstack.itemID == Item.glassBottle.itemID)
156                    {
157                        if (i1 > 0)
158                        {
159                            ItemStack itemstack1 = new ItemStack(Item.potion, 1, 0);
160
161                            if (!par5EntityPlayer.inventory.addItemStackToInventory(itemstack1))
162                            {
163                                par1World.spawnEntityInWorld(new EntityItem(par1World, (double)par2 + 0.5D, (double)par3 + 1.5D, (double)par4 + 0.5D, itemstack1));
164                            }
165                            else if (par5EntityPlayer instanceof EntityPlayerMP)
166                            {
167                                ((EntityPlayerMP)par5EntityPlayer).sendContainerToPlayer(par5EntityPlayer.inventoryContainer);
168                            }
169
170                            --itemstack.stackSize;
171
172                            if (itemstack.stackSize <= 0)
173                            {
174                                par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, (ItemStack)null);
175                            }
176
177                            par1World.setBlockMetadataWithNotify(par2, par3, par4, i1 - 1, 2);
178                        }
179                    }
180                    else if (i1 > 0 && itemstack.getItem() instanceof ItemArmor && ((ItemArmor)itemstack.getItem()).getArmorMaterial() == EnumArmorMaterial.CLOTH)
181                    {
182                        ItemArmor itemarmor = (ItemArmor)itemstack.getItem();
183                        itemarmor.removeColor(itemstack);
184                        par1World.setBlockMetadataWithNotify(par2, par3, par4, i1 - 1, 2);
185                        return true;
186                    }
187
188                    return true;
189                }
190            }
191        }
192    }
193
194    /**
195     * currently only used by BlockCauldron to incrament meta-data during rain
196     */
197    public void fillWithRain(World par1World, int par2, int par3, int par4)
198    {
199        if (par1World.rand.nextInt(20) == 1)
200        {
201            int l = par1World.getBlockMetadata(par2, par3, par4);
202
203            if (l < 3)
204            {
205                par1World.setBlockMetadataWithNotify(par2, par3, par4, l + 1, 2);
206            }
207        }
208    }
209
210    /**
211     * Returns the ID of the items to drop on destruction.
212     */
213    public int idDropped(int par1, Random par2Random, int par3)
214    {
215        return Item.cauldron.itemID;
216    }
217
218    @SideOnly(Side.CLIENT)
219
220    /**
221     * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
222     */
223    public int idPicked(World par1World, int par2, int par3, int par4)
224    {
225        return Item.cauldron.itemID;
226    }
227}