    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    private IInventory upperChest;
    013
    014    /** Inventory object corresponding to double chest lower part */
    015    private 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.upperChest.func_94042_c() ? this.upperChest.getInvName() : (this.lowerChest.func_94042_c() ? this.lowerChest.getInvName() : this.name);
    057    }
    058
    059    public boolean func_94042_c()
    060    {
    061        return this.upperChest.func_94042_c() || this.lowerChest.func_94042_c();
    062    }
    063
    064    /**
    065     * Returns the stack in slot i
    066     */
    067    public ItemStack getStackInSlot(int par1)
    068    {
    069        return par1 >= this.upperChest.getSizeInventory() ? this.lowerChest.getStackInSlot(par1 - this.upperChest.getSizeInventory()) : this.upperChest.getStackInSlot(par1);
    070    }
    071
    072    /**
    073     * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a
    074     * new stack.
    075     */
    076    public ItemStack decrStackSize(int par1, int par2)
    077    {
    078        return par1 >= this.upperChest.getSizeInventory() ? this.lowerChest.decrStackSize(par1 - this.upperChest.getSizeInventory(), par2) : this.upperChest.decrStackSize(par1, par2);
    079    }
    080
    081    /**
    082     * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
    083     * like when you close a workbench GUI.
    084     */
    085    public ItemStack getStackInSlotOnClosing(int par1)
    086    {
    087        return par1 >= this.upperChest.getSizeInventory() ? this.lowerChest.getStackInSlotOnClosing(par1 - this.upperChest.getSizeInventory()) : this.upperChest.getStackInSlotOnClosing(par1);
    088    }
    089
    090    /**
    091     * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
    092     */
    093    public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
    094    {
    095        if (par1 >= this.upperChest.getSizeInventory())
    096        {
    097            this.lowerChest.setInventorySlotContents(par1 - this.upperChest.getSizeInventory(), par2ItemStack);
    098        }
    099        else
    100        {
    101            this.upperChest.setInventorySlotContents(par1, par2ItemStack);
    102        }
    103    }
    104
    105    /**
    106     * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
    107     * this more of a set than a get?*
    108     */
    109    public int getInventoryStackLimit()
    110    {
    111        return this.upperChest.getInventoryStackLimit();
    112    }
    113
    114    /**
    115     * Called when an the contents of an Inventory change, usually
    116     */
    117    public void onInventoryChanged()
    118    {
    119        this.upperChest.onInventoryChanged();
    120        this.lowerChest.onInventoryChanged();
    121    }
    122
    123    /**
    124     * Do not make give this method the name canInteractWith because it clashes with Container
    125     */
    126    public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
    127    {
    128        return this.upperChest.isUseableByPlayer(par1EntityPlayer) && this.lowerChest.isUseableByPlayer(par1EntityPlayer);
    129    }
    130
    131    public void openChest()
    132    {
    133        this.upperChest.openChest();
    134        this.lowerChest.openChest();
    135    }
    136
    137    public void closeChest()
    138    {
    139        this.upperChest.closeChest();
    140        this.lowerChest.closeChest();
    141    }
    142
    143    public boolean func_94041_b(int par1, ItemStack par2ItemStack)
    144    {
    145        return true;
    146    }
    147}