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