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 BlockBrewingStand extends BlockContainer 009 { 010 private Random rand = new Random(); 011 012 public BlockBrewingStand(int par1) 013 { 014 super(par1, Material.iron); 015 this.blockIndexInTexture = 157; 016 } 017 018 /** 019 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two 020 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. 021 */ 022 public boolean isOpaqueCube() 023 { 024 return false; 025 } 026 027 /** 028 * The type of render function that is called for this block 029 */ 030 public int getRenderType() 031 { 032 return 25; 033 } 034 035 /** 036 * each class overrdies this to return a new <className> 037 */ 038 public TileEntity createNewTileEntity(World par1World) 039 { 040 return new TileEntityBrewingStand(); 041 } 042 043 /** 044 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) 045 */ 046 public boolean renderAsNormalBlock() 047 { 048 return false; 049 } 050 051 /** 052 * if the specified block is in the given AABB, add its collision bounding box to the given list 053 */ 054 public void addCollidingBlockToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity) 055 { 056 this.setBlockBounds(0.4375F, 0.0F, 0.4375F, 0.5625F, 0.875F, 0.5625F); 057 super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 058 this.setBlockBoundsForItemRender(); 059 super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 060 } 061 062 /** 063 * Sets the block's bounds for rendering it as an item 064 */ 065 public void setBlockBoundsForItemRender() 066 { 067 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F); 068 } 069 070 /** 071 * Called upon block activation (right click on the block.) 072 */ 073 public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) 074 { 075 if (par1World.isRemote) 076 { 077 return true; 078 } 079 else 080 { 081 TileEntityBrewingStand var10 = (TileEntityBrewingStand)par1World.getBlockTileEntity(par2, par3, par4); 082 083 if (var10 != null) 084 { 085 par5EntityPlayer.displayGUIBrewingStand(var10); 086 } 087 088 return true; 089 } 090 } 091 092 @SideOnly(Side.CLIENT) 093 094 /** 095 * A randomly called display update to be able to add particles or other items for display 096 */ 097 public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random) 098 { 099 double var6 = (double)((float)par2 + 0.4F + par5Random.nextFloat() * 0.2F); 100 double var8 = (double)((float)par3 + 0.7F + par5Random.nextFloat() * 0.3F); 101 double var10 = (double)((float)par4 + 0.4F + par5Random.nextFloat() * 0.2F); 102 par1World.spawnParticle("smoke", var6, var8, var10, 0.0D, 0.0D, 0.0D); 103 } 104 105 /** 106 * ejects contained items into the world, and notifies neighbours of an update, as appropriate 107 */ 108 public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) 109 { 110 TileEntity var7 = par1World.getBlockTileEntity(par2, par3, par4); 111 112 if (var7 instanceof TileEntityBrewingStand) 113 { 114 TileEntityBrewingStand var8 = (TileEntityBrewingStand)var7; 115 116 for (int var9 = 0; var9 < var8.getSizeInventory(); ++var9) 117 { 118 ItemStack var10 = var8.getStackInSlot(var9); 119 120 if (var10 != null) 121 { 122 float var11 = this.rand.nextFloat() * 0.8F + 0.1F; 123 float var12 = this.rand.nextFloat() * 0.8F + 0.1F; 124 float var13 = this.rand.nextFloat() * 0.8F + 0.1F; 125 126 while (var10.stackSize > 0) 127 { 128 int var14 = this.rand.nextInt(21) + 10; 129 130 if (var14 > var10.stackSize) 131 { 132 var14 = var10.stackSize; 133 } 134 135 var10.stackSize -= var14; 136 EntityItem var15 = new EntityItem(par1World, (double)((float)par2 + var11), (double)((float)par3 + var12), (double)((float)par4 + var13), new ItemStack(var10.itemID, var14, var10.getItemDamage())); 137 float var16 = 0.05F; 138 var15.motionX = (double)((float)this.rand.nextGaussian() * var16); 139 var15.motionY = (double)((float)this.rand.nextGaussian() * var16 + 0.2F); 140 var15.motionZ = (double)((float)this.rand.nextGaussian() * var16); 141 par1World.spawnEntityInWorld(var15); 142 } 143 } 144 } 145 } 146 147 super.breakBlock(par1World, par2, par3, par4, par5, par6); 148 } 149 150 /** 151 * Returns the ID of the items to drop on destruction. 152 */ 153 public int idDropped(int par1, Random par2Random, int par3) 154 { 155 return Item.brewingStand.shiftedIndex; 156 } 157 158 @SideOnly(Side.CLIENT) 159 160 /** 161 * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative) 162 */ 163 public int idPicked(World par1World, int par2, int par3, int par4) 164 { 165 return Item.brewingStand.shiftedIndex; 166 } 167 }