package net.minecraft.inventory; import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; public class InventoryBasic implements IInventory { private String inventoryTitle; private int slotsCount; private ItemStack[] inventoryContents; private List field_70480_d; public InventoryBasic(String par1Str, int par2) { this.inventoryTitle = par1Str; this.slotsCount = par2; this.inventoryContents = new ItemStack[par2]; } /** * Returns the stack in slot i */ public ItemStack getStackInSlot(int par1) { return this.inventoryContents[par1]; } /** * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a * new stack. */ public ItemStack decrStackSize(int par1, int par2) { if (this.inventoryContents[par1] != null) { ItemStack var3; if (this.inventoryContents[par1].stackSize <= par2) { var3 = this.inventoryContents[par1]; this.inventoryContents[par1] = null; this.onInventoryChanged(); return var3; } else { var3 = this.inventoryContents[par1].splitStack(par2); if (this.inventoryContents[par1].stackSize == 0) { this.inventoryContents[par1] = null; } this.onInventoryChanged(); return var3; } } else { return null; } } /** * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem - * like when you close a workbench GUI. */ public ItemStack getStackInSlotOnClosing(int par1) { if (this.inventoryContents[par1] != null) { ItemStack var2 = this.inventoryContents[par1]; this.inventoryContents[par1] = null; return var2; } else { return null; } } /** * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections). */ public void setInventorySlotContents(int par1, ItemStack par2ItemStack) { this.inventoryContents[par1] = par2ItemStack; if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) { par2ItemStack.stackSize = this.getInventoryStackLimit(); } this.onInventoryChanged(); } /** * Returns the number of slots in the inventory. */ public int getSizeInventory() { return this.slotsCount; } /** * Returns the name of the inventory. */ public String getInvName() { return this.inventoryTitle; } /** * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't * this more of a set than a get?* */ public int getInventoryStackLimit() { return 64; } /** * Called when an the contents of an Inventory change, usually */ public void onInventoryChanged() { if (this.field_70480_d != null) { for (int var1 = 0; var1 < this.field_70480_d.size(); ++var1) { ((IInvBasic)this.field_70480_d.get(var1)).onInventoryChanged(this); } } } /** * Do not make give this method the name canInteractWith because it clashes with Container */ public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) { return true; } public void openChest() {} public void closeChest() {} }