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.EntityLiving;
011import net.minecraft.entity.item.EntityItem;
012import net.minecraft.entity.player.EntityPlayer;
013import net.minecraft.inventory.Container;
014import net.minecraft.inventory.IInventory;
015import net.minecraft.item.Item;
016import net.minecraft.item.ItemStack;
017import net.minecraft.tileentity.TileEntity;
018import net.minecraft.tileentity.TileEntityBrewingStand;
019import net.minecraft.util.AxisAlignedBB;
020import net.minecraft.util.Icon;
021import net.minecraft.world.World;
022
023public class BlockBrewingStand extends BlockContainer
024{
025    private Random rand = new Random();
026    @SideOnly(Side.CLIENT)
027    private Icon field_94449_b;
028
029    public BlockBrewingStand(int par1)
030    {
031        super(par1, Material.iron);
032    }
033
034    /**
035     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
036     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
037     */
038    public boolean isOpaqueCube()
039    {
040        return false;
041    }
042
043    /**
044     * The type of render function that is called for this block
045     */
046    public int getRenderType()
047    {
048        return 25;
049    }
050
051    /**
052     * Returns a new instance of a block's tile entity class. Called on placing the block.
053     */
054    public TileEntity createNewTileEntity(World par1World)
055    {
056        return new TileEntityBrewingStand();
057    }
058
059    /**
060     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
061     */
062    public boolean renderAsNormalBlock()
063    {
064        return false;
065    }
066
067    /**
068     * Adds all intersecting collision boxes to a list. (Be sure to only add boxes to the list if they intersect the
069     * mask.) Parameters: World, X, Y, Z, mask, list, colliding entity
070     */
071    public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
072    {
073        this.setBlockBounds(0.4375F, 0.0F, 0.4375F, 0.5625F, 0.875F, 0.5625F);
074        super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
075        this.setBlockBoundsForItemRender();
076        super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
077    }
078
079    /**
080     * Sets the block's bounds for rendering it as an item
081     */
082    public void setBlockBoundsForItemRender()
083    {
084        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F);
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            TileEntityBrewingStand tileentitybrewingstand = (TileEntityBrewingStand)par1World.getBlockTileEntity(par2, par3, par4);
099
100            if (tileentitybrewingstand != null)
101            {
102                par5EntityPlayer.displayGUIBrewingStand(tileentitybrewingstand);
103            }
104
105            return true;
106        }
107    }
108
109    /**
110     * Called when the block is placed in the world.
111     */
112    public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving, ItemStack par6ItemStack)
113    {
114        if (par6ItemStack.hasDisplayName())
115        {
116            ((TileEntityBrewingStand)par1World.getBlockTileEntity(par2, par3, par4)).func_94131_a(par6ItemStack.getDisplayName());
117        }
118    }
119
120    /**
121     * ejects contained items into the world, and notifies neighbours of an update, as appropriate
122     */
123    public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
124    {
125        TileEntity tileentity = par1World.getBlockTileEntity(par2, par3, par4);
126
127        if (tileentity instanceof TileEntityBrewingStand)
128        {
129            TileEntityBrewingStand tileentitybrewingstand = (TileEntityBrewingStand)tileentity;
130
131            for (int j1 = 0; j1 < tileentitybrewingstand.getSizeInventory(); ++j1)
132            {
133                ItemStack itemstack = tileentitybrewingstand.getStackInSlot(j1);
134
135                if (itemstack != null)
136                {
137                    float f = this.rand.nextFloat() * 0.8F + 0.1F;
138                    float f1 = this.rand.nextFloat() * 0.8F + 0.1F;
139                    float f2 = this.rand.nextFloat() * 0.8F + 0.1F;
140
141                    while (itemstack.stackSize > 0)
142                    {
143                        int k1 = this.rand.nextInt(21) + 10;
144
145                        if (k1 > itemstack.stackSize)
146                        {
147                            k1 = itemstack.stackSize;
148                        }
149
150                        itemstack.stackSize -= k1;
151                        EntityItem entityitem = new EntityItem(par1World, (double)((float)par2 + f), (double)((float)par3 + f1), (double)((float)par4 + f2), new ItemStack(itemstack.itemID, k1, itemstack.getItemDamage()));
152                        float f3 = 0.05F;
153                        entityitem.motionX = (double)((float)this.rand.nextGaussian() * f3);
154                        entityitem.motionY = (double)((float)this.rand.nextGaussian() * f3 + 0.2F);
155                        entityitem.motionZ = (double)((float)this.rand.nextGaussian() * f3);
156                        par1World.spawnEntityInWorld(entityitem);
157                    }
158                }
159            }
160        }
161
162        super.breakBlock(par1World, par2, par3, par4, par5, par6);
163    }
164
165    /**
166     * Returns the ID of the items to drop on destruction.
167     */
168    public int idDropped(int par1, Random par2Random, int par3)
169    {
170        return Item.brewingStand.itemID;
171    }
172
173    @SideOnly(Side.CLIENT)
174
175    /**
176     * A randomly called display update to be able to add particles or other items for display
177     */
178    public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
179    {
180        double d0 = (double)((float)par2 + 0.4F + par5Random.nextFloat() * 0.2F);
181        double d1 = (double)((float)par3 + 0.7F + par5Random.nextFloat() * 0.3F);
182        double d2 = (double)((float)par4 + 0.4F + par5Random.nextFloat() * 0.2F);
183        par1World.spawnParticle("smoke", d0, d1, d2, 0.0D, 0.0D, 0.0D);
184    }
185
186    @SideOnly(Side.CLIENT)
187
188    /**
189     * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
190     */
191    public int idPicked(World par1World, int par2, int par3, int par4)
192    {
193        return Item.brewingStand.itemID;
194    }
195
196    public boolean func_96468_q_()
197    {
198        return true;
199    }
200
201    public int func_94328_b_(World par1World, int par2, int par3, int par4, int par5)
202    {
203        return Container.func_94526_b((IInventory)par1World.getBlockTileEntity(par2, par3, par4));
204    }
205
206    @SideOnly(Side.CLIENT)
207    public void func_94332_a(IconRegister par1IconRegister)
208    {
209        super.func_94332_a(par1IconRegister);
210        this.field_94449_b = par1IconRegister.func_94245_a("brewingStand_base");
211    }
212
213    @SideOnly(Side.CLIENT)
214    public Icon func_94448_e()
215    {
216        return this.field_94449_b;
217    }
218}