    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        public ItemStack func_82846_b(EntityPlayer par1EntityPlayer, int par2)
    080        {
    081            ItemStack var3 = null;
    082            Slot var4 = (Slot)this.inventorySlots.get(par2);
    083
    084            if (var4 != null && var4.getHasStack())
    085            {
    086                ItemStack var5 = var4.getStack();
    087                var3 = var5.copy();
    088
    089                if ((par2 < 0 || par2 > 2) && par2 != 3)
    090                {
    091                    if (!this.theSlot.getHasStack() && this.theSlot.isItemValid(var5))
    092                    {
    093                        if (!this.mergeItemStack(var5, 3, 4, false))
    094                        {
    095                            return null;
    096                        }
    097                    }
    098                    else if (SlotBrewingStandPotion.func_75243_a_(var3))
    099                    {
    100                        if (!this.mergeItemStack(var5, 0, 3, false))
    101                        {
    102                            return null;
    103                        }
    104                    }
    105                    else if (par2 >= 4 && par2 < 31)
    106                    {
    107                        if (!this.mergeItemStack(var5, 31, 40, false))
    108                        {
    109                            return null;
    110                        }
    111                    }
    112                    else if (par2 >= 31 && par2 < 40)
    113                    {
    114                        if (!this.mergeItemStack(var5, 4, 31, false))
    115                        {
    116                            return null;
    117                        }
    118                    }
    119                    else if (!this.mergeItemStack(var5, 4, 40, false))
    120                    {
    121                        return null;
    122                    }
    123                }
    124                else
    125                {
    126                    if (!this.mergeItemStack(var5, 4, 40, true))
    127                    {
    128                        return null;
    129                    }
    130
    131                    var4.onSlotChange(var5, var3);
    132                }
    133
    134                if (var5.stackSize == 0)
    135                {
    136                    var4.putStack((ItemStack)null);
    137                }
    138                else
    139                {
    140                    var4.onSlotChanged();
    141                }
    142
    143                if (var5.stackSize == var3.stackSize)
    144                {
    145                    return null;
    146                }
    147
    148                var4.func_82870_a(par1EntityPlayer, var5);
    149            }
    150
    151            return var3;
    152        }
    153    }