    001    package net.minecraft.src;
    002
    003    public class ContainerChest extends Container
    004    {
    005        private IInventory lowerChestInventory;
    006        private int numRows;
    007
    008        public ContainerChest(IInventory par1IInventory, IInventory par2IInventory)
    009        {
    010            this.lowerChestInventory = par2IInventory;
    011            this.numRows = par2IInventory.getSizeInventory() / 9;
    012            par2IInventory.openChest();
    013            int var3 = (this.numRows - 4) * 18;
    014            int var4;
    015            int var5;
    016
    017            for (var4 = 0; var4 < this.numRows; ++var4)
    018            {
    019                for (var5 = 0; var5 < 9; ++var5)
    020                {
    021                    this.addSlotToContainer(new Slot(par2IInventory, var5 + var4 * 9, 8 + var5 * 18, 18 + var4 * 18));
    022                }
    023            }
    024
    025            for (var4 = 0; var4 < 3; ++var4)
    026            {
    027                for (var5 = 0; var5 < 9; ++var5)
    028                {
    029                    this.addSlotToContainer(new Slot(par1IInventory, var5 + var4 * 9 + 9, 8 + var5 * 18, 103 + var4 * 18 + var3));
    030                }
    031            }
    032
    033            for (var4 = 0; var4 < 9; ++var4)
    034            {
    035                this.addSlotToContainer(new Slot(par1IInventory, var4, 8 + var4 * 18, 161 + var3));
    036            }
    037        }
    038
    039        public boolean canInteractWith(EntityPlayer par1EntityPlayer)
    040        {
    041            return this.lowerChestInventory.isUseableByPlayer(par1EntityPlayer);
    042        }
    043
    044        public ItemStack func_82846_b(EntityPlayer par1EntityPlayer, int par2)
    045        {
    046            ItemStack var3 = null;
    047            Slot var4 = (Slot)this.inventorySlots.get(par2);
    048
    049            if (var4 != null && var4.getHasStack())
    050            {
    051                ItemStack var5 = var4.getStack();
    052                var3 = var5.copy();
    053
    054                if (par2 < this.numRows * 9)
    055                {
    056                    if (!this.mergeItemStack(var5, this.numRows * 9, this.inventorySlots.size(), true))
    057                    {
    058                        return null;
    059                    }
    060                }
    061                else if (!this.mergeItemStack(var5, 0, this.numRows * 9, false))
    062                {
    063                    return null;
    064                }
    065
    066                if (var5.stackSize == 0)
    067                {
    068                    var4.putStack((ItemStack)null);
    069                }
    070                else
    071                {
    072                    var4.onSlotChanged();
    073                }
    074            }
    075
    076            return var3;
    077        }
    078
    079        /**
    080         * Callback for when the crafting gui is closed.
    081         */
    082        public void onCraftGuiClosed(EntityPlayer par1EntityPlayer)
    083        {
    084            super.onCraftGuiClosed(par1EntityPlayer);
    085            this.lowerChestInventory.closeChest();
    086        }
    087    }