/
CauldronRecipeWrapper.java
182 lines (149 loc) · 5.43 KB
/
CauldronRecipeWrapper.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package knightminer.inspirations.plugins.jei.cauldron;
import com.google.common.collect.ImmutableList;
import knightminer.inspirations.library.Util;
import knightminer.inspirations.library.recipe.cauldron.ISimpleCauldronRecipe;
import knightminer.inspirations.plugins.jei.JEIPlugin;
import knightminer.inspirations.plugins.jei.cauldron.ingredient.DyeIngredient;
import knightminer.inspirations.plugins.jei.cauldron.ingredient.PotionIngredient;
import knightminer.inspirations.recipes.block.BlockEnhancedCauldron.CauldronContents;
import net.minecraft.client.Minecraft;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionType;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import java.util.List;
import mezz.jei.api.ingredients.IIngredients;
public class CauldronRecipeWrapper implements ICauldronRecipeWrapper {
private static final FluidStack WATER_STACK = new FluidStack(FluidRegistry.WATER, 1);
protected final List<List<ItemStack>> input;
protected final FluidStack inputFluid;
protected final EnumDyeColor inputColor;
protected final PotionType inputPotion;
protected final int inputLevel;
protected final boolean boiling;
protected final List<ItemStack> output;
protected final FluidStack outputFluid;
protected final EnumDyeColor outputColor;
protected final PotionType outputPotion;
protected final int outputLevel;
public CauldronRecipeWrapper(ISimpleCauldronRecipe recipe) {
this.input = ImmutableList.of(recipe.getInput());
this.inputLevel = MathHelper.clamp(recipe.getInputLevel(), 0, 3);
this.boiling = recipe.isBoiling();
this.output = ImmutableList.of(recipe.getResult());
this.outputLevel = MathHelper.clamp(recipe.getLevel(inputLevel), 0, 3);
// input state
if(inputLevel == 0) {
this.inputFluid = null;
this.inputColor = null;
this.inputPotion = null;
} else {
Object inputState = recipe.getInputState();
this.inputFluid = (inputState instanceof Fluid) ? new FluidStack((Fluid) inputState, inputLevel) : null;
this.inputColor = (inputState instanceof EnumDyeColor) ? (EnumDyeColor) inputState : null;
this.inputPotion = (inputState instanceof PotionType) ? (PotionType) inputState : null;
}
// output state
if(outputLevel == 0) {
this.outputFluid = null;
this.outputColor = null;
this.outputPotion = null;
} else {
Object outputState = recipe.getState();
this.outputFluid = (outputState instanceof Fluid) ? new FluidStack((Fluid) outputState, outputLevel) : null;
this.outputColor = (outputState instanceof EnumDyeColor) ? (EnumDyeColor) outputState : null;
this.outputPotion = (outputState instanceof PotionType) ? (PotionType) outputState : null;
}
}
public CauldronRecipeWrapper(ItemStack input, ItemStack output) {
this(ImmutableList.of(input), output);
}
public CauldronRecipeWrapper(List<ItemStack> input, ItemStack output) {
this.input = ImmutableList.of(input);
this.output = ImmutableList.of(output);
this.inputLevel = 1;
this.outputLevel = 0;
this.boiling = false;
this.inputFluid = WATER_STACK;
this.outputFluid = null;
this.inputColor = this.outputColor = null;
this.inputPotion = this.outputPotion = null;
}
/* Getters used in the category */
@Override
public CauldronContents getInputType() {
return getType(inputLevel, inputFluid, inputColor, inputPotion);
}
@Override
public CauldronContents getOutputType() {
return getType(outputLevel, outputFluid, outputColor, outputPotion);
}
@Override
public int getInputLevel() {
return inputLevel;
}
@Override
public int getOutputLevel() {
return outputLevel;
}
/* JEI methods */
@Override
public void getIngredients(IIngredients ingredients) {
ingredients.setInputLists(ItemStack.class, input);
if(inputFluid != null) {
ingredients.setInput(FluidStack.class, inputFluid);
}
if(inputColor != null) {
ingredients.setInput(DyeIngredient.class, new DyeIngredient(inputColor));
}
if(inputPotion != null) {
ingredients.setInput(PotionIngredient.class, new PotionIngredient(inputPotion));
}
ingredients.setOutputs(ItemStack.class, output);
if(outputFluid != null) {
ingredients.setOutput(FluidStack.class, outputFluid);
}
if(outputColor != null) {
ingredients.setOutput(DyeIngredient.class, new DyeIngredient(outputColor));
}
if(outputPotion != null) {
ingredients.setOutput(PotionIngredient.class, new PotionIngredient(outputPotion));
}
}
@Override
public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) {
if(boiling) {
JEIPlugin.cauldron.fire.draw(minecraft, 45, 36);
}
}
@Override
public List<String> getTooltipStrings(int mouseX, int mouseY) {
List<String> tooltip = ICauldronRecipeWrapper.super.getTooltipStrings(mouseX, mouseY);
if(boiling && mouseX > 45 && mouseX <= 58 && mouseY > 36 && mouseY <= 48) {
tooltip.add(Util.translate("gui.jei.cauldron.boiling"));
}
return tooltip;
}
/* Helpers */
/**
* Quickly gets the type based on the given properties
*/
private static CauldronContents getType(int level, FluidStack fluid, EnumDyeColor color, PotionType potion) {
if(level == 0) {
return null;
}
if(fluid != null) {
return CauldronContents.FLUID;
}
if(color != null) {
return CauldronContents.DYE;
}
if(potion != null) {
return CauldronContents.POTION;
}
return null;
}
}