    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    private boolean field_94051_e;
    014
    015    public InventoryBasic(String par1Str, boolean par2, int par3)
    016    {
    017        this.inventoryTitle = par1Str;
    018        this.field_94051_e = par2;
    019        this.slotsCount = par3;
    020        this.inventoryContents = new ItemStack[par3];
    021    }
    022
    023    /**
    024     * Returns the stack in slot i
    025     */
    026    public ItemStack getStackInSlot(int par1)
    027    {
    028        return this.inventoryContents[par1];
    029    }
    030
    031    /**
    032     * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a
    033     * new stack.
    034     */
    035    public ItemStack decrStackSize(int par1, int par2)
    036    {
    037        if (this.inventoryContents[par1] != null)
    038        {
    039            ItemStack itemstack;
    040
    041            if (this.inventoryContents[par1].stackSize <= par2)
    042            {
    043                itemstack = this.inventoryContents[par1];
    044                this.inventoryContents[par1] = null;
    045                this.onInventoryChanged();
    046                return itemstack;
    047            }
    048            else
    049            {
    050                itemstack = this.inventoryContents[par1].splitStack(par2);
    051
    052                if (this.inventoryContents[par1].stackSize == 0)
    053                {
    054                    this.inventoryContents[par1] = null;
    055                }
    056
    057                this.onInventoryChanged();
    058                return itemstack;
    059            }
    060        }
    061        else
    062        {
    063            return null;
    064        }
    065    }
    066
    067    /**
    068     * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
    069     * like when you close a workbench GUI.
    070     */
    071    public ItemStack getStackInSlotOnClosing(int par1)
    072    {
    073        if (this.inventoryContents[par1] != null)
    074        {
    075            ItemStack itemstack = this.inventoryContents[par1];
    076            this.inventoryContents[par1] = null;
    077            return itemstack;
    078        }
    079        else
    080        {
    081            return null;
    082        }
    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        this.inventoryContents[par1] = par2ItemStack;
    091
    092        if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
    093        {
    094            par2ItemStack.stackSize = this.getInventoryStackLimit();
    095        }
    096
    097        this.onInventoryChanged();
    098    }
    099
    100    /**
    101     * Returns the number of slots in the inventory.
    102     */
    103    public int getSizeInventory()
    104    {
    105        return this.slotsCount;
    106    }
    107
    108    /**
    109     * Returns the name of the inventory.
    110     */
    111    public String getInvName()
    112    {
    113        return this.inventoryTitle;
    114    }
    115
    116    public boolean func_94042_c()
    117    {
    118        return this.field_94051_e;
    119    }
    120
    121    /**
    122     * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
    123     * this more of a set than a get?*
    124     */
    125    public int getInventoryStackLimit()
    126    {
    127        return 64;
    128    }
    129
    130    /**
    131     * Called when an the contents of an Inventory change, usually
    132     */
    133    public void onInventoryChanged()
    134    {
    135        if (this.field_70480_d != null)
    136        {
    137            for (int i = 0; i < this.field_70480_d.size(); ++i)
    138            {
    139                ((IInvBasic)this.field_70480_d.get(i)).onInventoryChanged(this);
    140            }
    141        }
    142    }
    143
    144    /**
    145     * Do not make give this method the name canInteractWith because it clashes with Container
    146     */
    147    public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
    148    {
    149        return true;
    150    }
    151
    152    public void openChest() {}
    153
    154    public void closeChest() {}
    155
    156    public boolean func_94041_b(int par1, ItemStack par2ItemStack)
    157    {
    158        return true;
    159    }
    160}