    001    package net.minecraft.inventory;
    002
    003    import net.minecraft.entity.player.EntityPlayer;
    004    import net.minecraft.item.ItemStack;
    005
    006    public class ContainerChest extends Container
    007    {
    008        private IInventory lowerChestInventory;
    009        private int numRows;
    010
    011        public ContainerChest(IInventory par1IInventory, IInventory par2IInventory)
    012        {
    013            this.lowerChestInventory = par2IInventory;
    014            this.numRows = par2IInventory.getSizeInventory() / 9;
    015            par2IInventory.openChest();
    016            int var3 = (this.numRows - 4) * 18;
    017            int var4;
    018            int var5;
    019
    020            for (var4 = 0; var4 < this.numRows; ++var4)
    021            {
    022                for (var5 = 0; var5 < 9; ++var5)
    023                {
    024                    this.addSlotToContainer(new Slot(par2IInventory, var5 + var4 * 9, 8 + var5 * 18, 18 + var4 * 18));
    025                }
    026            }
    027
    028            for (var4 = 0; var4 < 3; ++var4)
    029            {
    030                for (var5 = 0; var5 < 9; ++var5)
    031                {
    032                    this.addSlotToContainer(new Slot(par1IInventory, var5 + var4 * 9 + 9, 8 + var5 * 18, 103 + var4 * 18 + var3));
    033                }
    034            }
    035
    036            for (var4 = 0; var4 < 9; ++var4)
    037            {
    038                this.addSlotToContainer(new Slot(par1IInventory, var4, 8 + var4 * 18, 161 + var3));
    039            }
    040        }
    041
    042        public boolean canInteractWith(EntityPlayer par1EntityPlayer)
    043        {
    044            return this.lowerChestInventory.isUseableByPlayer(par1EntityPlayer);
    045        }
    046
    047        /**
    048         * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
    049         */
    050        public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    051        {
    052            ItemStack var3 = null;
    053            Slot var4 = (Slot)this.inventorySlots.get(par2);
    054
    055            if (var4 != null && var4.getHasStack())
    056            {
    057                ItemStack var5 = var4.getStack();
    058                var3 = var5.copy();
    059
    060                if (par2 < this.numRows * 9)
    061                {
    062                    if (!this.mergeItemStack(var5, this.numRows * 9, this.inventorySlots.size(), true))
    063                    {
    064                        return null;
    065                    }
    066                }
    067                else if (!this.mergeItemStack(var5, 0, this.numRows * 9, false))
    068                {
    069                    return null;
    070                }
    071
    072                if (var5.stackSize == 0)
    073                {
    074                    var4.putStack((ItemStack)null);
    075                }
    076                else
    077                {
    078                    var4.onSlotChanged();
    079                }
    080            }
    081
    082            return var3;
    083        }
    084
    085        /**
    086         * Callback for when the crafting gui is closed.
    087         */
    088        public void onCraftGuiClosed(EntityPlayer par1EntityPlayer)
    089        {
    090            super.onCraftGuiClosed(par1EntityPlayer);
    091            this.lowerChestInventory.closeChest();
    092        }
    093
    094        /**
    095         * Return this chest container's lower chest inventory.
    096         */
    097        public IInventory getLowerChestInventory()
    098        {
    099            return this.lowerChestInventory;
    100        }
    101    }