    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005
    006    public class Slot
    007    {
    008        /** The index of the slot in the inventory. */
    009        private final int slotIndex;
    010
    011        /** The inventory we want to extract a slot from. */
    012        public final IInventory inventory;
    013
    014        /** the id of the slot(also the index in the inventory arraylist) */
    015        public int slotNumber;
    016
    017        /** display position of the inventory slot on the screen x axis */
    018        public int xDisplayPosition;
    019
    020        /** display position of the inventory slot on the screen y axis */
    021        public int yDisplayPosition;
    022
    023        public Slot(IInventory par1IInventory, int par2, int par3, int par4)
    024        {
    025            this.inventory = par1IInventory;
    026            this.slotIndex = par2;
    027            this.xDisplayPosition = par3;
    028            this.yDisplayPosition = par4;
    029        }
    030
    031        /**
    032         * if par2 has more items than par1, onCrafting(item,countIncrease) is called
    033         */
    034        public void onSlotChange(ItemStack par1ItemStack, ItemStack par2ItemStack)
    035        {
    036            if (par1ItemStack != null && par2ItemStack != null)
    037            {
    038                if (par1ItemStack.itemID == par2ItemStack.itemID)
    039                {
    040                    int var3 = par2ItemStack.stackSize - par1ItemStack.stackSize;
    041
    042                    if (var3 > 0)
    043                    {
    044                        this.onCrafting(par1ItemStack, var3);
    045                    }
    046                }
    047            }
    048        }
    049
    050        /**
    051         * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
    052         * internal count then calls onCrafting(item).
    053         */
    054        protected void onCrafting(ItemStack par1ItemStack, int par2) {}
    055
    056        /**
    057         * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
    058         */
    059        protected void onCrafting(ItemStack par1ItemStack) {}
    060
    061        /**
    062         * Called when the player picks up an item from an inventory slot
    063         */
    064        public void onPickupFromSlot(ItemStack par1ItemStack)
    065        {
    066            this.onSlotChanged();
    067        }
    068
    069        /**
    070         * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
    071         */
    072        public boolean isItemValid(ItemStack par1ItemStack)
    073        {
    074            return true;
    075        }
    076
    077        /**
    078         * Helper fnct to get the stack in the slot.
    079         */
    080        public ItemStack getStack()
    081        {
    082            return this.inventory.getStackInSlot(this.slotIndex);
    083        }
    084
    085        /**
    086         * Returns if this slot contains a stack.
    087         */
    088        public boolean getHasStack()
    089        {
    090            return this.getStack() != null;
    091        }
    092
    093        /**
    094         * Helper method to put a stack in the slot.
    095         */
    096        public void putStack(ItemStack par1ItemStack)
    097        {
    098            this.inventory.setInventorySlotContents(this.slotIndex, par1ItemStack);
    099            this.onSlotChanged();
    100        }
    101
    102        /**
    103         * Called when the stack in a Slot changes
    104         */
    105        public void onSlotChanged()
    106        {
    107            this.inventory.onInventoryChanged();
    108        }
    109
    110        /**
    111         * Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 in the case
    112         * of armor slots)
    113         */
    114        public int getSlotStackLimit()
    115        {
    116            return this.inventory.getInventoryStackLimit();
    117        }
    118
    119        /**
    120         * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
    121         * stack.
    122         */
    123        public ItemStack decrStackSize(int par1)
    124        {
    125            return this.inventory.decrStackSize(this.slotIndex, par1);
    126        }
    127
    128        /**
    129         * returns true if this slot is in par2 of par1
    130         */
    131        public boolean isSlotInInventory(IInventory par1IInventory, int par2)
    132        {
    133            return par1IInventory == this.inventory && par2 == this.slotIndex;
    134        }
    135
    136        @SideOnly(Side.CLIENT)
    137
    138        /**
    139         * Returns the icon index on items.png that is used as background image of the slot.
    140         */
    141        public int getBackgroundIconIndex()
    142        {
    143            return -1;
    144        }
    145    }