-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathCTRecipeBuilder.java
More file actions
164 lines (138 loc) · 5.36 KB
/
CTRecipeBuilder.java
File metadata and controls
164 lines (138 loc) · 5.36 KB
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
package gregtech.api.recipes.crafttweaker;
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.item.IIngredient;
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.liquid.ILiquidStack;
import crafttweaker.api.minecraft.CraftTweakerMC;
import gregtech.api.recipes.CountableIngredient;
import gregtech.api.recipes.RecipeBuilder;
import gregtech.api.recipes.ingredients.IntCircuitIngredient;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.stream.Collectors;
@ZenClass("mods.gregtech.recipe.RecipeBuilder")
@ZenRegister
public class CTRecipeBuilder {
private final RecipeBuilder<?> backingBuilder;
public CTRecipeBuilder(RecipeBuilder<?> backingBuilder) {
this.backingBuilder = backingBuilder;
}
@ZenMethod
public CTRecipeBuilder duration(int duration) {
this.backingBuilder.duration(duration);
return this;
}
@ZenMethod
public CTRecipeBuilder EUt(int EUt) {
this.backingBuilder.EUt(EUt);
return this;
}
@ZenMethod
public CTRecipeBuilder hidden() {
this.backingBuilder.hidden();
return this;
}
@ZenMethod
public CTRecipeBuilder inputs(IIngredient... ingredients) {
this.backingBuilder.inputsIngredients(Arrays.stream(ingredients)
.map(s -> new CountableIngredient(new CraftTweakerIngredientWrapper(s), s.getAmount()))
.collect(Collectors.toList()));
return this;
}
@ZenMethod
public CTRecipeBuilder notConsumable(IIngredient ingredient) {
this.backingBuilder.notConsumable(new CraftTweakerIngredientWrapper(ingredient));
return this;
}
@ZenMethod
public CTRecipeBuilder notConsumable(ILiquidStack ingredient) {
this.backingBuilder.notConsumable(CraftTweakerMC.getLiquidStack(ingredient));
return this;
}
@ZenMethod
public CTRecipeBuilder circuit(int num) {
this.backingBuilder.notConsumable(CraftTweakerIngredientWrapper.fromStacks(IntCircuitIngredient.getIntegratedCircuit(num)));
return this;
}
//note that fluid input predicates are not supported
@ZenMethod
public CTRecipeBuilder fluidInputs(ILiquidStack... ingredients) {
this.backingBuilder.fluidInputs(Arrays.stream(ingredients)
.map(CraftTweakerMC::getLiquidStack)
.collect(Collectors.toList()));
return this;
}
@ZenMethod
public CTRecipeBuilder outputs(IItemStack... ingredients) {
this.backingBuilder.outputs(Arrays.stream(ingredients)
.map(CraftTweakerMC::getItemStack)
.collect(Collectors.toList()));
return this;
}
@ZenMethod
public CTRecipeBuilder chancedOutput(IItemStack outputStack, int chanceValue, int tierChanceBoost) {
this.backingBuilder.chancedOutput(CraftTweakerMC.getItemStack(outputStack), chanceValue, tierChanceBoost);
return this;
}
@ZenMethod
public CTRecipeBuilder fluidOutputs(ILiquidStack... ingredients) {
this.backingBuilder.fluidOutputs(Arrays.stream(ingredients)
.map(CraftTweakerMC::getLiquidStack)
.collect(Collectors.toList()));
return this;
}
@ZenMethod
public CTRecipeBuilder property(String key, int value) {
boolean applied = this.backingBuilder.applyProperty(key, value);
if (!applied) {
throw new IllegalArgumentException("Property " +
key + " cannot be applied to recipe type " +
backingBuilder.getClass().getSimpleName());
}
return this;
}
@ZenMethod
public CTRecipeBuilder property(String key, IItemStack item) {
boolean applied = this.backingBuilder.applyProperty(key, CraftTweakerMC.getItemStack(item));
if (!applied) {
throw new IllegalArgumentException("Property " +
key + " cannot be applied to recipe type " +
backingBuilder.getClass().getSimpleName() + " for Item " + CraftTweakerMC.getItemStack(item).getDisplayName());
}
return this;
}
@ZenMethod
public void buildAndRegister() {
this.backingBuilder.buildAndRegister();
}
@ZenMethod
@Override
public String toString() {
return this.backingBuilder.toString();
}
public static class CraftTweakerIngredientWrapper extends Ingredient {
private final IIngredient ingredient;
public CraftTweakerIngredientWrapper(IIngredient ingredient) {
super(ingredient.getItems().stream()
.map(CraftTweakerMC::getItemStack)
.toArray(ItemStack[]::new));
this.ingredient = ingredient;
}
@Override
public boolean apply(@Nullable ItemStack itemStack) {
if (itemStack == null) {
// Avoiding NPE
itemStack = ItemStack.EMPTY;
}
//because CT is dump enough to compare stack sizes by default...
// Setting stack size to 1 to avoid problem with non-consumable ingredients (count - 0)
IItemStack stack = CraftTweakerMC.getIItemStack(itemStack).amount(1);
return ingredient.amount(1)
.matches(stack);
}
}
}