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