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