MerchantRecipe .java

net.minecraft.village.MerchantRecipe (class): members: increaseMaxTradeUses, compensateToolUses, getSecondItemToBuy, hasSecondItemToBuy, incrementToolUses.

net.minecraft.villageclass181 linescommon4.4 KB

API Surface (13)

ItemStack getItemToBuy()
ItemStack getSecondItemToBuy()
boolean hasSecondItemToBuy()
ItemStack getItemToSell()
int getToolUses()
int getMaxTradeUses()
void incrementToolUses()
void increaseMaxTradeUses(int increment)
boolean isRecipeDisabled()
void compensateToolUses()
boolean getRewardsExp()
void readFromTags(NBTTagCompound tagCompound)
NBTTagCompound writeToTags()

Fields & Constants (6)

itemToBuy
secondItemToBuy
itemToSell
toolUses
maxTradeUses
rewardsExp

String literals (5)

"sell"
"buyB"
"uses"
"maxUses"
"rewardExp"

Code Graph: Dependencies (3)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

MerchantRecipe.java181 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.village;
2
3
import net.minecraft.item.Item;
4
import net.minecraft.item.ItemStack;
5
import net.minecraft.nbt.NBTTagCompound;
6
7
public class MerchantRecipe
8
{
9
    /** Item the Villager buys. */
10
    private ItemStack itemToBuy;
11
12
    /** Second Item the Villager buys. */
13
    private ItemStack secondItemToBuy;
14
15
    /** Item the Villager sells. */
16
    private ItemStack itemToSell;
17
18
    /**
19
     * Saves how much has been tool used when put into to slot to be enchanted.
20
     */
21
    private int toolUses;
22
23
    /** Maximum times this trade can be used. */
24
    private int maxTradeUses;
25
    private boolean rewardsExp;
26
27
    public MerchantRecipe(NBTTagCompound tagCompound)
28
    {
29
        this.readFromTags(tagCompound);
30
    }
31
32
    public MerchantRecipe(ItemStack buy1, ItemStack buy2, ItemStack sell)
33
    {
34
        this(buy1, buy2, sell, 0, 7);
35
    }
36
37
    public MerchantRecipe(ItemStack buy1, ItemStack buy2, ItemStack sell, int toolUsesIn, int maxTradeUsesIn)
38
    {
39
        this.itemToBuy = buy1;
40
        this.secondItemToBuy = buy2;
41
        this.itemToSell = sell;
42
        this.toolUses = toolUsesIn;
43
        this.maxTradeUses = maxTradeUsesIn;
44
        this.rewardsExp = true;
45
    }
46
47
    public MerchantRecipe(ItemStack buy1, ItemStack sell)
48
    {
49
        this(buy1, (ItemStack)null, sell);
50
    }
51
52
    public MerchantRecipe(ItemStack buy1, Item sellItem)
53
    {
54
        this(buy1, new ItemStack(sellItem));
55
    }
56
57
    /**
58
     * Gets the itemToBuy.
59
     */
60
    public ItemStack getItemToBuy()
61
    {
62
        return this.itemToBuy;
63
    }
64
65
    /**
66
     * Gets secondItemToBuy.
67
     */
68
    public ItemStack getSecondItemToBuy()
69
    {
70
        return this.secondItemToBuy;
71
    }
72
73
    /**
74
     * Gets if Villager has secondItemToBuy.
75
     */
76
    public boolean hasSecondItemToBuy()
77
    {
78
        return this.secondItemToBuy != null;
79
    }
80
81
    /**
82
     * Gets itemToSell.
83
     */
84
    public ItemStack getItemToSell()
85
    {
86
        return this.itemToSell;
87
    }
88
89
    public int getToolUses()
90
    {
91
        return this.toolUses;
92
    }
93
94
    public int getMaxTradeUses()
95
    {
96
        return this.maxTradeUses;
97
    }
98
99
    public void incrementToolUses()
100
    {
101
        ++this.toolUses;
102
    }
103
104
    public void increaseMaxTradeUses(int increment)
105
    {
106
        this.maxTradeUses += increment;
107
    }
108
109
    public boolean isRecipeDisabled()
110
    {
111
        return this.toolUses >= this.maxTradeUses;
112
    }
113
114
    /**
115
     * Compensates {@link net.minecraft.village.MerchantRecipe#toolUses toolUses} with {@link
116
     * net.minecraft.village.MerchantRecipe#maxTradeUses maxTradeUses}
117
     */
118
    public void compensateToolUses()
119
    {
120
        this.toolUses = this.maxTradeUses;
121
    }
122
123
    public boolean getRewardsExp()
124
    {
125
        return this.rewardsExp;
126
    }
127
128
    public void readFromTags(NBTTagCompound tagCompound)
129
    {
130
        NBTTagCompound nbttagcompound = tagCompound.getCompoundTag("buy");
131
        this.itemToBuy = ItemStack.loadItemStackFromNBT(nbttagcompound);
132
        NBTTagCompound nbttagcompound1 = tagCompound.getCompoundTag("sell");
133
        this.itemToSell = ItemStack.loadItemStackFromNBT(nbttagcompound1);
134
135
        if (tagCompound.hasKey("buyB", 10))
136
        {
137
            this.secondItemToBuy = ItemStack.loadItemStackFromNBT(tagCompound.getCompoundTag("buyB"));
138
        }
139
140
        if (tagCompound.hasKey("uses", 99))
141
        {
142
            this.toolUses = tagCompound.getInteger("uses");
143
        }
144
145
        if (tagCompound.hasKey("maxUses", 99))
146
        {
147
            this.maxTradeUses = tagCompound.getInteger("maxUses");
148
        }
149
        else
150
        {
151
            this.maxTradeUses = 7;
152
        }
153
154
        if (tagCompound.hasKey("rewardExp", 1))
155
        {
156
            this.rewardsExp = tagCompound.getBoolean("rewardExp");
157
        }
158
        else
159
        {
160
            this.rewardsExp = true;
161
        }
162
    }
163
164
    public NBTTagCompound writeToTags()
165
    {
166
        NBTTagCompound nbttagcompound = new NBTTagCompound();
167
        nbttagcompound.setTag("buy", this.itemToBuy.writeToNBT(new NBTTagCompound()));
168
        nbttagcompound.setTag("sell", this.itemToSell.writeToNBT(new NBTTagCompound()));
169
170
        if (this.secondItemToBuy != null)
171
        {
172
            nbttagcompound.setTag("buyB", this.secondItemToBuy.writeToNBT(new NBTTagCompound()));
173
        }
174
175
        nbttagcompound.setInteger("uses", this.toolUses);
176
        nbttagcompound.setInteger("maxUses", this.maxTradeUses);
177
        nbttagcompound.setBoolean("rewardExp", this.rewardsExp);
178
        return nbttagcompound;
179
    }
180
}
181

Deobfuscated MCP 1.8.9 source of MerchantRecipe from Marcelektro/MavenMCP-1.8.9 (net/minecraft/village/MerchantRecipe.java), stored verbatim.