/
BrewingRecipeWrapper.java
110 lines (87 loc) · 2.99 KB
/
BrewingRecipeWrapper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package mezz.jei.plugins.vanilla.brewing;
import com.google.common.base.Objects;
import javax.annotation.Nonnull;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import mezz.jei.plugins.vanilla.VanillaRecipeWrapper;
public class BrewingRecipeWrapper extends VanillaRecipeWrapper {
private final List<ItemStack> ingredients;
private final ItemStack potionInput;
private final ItemStack potionOutput;
private final List inputs;
private int brewingSteps;
private final int hashCode;
public BrewingRecipeWrapper(ItemStack ingredient, ItemStack potionInput, ItemStack potionOutput, int brewingSteps) {
this(Collections.singletonList(ingredient), potionInput, potionOutput, brewingSteps);
}
@SuppressWarnings("unchecked")
public BrewingRecipeWrapper(List<ItemStack> ingredients, ItemStack potionInput, ItemStack potionOutput, int brewingSteps) {
this.ingredients = ingredients;
this.potionInput = potionInput;
this.potionOutput = potionOutput;
this.brewingSteps = brewingSteps;
this.inputs = new ArrayList<>();
this.inputs.add(potionInput);
this.inputs.add(potionInput);
this.inputs.add(potionInput);
this.inputs.add(ingredients);
ItemStack firstIngredient = ingredients.get(0);
this.hashCode = Objects.hashCode(potionInput.getMetadata(), potionOutput.getMetadata(), firstIngredient.getItem(), firstIngredient.getMetadata());
}
@Override
public List getInputs() {
return inputs;
}
@Override
public List<ItemStack> getOutputs() {
return Collections.singletonList(potionOutput);
}
@Override
public void drawInfo(@Nonnull Minecraft minecraft) {
if (brewingSteps > 0) {
String steps = StatCollector.translateToLocalFormatted("gui.jei.brewingRecipes.steps", brewingSteps);
minecraft.fontRendererObj.drawString(steps, 70, 28, Color.gray.getRGB());
}
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof BrewingRecipeWrapper)) {
return false;
}
BrewingRecipeWrapper other = (BrewingRecipeWrapper) obj;
if (!arePotionsEqual(other.potionInput, potionInput)) {
return false;
}
if (!arePotionsEqual(other.potionOutput, potionOutput)) {
return false;
}
if (ingredients.size() != other.ingredients.size()) {
return false;
}
for (int i = 0; i < ingredients.size(); i++) {
if (!ItemStack.areItemStacksEqual(ingredients.get(i), other.ingredients.get(i))) {
return false;
}
}
return true;
}
private static boolean arePotionsEqual(ItemStack potion1, ItemStack potion2) {
return potion1.getMetadata() == potion2.getMetadata();
}
public int getBrewingSteps() {
return brewingSteps;
}
@Override
public int hashCode() {
return hashCode;
}
@Override
public String toString() {
return ingredients + " + " + potionInput + " = " + potionOutput;
}
}