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.Random; 006 007 public class BlockFlowerPot extends Block 008 { 009 public BlockFlowerPot(int par1) 010 { 011 super(par1, Material.circuits); 012 this.blockIndexInTexture = 186; 013 this.setBlockBoundsForItemRender(); 014 this.setRequiresSelfNotify(); 015 } 016 017 /** 018 * Sets the block's bounds for rendering it as an item 019 */ 020 public void setBlockBoundsForItemRender() 021 { 022 float var1 = 0.375F; 023 float var2 = var1 / 2.0F; 024 this.setBlockBounds(0.5F - var2, 0.0F, 0.5F - var2, 0.5F + var2, var1, 0.5F + var2); 025 } 026 027 /** 028 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two 029 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. 030 */ 031 public boolean isOpaqueCube() 032 { 033 return false; 034 } 035 036 /** 037 * The type of render function that is called for this block 038 */ 039 public int getRenderType() 040 { 041 return 33; 042 } 043 044 /** 045 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) 046 */ 047 public boolean renderAsNormalBlock() 048 { 049 return false; 050 } 051 052 /** 053 * Called upon block activation (right click on the block.) 054 */ 055 public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) 056 { 057 ItemStack var10 = par5EntityPlayer.inventory.getCurrentItem(); 058 059 if (var10 == null) 060 { 061 return false; 062 } 063 else if (par1World.getBlockMetadata(par2, par3, par4) != 0) 064 { 065 return false; 066 } 067 else 068 { 069 int var11 = getMetaForPlant(var10); 070 071 if (var11 > 0) 072 { 073 par1World.setBlockMetadataWithNotify(par2, par3, par4, var11); 074 075 if (!par5EntityPlayer.capabilities.isCreativeMode && --var10.stackSize <= 0) 076 { 077 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, (ItemStack)null); 078 } 079 080 return true; 081 } 082 else 083 { 084 return false; 085 } 086 } 087 } 088 089 @SideOnly(Side.CLIENT) 090 091 /** 092 * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative) 093 */ 094 public int idPicked(World par1World, int par2, int par3, int par4) 095 { 096 ItemStack var5 = getPlantForMeta(par1World.getBlockMetadata(par2, par3, par4)); 097 return var5 == null ? Item.flowerPot.shiftedIndex : var5.itemID; 098 } 099 100 /** 101 * Get the block's damage value (for use with pick block). 102 */ 103 public int getDamageValue(World par1World, int par2, int par3, int par4) 104 { 105 ItemStack var5 = getPlantForMeta(par1World.getBlockMetadata(par2, par3, par4)); 106 return var5 == null ? Item.flowerPot.shiftedIndex : var5.getItemDamage(); 107 } 108 109 @SideOnly(Side.CLIENT) 110 public boolean func_82505_u_() 111 { 112 return true; 113 } 114 115 /** 116 * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z 117 */ 118 public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) 119 { 120 return super.canPlaceBlockAt(par1World, par2, par3, par4) && par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4); 121 } 122 123 /** 124 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are 125 * their own) Args: x, y, z, neighbor blockID 126 */ 127 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) 128 { 129 if (!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4)) 130 { 131 this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0); 132 par1World.setBlockWithNotify(par2, par3, par4, 0); 133 } 134 } 135 136 /** 137 * Drops the block items with a specified chance of dropping the specified items 138 */ 139 public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7) 140 { 141 super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, par7); 142 143 if (par5 > 0) 144 { 145 ItemStack var8 = getPlantForMeta(par5); 146 147 if (var8 != null) 148 { 149 this.dropBlockAsItem_do(par1World, par2, par3, par4, var8); 150 } 151 } 152 } 153 154 /** 155 * Returns the ID of the items to drop on destruction. 156 */ 157 public int idDropped(int par1, Random par2Random, int par3) 158 { 159 return Item.flowerPot.shiftedIndex; 160 } 161 162 /** 163 * Return the item associated with the specified flower pot metadata value. 164 */ 165 public static ItemStack getPlantForMeta(int par0) 166 { 167 switch (par0) 168 { 169 case 1: 170 return new ItemStack(Block.plantRed); 171 case 2: 172 return new ItemStack(Block.plantYellow); 173 case 3: 174 return new ItemStack(Block.sapling, 1, 0); 175 case 4: 176 return new ItemStack(Block.sapling, 1, 1); 177 case 5: 178 return new ItemStack(Block.sapling, 1, 2); 179 case 6: 180 return new ItemStack(Block.sapling, 1, 3); 181 case 7: 182 return new ItemStack(Block.mushroomRed); 183 case 8: 184 return new ItemStack(Block.mushroomBrown); 185 case 9: 186 return new ItemStack(Block.cactus); 187 case 10: 188 return new ItemStack(Block.deadBush); 189 case 11: 190 return new ItemStack(Block.tallGrass, 1, 2); 191 default: 192 return null; 193 } 194 } 195 196 /** 197 * Return the flower pot metadata value associated with the specified item. 198 */ 199 public static int getMetaForPlant(ItemStack par0ItemStack) 200 { 201 int var1 = par0ItemStack.getItem().shiftedIndex; 202 203 if (var1 == Block.plantRed.blockID) 204 { 205 return 1; 206 } 207 else if (var1 == Block.plantYellow.blockID) 208 { 209 return 2; 210 } 211 else if (var1 == Block.cactus.blockID) 212 { 213 return 9; 214 } 215 else if (var1 == Block.mushroomBrown.blockID) 216 { 217 return 8; 218 } 219 else if (var1 == Block.mushroomRed.blockID) 220 { 221 return 7; 222 } 223 else if (var1 == Block.deadBush.blockID) 224 { 225 return 10; 226 } 227 else 228 { 229 if (var1 == Block.sapling.blockID) 230 { 231 switch (par0ItemStack.getItemDamage()) 232 { 233 case 0: 234 return 3; 235 case 1: 236 return 4; 237 case 2: 238 return 5; 239 case 3: 240 return 6; 241 } 242 } 243 244 if (var1 == Block.tallGrass.blockID) 245 { 246 switch (par0ItemStack.getItemDamage()) 247 { 248 case 2: 249 return 11; 250 } 251 } 252 253 return 0; 254 } 255 } 256 }