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