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    /**
117     * If this returns false, the inventory name will be used as an unlocalized name, and translated into the player's
118     * language. Otherwise it will be used directly.
119     */
120    public boolean isInvNameLocalized()
121    {
122        return this.field_94051_e;
123    }
124
125    /**
126     * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
127     * this more of a set than a get?*
128     */
129    public int getInventoryStackLimit()
130    {
131        return 64;
132    }
133
134    /**
135     * Called when an the contents of an Inventory change, usually
136     */
137    public void onInventoryChanged()
138    {
139        if (this.field_70480_d != null)
140        {
141            for (int i = 0; i < this.field_70480_d.size(); ++i)
142            {
143                ((IInvBasic)this.field_70480_d.get(i)).onInventoryChanged(this);
144            }
145        }
146    }
147
148    /**
149     * Do not make give this method the name canInteractWith because it clashes with Container
150     */
151    public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
152    {
153        return true;
154    }
155
156    public void openChest() {}
157
158    public void closeChest() {}
159
160    /**
161     * Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
162     */
163    public boolean isStackValidForSlot(int par1, ItemStack par2ItemStack)
164    {
165        return true;
166    }
167}