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