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