-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathRecipeMapBuilder.java
More file actions
317 lines (276 loc) · 10.3 KB
/
Copy pathRecipeMapBuilder.java
File metadata and controls
317 lines (276 loc) · 10.3 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
package gregtech.api.recipes;
import gregtech.api.gui.resources.TextureArea;
import gregtech.api.gui.widgets.ProgressWidget;
import gregtech.api.recipes.ui.RecipeMapUI;
import gregtech.api.recipes.ui.RecipeMapUIFunction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import it.unimi.dsi.fastutil.bytes.Byte2ObjectArrayMap;
import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import static gregtech.api.recipes.ui.RecipeMapUI.computeOverlayKey;
public class RecipeMapBuilder<B extends RecipeBuilder<B>> {
private final String unlocalizedName;
private final B defaultRecipeBuilder;
private final Byte2ObjectMap<TextureArea> slotOverlays = new Byte2ObjectArrayMap<>();
private int itemInputs;
private boolean modifyItemInputs = true;
private int itemOutputs;
private boolean modifyItemOutputs = true;
private int fluidInputs;
private boolean modifyFluidInputs = true;
private int fluidOutputs;
private boolean modifyFluidOutputs = true;
private boolean isGenerator;
private @Nullable TextureArea progressBar;
private @Nullable ProgressWidget.MoveType moveType;
private @Nullable TextureArea specialTexture;
private int @Nullable [] specialTextureLocation;
private RecipeMapUIFunction recipeMapUIFunction = this::buildUI;
private SoundEvent sound;
private boolean allowEmptyOutputs;
private @Nullable Map<ResourceLocation, RecipeBuildAction<B>> buildActions;
private boolean sortToBack;
/**
* @param unlocalizedName the name of the recipemap
* @param defaultRecipeBuilder the default recipe builder of the recipemap
*/
public RecipeMapBuilder(@NotNull String unlocalizedName, @NotNull B defaultRecipeBuilder) {
this.unlocalizedName = unlocalizedName;
this.defaultRecipeBuilder = defaultRecipeBuilder;
}
/**
* @param itemInputs the amount of item inputs
* @return this
*/
public @NotNull RecipeMapBuilder<B> itemInputs(int itemInputs) {
this.itemInputs = itemInputs;
return this;
}
/**
* @param modifyItemInputs if item input limit modification should be allowed
* @return this
*/
public @NotNull RecipeMapBuilder<B> modifyItemInputs(boolean modifyItemInputs) {
this.modifyItemInputs = modifyItemInputs;
return this;
}
/**
* @param itemOutputs the amount of item outputs
* @return this
*/
public @NotNull RecipeMapBuilder<B> itemOutputs(int itemOutputs) {
this.itemOutputs = itemOutputs;
return this;
}
/**
* @param modifyItemOutputs if item output limit modification should be allowed
* @return this
*/
public @NotNull RecipeMapBuilder<B> modifyItemOutputs(boolean modifyItemOutputs) {
this.modifyItemOutputs = modifyItemOutputs;
return this;
}
/**
* @param fluidInputs the amount of fluid inputs
* @return this
*/
public @NotNull RecipeMapBuilder<B> fluidInputs(int fluidInputs) {
this.fluidInputs = fluidInputs;
return this;
}
/**
* @param modifyFluidInputs if fluid input limit modification should be allowed
* @return this
*/
public @NotNull RecipeMapBuilder<B> modifyFluidInputs(boolean modifyFluidInputs) {
this.modifyFluidInputs = modifyFluidInputs;
return this;
}
/**
* @param fluidOutputs the amount of fluid outputs
* @return this
*/
public @NotNull RecipeMapBuilder<B> fluidOutputs(int fluidOutputs) {
this.fluidOutputs = fluidOutputs;
return this;
}
/**
* @param modifyFluidOutputs if fluid output limit modification should be allowed
* @return this
*/
public @NotNull RecipeMapBuilder<B> modifyFluidOutputs(boolean modifyFluidOutputs) {
this.modifyFluidOutputs = modifyFluidOutputs;
return this;
}
/**
* Mark this recipemap is generating energy
*
* @return this
*/
public @NotNull RecipeMapBuilder<B> generator() {
this.isGenerator = true;
return this;
}
/**
* @param progressBar the progress bar texture to use
* @return this
*/
public @NotNull RecipeMapBuilder<B> progressBar(@Nullable TextureArea progressBar) {
this.progressBar = progressBar;
return this;
}
/**
* @param progressBar the progress bar texture to use
* @param moveType the progress bar move type to use
* @return this
*/
public @NotNull RecipeMapBuilder<B> progressBar(@Nullable TextureArea progressBar,
@Nullable ProgressWidget.MoveType moveType) {
this.progressBar = progressBar;
this.moveType = moveType;
return this;
}
/**
* @param texture the texture to use
* @param isOutput if the slot is an output slot
* @return this
*/
public @NotNull RecipeMapBuilder<B> itemSlotOverlay(@NotNull TextureArea texture, boolean isOutput) {
this.slotOverlays.put(computeOverlayKey(isOutput, false, false), texture);
this.slotOverlays.put(computeOverlayKey(isOutput, false, true), texture);
return this;
}
/**
* @param texture the texture to use
* @param isOutput if the slot is an output slot
* @param isLastSlot if the slot is the last slot
* @return this
*/
public @NotNull RecipeMapBuilder<B> itemSlotOverlay(@NotNull TextureArea texture, boolean isOutput,
boolean isLastSlot) {
this.slotOverlays.put(computeOverlayKey(isOutput, false, isLastSlot), texture);
return this;
}
/**
* @param texture the texture to use
* @param isOutput if the slot is an output slot
* @return this
*/
public @NotNull RecipeMapBuilder<B> fluidSlotOverlay(@NotNull TextureArea texture, boolean isOutput) {
this.slotOverlays.put(computeOverlayKey(isOutput, true, false), texture);
this.slotOverlays.put(computeOverlayKey(isOutput, true, true), texture);
return this;
}
/**
* @param texture the texture to use
* @param isOutput if the slot is an output slot
* @param isLastSlot if the slot is the last slot
* @return this
*/
public @NotNull RecipeMapBuilder<B> fluidSlotOverlay(@NotNull TextureArea texture, boolean isOutput,
boolean isLastSlot) {
this.slotOverlays.put(computeOverlayKey(isOutput, true, isLastSlot), texture);
return this;
}
public @NotNull RecipeMapBuilder<B> specialTexture(@NotNull TextureArea texture, int x, int y, int width,
int height) {
this.specialTexture = texture;
this.specialTextureLocation = new int[] { x, y, width, height };
return this;
}
/**
* @param recipeMapUIFunction the custom function for creating the RecipeMap's ui
* @return this
*/
public @NotNull RecipeMapBuilder<B> ui(@NotNull RecipeMapUIFunction recipeMapUIFunction) {
this.recipeMapUIFunction = recipeMapUIFunction;
return this;
}
/**
* @param recipeMap the recipemap associated with the ui
* @return the RecipeMap's ui
*/
private @NotNull RecipeMapUI<?> buildUI(@NotNull RecipeMap<?> recipeMap) {
RecipeMapUI<?> ui = new RecipeMapUI<>(recipeMap, modifyItemInputs, modifyItemOutputs, modifyFluidInputs,
modifyFluidOutputs, isGenerator);
if (progressBar != null) {
ui.setProgressBarTexture(progressBar);
}
if (moveType != null) {
ui.setProgressBarMoveType(moveType);
}
if (specialTexture != null && specialTextureLocation != null) {
ui.setSpecialTexture(specialTexture, specialTextureLocation);
}
for (var entry : slotOverlays.byte2ObjectEntrySet()) {
ui.setSlotOverlay(entry.getByteKey(), entry.getValue());
}
return ui;
}
/**
* @param sound the sound to use
* @return this
*/
public @NotNull RecipeMapBuilder<B> sound(@NotNull SoundEvent sound) {
this.sound = sound;
return this;
}
/**
* Make the recipemap accept recipes without any outputs
*
* @return this
*/
public @NotNull RecipeMapBuilder<B> allowEmptyOutputs() {
this.allowEmptyOutputs = true;
return this;
}
/**
* Add a recipe build action to be performed upon this RecipeMap's builder's recipe registration.
*
* @param name the unique name of the action
* @param action the action to perform
* @return this
*/
public @NotNull RecipeMapBuilder<B> onBuild(@NotNull ResourceLocation name, @NotNull RecipeBuildAction<B> action) {
if (buildActions == null) {
buildActions = new Object2ObjectOpenHashMap<>();
} else if (buildActions.containsKey(name)) {
throw new IllegalArgumentException("Cannot register RecipeBuildAction with duplicate name: " + name);
}
buildActions.put(name, action);
return this;
}
/**
* Have the primary {@link gregtech.api.recipes.category.GTRecipeCategory} for the RecipeMap be sorted to the end
* of the JEI recipe category list.
*
* @param sortToBack if it should be sorted to the back
* @return this
*/
public @NotNull RecipeMapBuilder<B> jeiSortToBack(boolean sortToBack) {
this.sortToBack = sortToBack;
return this;
}
/**
* <strong>Do not call this twice. RecipeMapBuilders are not re-usable.</strong>
*
* @return a new RecipeMap
*/
public @NotNull RecipeMap<B> build() {
RecipeMap<B> recipeMap = new RecipeMap<>(unlocalizedName, defaultRecipeBuilder, this.recipeMapUIFunction,
itemInputs, itemOutputs, fluidInputs, fluidOutputs);
recipeMap.setSound(sound);
if (allowEmptyOutputs) {
recipeMap.allowEmptyOutput();
}
if (buildActions != null) {
recipeMap.onRecipeBuild(buildActions);
}
recipeMap.getPrimaryRecipeCategory().jeiSortToBack(sortToBack);
return recipeMap;
}
}