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