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