    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005
    006    public class ContainerBrewingStand extends Container
    007    {
    008        private TileEntityBrewingStand tileBrewingStand;
    009
    010        /** Instance of Slot. */
    011        private final Slot theSlot;
    012        private int brewTime = 0;
    013
    014        public ContainerBrewingStand(InventoryPlayer par1InventoryPlayer, TileEntityBrewingStand par2TileEntityBrewingStand)
    015        {
    016            this.tileBrewingStand = par2TileEntityBrewingStand;
    017            this.addSlotToContainer(new SlotBrewingStandPotion(par1InventoryPlayer.player, par2TileEntityBrewingStand, 0, 56, 46));
    018            this.addSlotToContainer(new SlotBrewingStandPotion(par1InventoryPlayer.player, par2TileEntityBrewingStand, 1, 79, 53));
    019            this.addSlotToContainer(new SlotBrewingStandPotion(par1InventoryPlayer.player, par2TileEntityBrewingStand, 2, 102, 46));
    020            this.theSlot = this.addSlotToContainer(new SlotBrewingStandIngredient(this, par2TileEntityBrewingStand, 3, 79, 17));
    021            int var3;
    022
    023            for (var3 = 0; var3 < 3; ++var3)
    024            {
    025                for (int var4 = 0; var4 < 9; ++var4)
    026                {
    027                    this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
    028                }
    029            }
    030
    031            for (var3 = 0; var3 < 9; ++var3)
    032            {
    033                this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142));
    034            }
    035        }
    036
    037        public void addCraftingToCrafters(ICrafting par1ICrafting)
    038        {
    039            super.addCraftingToCrafters(par1ICrafting);
    040            par1ICrafting.updateCraftingInventoryInfo(this, 0, this.tileBrewingStand.getBrewTime());
    041        }
    042
    043        /**
    044         * Updates crafting matrix; called from onCraftMatrixChanged. Args: none
    045         */
    046        public void updateCraftingResults()
    047        {
    048            super.updateCraftingResults();
    049
    050            for (int var1 = 0; var1 < this.crafters.size(); ++var1)
    051            {
    052                ICrafting var2 = (ICrafting)this.crafters.get(var1);
    053
    054                if (this.brewTime != this.tileBrewingStand.getBrewTime())
    055                {
    056                    var2.updateCraftingInventoryInfo(this, 0, this.tileBrewingStand.getBrewTime());
    057                }
    058            }
    059
    060            this.brewTime = this.tileBrewingStand.getBrewTime();
    061        }
    062
    063        @SideOnly(Side.CLIENT)
    064        public void updateProgressBar(int par1, int par2)
    065        {
    066            if (par1 == 0)
    067            {
    068                this.tileBrewingStand.setBrewTime(par2);
    069            }
    070        }
    071
    072        public boolean canInteractWith(EntityPlayer par1EntityPlayer)
    073        {
    074            return this.tileBrewingStand.isUseableByPlayer(par1EntityPlayer);
    075        }
    076
    077        /**
    078         * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
    079         */
    080        public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    081        {
    082            ItemStack var3 = null;
    083            Slot var4 = (Slot)this.inventorySlots.get(par2);
    084
    085            if (var4 != null && var4.getHasStack())
    086            {
    087                ItemStack var5 = var4.getStack();
    088                var3 = var5.copy();
    089
    090                if ((par2 < 0 || par2 > 2) && par2 != 3)
    091                {
    092                    if (!this.theSlot.getHasStack() && this.theSlot.isItemValid(var5))
    093                    {
    094                        if (!this.mergeItemStack(var5, 3, 4, false))
    095                        {
    096                            return null;
    097                        }
    098                    }
    099                    else if (SlotBrewingStandPotion.func_75243_a_(var3))
    100                    {
    101                        if (!this.mergeItemStack(var5, 0, 3, false))
    102                        {
    103                            return null;
    104                        }
    105                    }
    106                    else if (par2 >= 4 && par2 < 31)
    107                    {
    108                        if (!this.mergeItemStack(var5, 31, 40, false))
    109                        {
    110                            return null;
    111                        }
    112                    }
    113                    else if (par2 >= 31 && par2 < 40)
    114                    {
    115                        if (!this.mergeItemStack(var5, 4, 31, false))
    116                        {
    117                            return null;
    118                        }
    119                    }
    120                    else if (!this.mergeItemStack(var5, 4, 40, false))
    121                    {
    122                        return null;
    123                    }
    124                }
    125                else
    126                {
    127                    if (!this.mergeItemStack(var5, 4, 40, true))
    128                    {
    129                        return null;
    130                    }
    131
    132                    var4.onSlotChange(var5, var3);
    133                }
    134
    135                if (var5.stackSize == 0)
    136                {
    137                    var4.putStack((ItemStack)null);
    138                }
    139                else
    140                {
    141                    var4.onSlotChanged();
    142                }
    143
    144                if (var5.stackSize == var3.stackSize)
    145                {
    146                    return null;
    147                }
    148
    149                var4.onPickupFromSlot(par1EntityPlayer, var5);
    150            }
    151
    152            return var3;
    153        }
    154    }