001    package net.minecraft.src;
002    
003    public class SlotMerchantResult extends Slot
004    {
005        private final InventoryMerchant field_75233_a;
006        private EntityPlayer field_75232_b;
007        private int field_75231_g;
008        private final IMerchant field_75234_h;
009    
010        public SlotMerchantResult(EntityPlayer par1EntityPlayer, IMerchant par2IMerchant, InventoryMerchant par3InventoryMerchant, int par4, int par5, int par6)
011        {
012            super(par3InventoryMerchant, par4, par5, par6);
013            this.field_75232_b = par1EntityPlayer;
014            this.field_75234_h = par2IMerchant;
015            this.field_75233_a = par3InventoryMerchant;
016        }
017    
018        /**
019         * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
020         */
021        public boolean isItemValid(ItemStack par1ItemStack)
022        {
023            return false;
024        }
025    
026        /**
027         * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
028         * stack.
029         */
030        public ItemStack decrStackSize(int par1)
031        {
032            if (this.getHasStack())
033            {
034                this.field_75231_g += Math.min(par1, this.getStack().stackSize);
035            }
036    
037            return super.decrStackSize(par1);
038        }
039    
040        /**
041         * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
042         * internal count then calls onCrafting(item).
043         */
044        protected void onCrafting(ItemStack par1ItemStack, int par2)
045        {
046            this.field_75231_g += par2;
047            this.onCrafting(par1ItemStack);
048        }
049    
050        /**
051         * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
052         */
053        protected void onCrafting(ItemStack par1ItemStack)
054        {
055            par1ItemStack.onCrafting(this.field_75232_b.worldObj, this.field_75232_b, this.field_75231_g);
056            this.field_75231_g = 0;
057        }
058    
059        /**
060         * Called when the player picks up an item from an inventory slot
061         */
062        public void onPickupFromSlot(ItemStack par1ItemStack)
063        {
064            this.onCrafting(par1ItemStack);
065            MerchantRecipe var2 = this.field_75233_a.getCurrentRecipe();
066    
067            if (var2 != null)
068            {
069                ItemStack var3 = this.field_75233_a.getStackInSlot(0);
070                ItemStack var4 = this.field_75233_a.getStackInSlot(1);
071    
072                if (this.func_75230_a(var2, var3, var4) || this.func_75230_a(var2, var4, var3))
073                {
074                    if (var3 != null && var3.stackSize <= 0)
075                    {
076                        var3 = null;
077                    }
078    
079                    if (var4 != null && var4.stackSize <= 0)
080                    {
081                        var4 = null;
082                    }
083    
084                    this.field_75233_a.setInventorySlotContents(0, var3);
085                    this.field_75233_a.setInventorySlotContents(1, var4);
086                    this.field_75234_h.useRecipe(var2);
087                }
088            }
089        }
090    
091        private boolean func_75230_a(MerchantRecipe par1MerchantRecipe, ItemStack par2ItemStack, ItemStack par3ItemStack)
092        {
093            ItemStack var4 = par1MerchantRecipe.getItemToBuy();
094            ItemStack var5 = par1MerchantRecipe.getSecondItemToBuy();
095    
096            if (par2ItemStack != null && par2ItemStack.itemID == var4.itemID)
097            {
098                if (var5 != null && par3ItemStack != null && var5.itemID == par3ItemStack.itemID)
099                {
100                    par2ItemStack.stackSize -= var4.stackSize;
101                    par3ItemStack.stackSize -= var5.stackSize;
102                    return true;
103                }
104    
105                if (var5 == null && par3ItemStack == null)
106                {
107                    par2ItemStack.stackSize -= var4.stackSize;
108                    return true;
109                }
110            }
111    
112            return false;
113        }
114    }