    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 var4 = par2 * par3;
    022        this.stackList = new ItemStack[var4];
    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 var3 = par1 + par2 * this.inventoryWidth;
    051            return this.getStackInSlot(var3);
    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    /**
    068     * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
    069     * like when you close a workbench GUI.
    070     */
    071    public ItemStack getStackInSlotOnClosing(int par1)
    072    {
    073        if (this.stackList[par1] != null)
    074        {
    075            ItemStack var2 = this.stackList[par1];
    076            this.stackList[par1] = null;
    077            return var2;
    078        }
    079        else
    080        {
    081            return null;
    082        }
    083    }
    084
    085    /**
    086     * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a
    087     * new stack.
    088     */
    089    public ItemStack decrStackSize(int par1, int par2)
    090    {
    091        if (this.stackList[par1] != null)
    092        {
    093            ItemStack var3;
    094
    095            if (this.stackList[par1].stackSize <= par2)
    096            {
    097                var3 = this.stackList[par1];
    098                this.stackList[par1] = null;
    099                this.eventHandler.onCraftMatrixChanged(this);
    100                return var3;
    101            }
    102            else
    103            {
    104                var3 = this.stackList[par1].splitStack(par2);
    105
    106                if (this.stackList[par1].stackSize == 0)
    107                {
    108                    this.stackList[par1] = null;
    109                }
    110
    111                this.eventHandler.onCraftMatrixChanged(this);
    112                return var3;
    113            }
    114        }
    115        else
    116        {
    117            return null;
    118        }
    119    }
    120
    121    /**
    122     * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
    123     */
    124    public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
    125    {
    126        this.stackList[par1] = par2ItemStack;
    127        this.eventHandler.onCraftMatrixChanged(this);
    128    }
    129
    130    /**
    131     * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
    132     * this more of a set than a get?*
    133     */
    134    public int getInventoryStackLimit()
    135    {
    136        return 64;
    137    }
    138
    139    /**
    140     * Called when an the contents of an Inventory change, usually
    141     */
    142    public void onInventoryChanged() {}
    143
    144    /**
    145     * Do not make give this method the name canInteractWith because it clashes with Container
    146     */
    147    public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
    148    {
    149        return true;
    150    }
    151
    152    public void openChest() {}
    153
    154    public void closeChest() {}
    155}