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