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 MerchantRecipe
007    {
008        /** Item the Villager buys. */
009        private ItemStack itemToBuy;
010    
011        /** Second Item the Villager buys. */
012        private ItemStack secondItemToBuy;
013    
014        /** Item the Villager sells. */
015        private ItemStack itemToSell;
016    
017        /**
018         * Saves how much has been tool used when put into to slot to be enchanted.
019         */
020        private int toolUses;
021        private int field_82786_e;
022    
023        public MerchantRecipe(NBTTagCompound par1NBTTagCompound)
024        {
025            this.readFromTags(par1NBTTagCompound);
026        }
027    
028        public MerchantRecipe(ItemStack par1ItemStack, ItemStack par2ItemStack, ItemStack par3ItemStack)
029        {
030            this.itemToBuy = par1ItemStack;
031            this.secondItemToBuy = par2ItemStack;
032            this.itemToSell = par3ItemStack;
033            this.field_82786_e = 7;
034        }
035    
036        public MerchantRecipe(ItemStack par1ItemStack, ItemStack par2ItemStack)
037        {
038            this(par1ItemStack, (ItemStack)null, par2ItemStack);
039        }
040    
041        public MerchantRecipe(ItemStack par1ItemStack, Item par2Item)
042        {
043            this(par1ItemStack, new ItemStack(par2Item));
044        }
045    
046        /**
047         * Gets the itemToBuy.
048         */
049        public ItemStack getItemToBuy()
050        {
051            return this.itemToBuy;
052        }
053    
054        /**
055         * Gets secondItemToBuy.
056         */
057        public ItemStack getSecondItemToBuy()
058        {
059            return this.secondItemToBuy;
060        }
061    
062        /**
063         * Gets if Villager has secondItemToBuy.
064         */
065        public boolean hasSecondItemToBuy()
066        {
067            return this.secondItemToBuy != null;
068        }
069    
070        /**
071         * Gets itemToSell.
072         */
073        public ItemStack getItemToSell()
074        {
075            return this.itemToSell;
076        }
077    
078        /**
079         * checks if both the first and second ItemToBuy IDs are the same
080         */
081        public boolean hasSameIDsAs(MerchantRecipe par1MerchantRecipe)
082        {
083            return this.itemToBuy.itemID == par1MerchantRecipe.itemToBuy.itemID && this.itemToSell.itemID == par1MerchantRecipe.itemToSell.itemID ? this.secondItemToBuy == null && par1MerchantRecipe.secondItemToBuy == null || this.secondItemToBuy != null && par1MerchantRecipe.secondItemToBuy != null && this.secondItemToBuy.itemID == par1MerchantRecipe.secondItemToBuy.itemID : false;
084        }
085    
086        /**
087         * checks first and second ItemToBuy ID's and count. Calls hasSameIDs
088         */
089        public boolean hasSameItemsAs(MerchantRecipe par1MerchantRecipe)
090        {
091            return this.hasSameIDsAs(par1MerchantRecipe) && (this.itemToBuy.stackSize < par1MerchantRecipe.itemToBuy.stackSize || this.secondItemToBuy != null && this.secondItemToBuy.stackSize < par1MerchantRecipe.secondItemToBuy.stackSize);
092        }
093    
094        public void incrementToolUses()
095        {
096            ++this.toolUses;
097        }
098    
099        public void func_82783_a(int par1)
100        {
101            this.field_82786_e += par1;
102        }
103    
104        public boolean func_82784_g()
105        {
106            return this.toolUses >= this.field_82786_e;
107        }
108    
109        @SideOnly(Side.CLIENT)
110        public void func_82785_h()
111        {
112            this.toolUses = this.field_82786_e;
113        }
114    
115        public void readFromTags(NBTTagCompound par1NBTTagCompound)
116        {
117            NBTTagCompound var2 = par1NBTTagCompound.getCompoundTag("buy");
118            this.itemToBuy = ItemStack.loadItemStackFromNBT(var2);
119            NBTTagCompound var3 = par1NBTTagCompound.getCompoundTag("sell");
120            this.itemToSell = ItemStack.loadItemStackFromNBT(var3);
121    
122            if (par1NBTTagCompound.hasKey("buyB"))
123            {
124                this.secondItemToBuy = ItemStack.loadItemStackFromNBT(par1NBTTagCompound.getCompoundTag("buyB"));
125            }
126    
127            if (par1NBTTagCompound.hasKey("uses"))
128            {
129                this.toolUses = par1NBTTagCompound.getInteger("uses");
130            }
131    
132            if (par1NBTTagCompound.hasKey("maxUses"))
133            {
134                this.field_82786_e = par1NBTTagCompound.getInteger("maxUses");
135            }
136            else
137            {
138                this.field_82786_e = 7;
139            }
140        }
141    
142        public NBTTagCompound writeToTags()
143        {
144            NBTTagCompound var1 = new NBTTagCompound();
145            var1.setCompoundTag("buy", this.itemToBuy.writeToNBT(new NBTTagCompound("buy")));
146            var1.setCompoundTag("sell", this.itemToSell.writeToNBT(new NBTTagCompound("sell")));
147    
148            if (this.secondItemToBuy != null)
149            {
150                var1.setCompoundTag("buyB", this.secondItemToBuy.writeToNBT(new NBTTagCompound("buyB")));
151            }
152    
153            var1.setInteger("uses", this.toolUses);
154            var1.setInteger("maxUses", this.field_82786_e);
155            return var1;
156        }
157    }