    001package net.minecraft.inventory;
    002
    003import net.minecraft.entity.player.EntityPlayer;
    004import net.minecraft.item.ItemStack;
    005
    006public class InventoryLargeChest implements IInventory
    007{
    008    /** Name of the chest. */
    009    private String name;
    010
    011    /** Inventory object corresponding to double chest upper part */
    012    public IInventory upperChest;
    013
    014    /** Inventory object corresponding to double chest lower part */
    015    public IInventory lowerChest;
    016
    017    public InventoryLargeChest(String par1Str, IInventory par2IInventory, IInventory par3IInventory)
    018    {
    019        this.name = par1Str;
    020
    021        if (par2IInventory == null)
    022        {
    023            par2IInventory = par3IInventory;
    024        }
    025
    026        if (par3IInventory == null)
    027        {
    028            par3IInventory = par2IInventory;
    029        }
    030
    031        this.upperChest = par2IInventory;
    032        this.lowerChest = par3IInventory;
    033    }
    034
    035    /**
    036     * Returns the number of slots in the inventory.
    037     */
    038    public int getSizeInventory()
    039    {
    040        return this.upperChest.getSizeInventory() + this.lowerChest.getSizeInventory();
    041    }
    042
    043    /**
    044     * Return whether the given inventory is part of this large chest.
    045     */
    046    public boolean isPartOfLargeChest(IInventory par1IInventory)
    047    {
    048        return this.upperChest == par1IInventory || this.lowerChest == par1IInventory;
    049    }
    050
    051    /**
    052     * Returns the name of the inventory.
    053     */
    054    public String getInvName()
    055    {
    056        return this.name;
    057    }
    058
    059    /**
    060     * Returns the stack in slot i
    061     */
    062    public ItemStack getStackInSlot(int par1)
    063    {
    064        return par1 >= this.upperChest.getSizeInventory() ? this.lowerChest.getStackInSlot(par1 - this.upperChest.getSizeInventory()) : this.upperChest.getStackInSlot(par1);
    065    }
    066
    067    /**
    068     * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a
    069     * new stack.
    070     */
    071    public ItemStack decrStackSize(int par1, int par2)
    072    {
    073        return par1 >= this.upperChest.getSizeInventory() ? this.lowerChest.decrStackSize(par1 - this.upperChest.getSizeInventory(), par2) : this.upperChest.decrStackSize(par1, par2);
    074    }
    075
    076    /**
    077     * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
    078     * like when you close a workbench GUI.
    079     */
    080    public ItemStack getStackInSlotOnClosing(int par1)
    081    {
    082        return par1 >= this.upperChest.getSizeInventory() ? this.lowerChest.getStackInSlotOnClosing(par1 - this.upperChest.getSizeInventory()) : this.upperChest.getStackInSlotOnClosing(par1);
    083    }
    084
    085    /**
    086     * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
    087     */
    088    public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
    089    {
    090        if (par1 >= this.upperChest.getSizeInventory())
    091        {
    092            this.lowerChest.setInventorySlotContents(par1 - this.upperChest.getSizeInventory(), par2ItemStack);
    093        }
    094        else
    095        {
    096            this.upperChest.setInventorySlotContents(par1, par2ItemStack);
    097        }
    098    }
    099
    100    /**
    101     * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
    102     * this more of a set than a get?*
    103     */
    104    public int getInventoryStackLimit()
    105    {
    106        return this.upperChest.getInventoryStackLimit();
    107    }
    108
    109    /**
    110     * Called when an the contents of an Inventory change, usually
    111     */
    112    public void onInventoryChanged()
    113    {
    114        this.upperChest.onInventoryChanged();
    115        this.lowerChest.onInventoryChanged();
    116    }
    117
    118    /**
    119     * Do not make give this method the name canInteractWith because it clashes with Container
    120     */
    121    public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
    122    {
    123        return this.upperChest.isUseableByPlayer(par1EntityPlayer) && this.lowerChest.isUseableByPlayer(par1EntityPlayer);
    124    }
    125
    126    public void openChest()
    127    {
    128        this.upperChest.openChest();
    129        this.lowerChest.openChest();
    130    }
    131
    132    public void closeChest()
    133    {
    134        this.upperChest.closeChest();
    135        this.lowerChest.closeChest();
    136    }
    137}