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