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