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