    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        public void func_82870_a(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack)
    062        {
    063            this.onSlotChanged();
    064        }
    065
    066        /**
    067         * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
    068         */
    069        public boolean isItemValid(ItemStack par1ItemStack)
    070        {
    071            return true;
    072        }
    073
    074        /**
    075         * Helper fnct to get the stack in the slot.
    076         */
    077        public ItemStack getStack()
    078        {
    079            return this.inventory.getStackInSlot(this.slotIndex);
    080        }
    081
    082        /**
    083         * Returns if this slot contains a stack.
    084         */
    085        public boolean getHasStack()
    086        {
    087            return this.getStack() != null;
    088        }
    089
    090        /**
    091         * Helper method to put a stack in the slot.
    092         */
    093        public void putStack(ItemStack par1ItemStack)
    094        {
    095            this.inventory.setInventorySlotContents(this.slotIndex, par1ItemStack);
    096            this.onSlotChanged();
    097        }
    098
    099        /**
    100         * Called when the stack in a Slot changes
    101         */
    102        public void onSlotChanged()
    103        {
    104            this.inventory.onInventoryChanged();
    105        }
    106
    107        /**
    108         * Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 in the case
    109         * of armor slots)
    110         */
    111        public int getSlotStackLimit()
    112        {
    113            return this.inventory.getInventoryStackLimit();
    114        }
    115
    116        /**
    117         * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
    118         * stack.
    119         */
    120        public ItemStack decrStackSize(int par1)
    121        {
    122            return this.inventory.decrStackSize(this.slotIndex, par1);
    123        }
    124
    125        /**
    126         * returns true if this slot is in par2 of par1
    127         */
    128        public boolean isSlotInInventory(IInventory par1IInventory, int par2)
    129        {
    130            return par1IInventory == this.inventory && par2 == this.slotIndex;
    131        }
    132
    133        public boolean func_82869_a(EntityPlayer par1EntityPlayer)
    134        {
    135            return true;
    136        }
    137
    138        @SideOnly(Side.CLIENT)
    139
    140        /**
    141         * Returns the icon index on items.png that is used as background image of the slot.
    142         */
    143        public int getBackgroundIconIndex()
    144        {
    145            return -1;
    146        }
    147    }