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