-
Notifications
You must be signed in to change notification settings - Fork 180
/
GTRecipeBuilder.java
1312 lines (1131 loc) · 52 KB
/
GTRecipeBuilder.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
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package com.gregtechceu.gtceu.data.recipe.builder;
import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.capability.recipe.*;
import com.gregtechceu.gtceu.api.data.chemical.ChemicalHelper;
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.chemical.material.stack.UnificationEntry;
import com.gregtechceu.gtceu.api.data.medicalcondition.MedicalCondition;
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
import com.gregtechceu.gtceu.api.data.tag.TagUtil;
import com.gregtechceu.gtceu.api.item.component.IDataItem;
import com.gregtechceu.gtceu.api.machine.MachineDefinition;
import com.gregtechceu.gtceu.api.machine.multiblock.CleanroomType;
import com.gregtechceu.gtceu.api.recipe.*;
import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory;
import com.gregtechceu.gtceu.api.recipe.chance.logic.ChanceLogic;
import com.gregtechceu.gtceu.api.recipe.content.Content;
import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient;
import com.gregtechceu.gtceu.api.recipe.ingredient.IntCircuitIngredient;
import com.gregtechceu.gtceu.api.recipe.ingredient.IntProviderIngredient;
import com.gregtechceu.gtceu.api.recipe.ingredient.SizedIngredient;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.common.data.GTRecipeTypes;
import com.gregtechceu.gtceu.common.item.IntCircuitBehaviour;
import com.gregtechceu.gtceu.common.recipe.condition.*;
import com.gregtechceu.gtceu.config.ConfigHolder;
import com.gregtechceu.gtceu.utils.ResearchManager;
import com.lowdragmc.lowdraglib.utils.NBTToJsonConverter;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.util.valueproviders.IntProvider;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.fluids.FluidStack;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import javax.annotation.ParametersAreNonnullByDefault;
@SuppressWarnings({ "unchecked", "UnusedReturnValue" })
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@Accessors(chain = true, fluent = true)
public class GTRecipeBuilder {
public final Map<RecipeCapability<?>, List<Content>> input = new IdentityHashMap<>();
public final Map<RecipeCapability<?>, List<Content>> tickInput = new IdentityHashMap<>();
public final Map<RecipeCapability<?>, List<Content>> output = new IdentityHashMap<>();
public final Map<RecipeCapability<?>, List<Content>> tickOutput = new IdentityHashMap<>();
public final Map<RecipeCapability<?>, ChanceLogic> inputChanceLogic = new IdentityHashMap<>();
public final Map<RecipeCapability<?>, ChanceLogic> outputChanceLogic = new IdentityHashMap<>();
public final Map<RecipeCapability<?>, ChanceLogic> tickInputChanceLogic = new IdentityHashMap<>();
public final Map<RecipeCapability<?>, ChanceLogic> tickOutputChanceLogic = new IdentityHashMap<>();
public final List<RecipeCondition> conditions = new ArrayList<>();
@NotNull
public CompoundTag data = new CompoundTag();
@Setter
public ResourceLocation id;
@Setter
public GTRecipeType recipeType;
@Setter
public int duration = 100;
@Setter
public boolean perTick;
@Setter
public String slotName;
@Setter
public String uiName;
@Setter
public int chance = ChanceLogic.getMaxChancedValue();
@Setter
public int maxChance = ChanceLogic.getMaxChancedValue();
@Setter
public int tierChanceBoost = 0;
@Setter
public boolean isFuel = false;
public GTRecipeCategory recipeCategory;
@Setter
public BiConsumer<GTRecipeBuilder, Consumer<FinishedRecipe>> onSave;
@Getter
private final Collection<ResearchRecipeEntry> researchRecipeEntries = new ArrayList<>();
private boolean generatingRecipes = true;
public GTRecipeBuilder(ResourceLocation id, GTRecipeType recipeType) {
this.id = id;
this.recipeType = recipeType;
this.recipeCategory = recipeType.getCategory();
}
public GTRecipeBuilder(GTRecipe toCopy, GTRecipeType recipeType) {
this.id = toCopy.id;
this.recipeType = recipeType;
toCopy.inputs.forEach((k, v) -> this.input.put(k, new ArrayList<>(v)));
toCopy.outputs.forEach((k, v) -> this.output.put(k, new ArrayList<>(v)));
toCopy.tickInputs.forEach((k, v) -> this.tickInput.put(k, new ArrayList<>(v)));
toCopy.tickOutputs.forEach((k, v) -> this.tickOutput.put(k, new ArrayList<>(v)));
this.inputChanceLogic.putAll(toCopy.inputChanceLogics);
this.outputChanceLogic.putAll(toCopy.outputChanceLogics);
this.tickInputChanceLogic.putAll(toCopy.tickInputChanceLogics);
this.tickOutputChanceLogic.putAll(toCopy.tickOutputChanceLogics);
this.conditions.addAll(toCopy.conditions);
this.data = toCopy.data.copy();
this.duration = toCopy.duration;
this.isFuel = toCopy.isFuel;
this.recipeCategory = toCopy.recipeCategory;
}
public static GTRecipeBuilder of(ResourceLocation id, GTRecipeType recipeType) {
return new GTRecipeBuilder(id, recipeType);
}
public static GTRecipeBuilder ofRaw() {
return new GTRecipeBuilder(GTCEu.id("raw"), GTRecipeTypes.DUMMY_RECIPES);
}
public GTRecipeBuilder copy(String id) {
return copy(GTCEu.id(id));
}
public GTRecipeBuilder copy(ResourceLocation id) {
GTRecipeBuilder copy = new GTRecipeBuilder(id, this.recipeType);
this.input.forEach((k, v) -> copy.input.put(k, new ArrayList<>(v)));
this.output.forEach((k, v) -> copy.output.put(k, new ArrayList<>(v)));
this.tickInput.forEach((k, v) -> copy.tickInput.put(k, new ArrayList<>(v)));
this.tickOutput.forEach((k, v) -> copy.tickOutput.put(k, new ArrayList<>(v)));
copy.inputChanceLogic.putAll(this.inputChanceLogic);
copy.outputChanceLogic.putAll(this.outputChanceLogic);
copy.tickInputChanceLogic.putAll(this.tickInputChanceLogic);
copy.tickOutputChanceLogic.putAll(this.tickOutputChanceLogic);
copy.conditions.addAll(this.conditions);
copy.data = this.data.copy();
copy.duration = this.duration;
copy.chance = this.chance;
copy.perTick = this.perTick;
copy.isFuel = this.isFuel;
copy.recipeCategory = this.recipeCategory;
copy.uiName = this.uiName;
copy.slotName = this.slotName;
copy.onSave = this.onSave;
return copy;
}
public GTRecipeBuilder copyFrom(GTRecipeBuilder builder) {
return builder.copy(builder.id).onSave(null).recipeType(recipeType).category(recipeCategory);
}
public <T> GTRecipeBuilder input(RecipeCapability<T> capability, T obj) {
var t = (perTick ? tickInput : input);
if (t.get(capability) != null && t.get(capability).size() >= recipeType.getMaxInputs(capability)) {
GTCEu.LOGGER.warn("Trying to add more inputs than RecipeType can support, id: {}, Max {}{}Inputs: {}",
id, (perTick ? "Tick " : ""), capability.name, recipeType.getMaxInputs(capability));
}
t.computeIfAbsent(capability, c -> new ArrayList<>())
.add(new Content(capability.of(obj), chance, maxChance, tierChanceBoost, slotName, uiName));
return this;
}
public <T> GTRecipeBuilder input(RecipeCapability<T> capability, T... obj) {
var t = (perTick ? tickInput : input);
if (t.get(capability) != null && t.get(capability).size() + obj.length > recipeType.getMaxInputs(capability)) {
GTCEu.LOGGER.warn("Trying to add more inputs than RecipeType can support, id: {}, Max {}{}Inputs: {}",
id, (perTick ? "Tick " : ""), capability.name, recipeType.getMaxInputs(capability));
}
(perTick ? tickInput : input).computeIfAbsent(capability, c -> new ArrayList<>()).addAll(Arrays.stream(obj)
.map(capability::of)
.map(o -> new Content(o, chance, maxChance, tierChanceBoost, slotName, uiName)).toList());
return this;
}
public <T> GTRecipeBuilder output(RecipeCapability<T> capability, T obj) {
var t = (perTick ? tickOutput : output);
if (t.get(capability) != null && t.get(capability).size() >= recipeType.getMaxOutputs(capability)) {
GTCEu.LOGGER.warn("Trying to add more outputs than RecipeType can support, id: {}, Max {}{}Outputs: {}",
id, (perTick ? "Tick " : ""), capability.name, recipeType.getMaxOutputs(capability));
}
(perTick ? tickOutput : output).computeIfAbsent(capability, c -> new ArrayList<>())
.add(new Content(capability.of(obj), chance, maxChance, tierChanceBoost, slotName, uiName));
return this;
}
public <T> GTRecipeBuilder output(RecipeCapability<T> capability, T... obj) {
var t = (perTick ? tickOutput : output);
if (t.get(capability) != null && t.get(capability).size() + obj.length > recipeType.getMaxOutputs(capability)) {
GTCEu.LOGGER.warn("Trying to add more outputs than RecipeType can support, id: {}, Max {}{}Outputs: {}",
id, (perTick ? "Tick " : ""), capability.name, recipeType.getMaxOutputs(capability));
}
(perTick ? tickOutput : output).computeIfAbsent(capability, c -> new ArrayList<>()).addAll(Arrays.stream(obj)
.map(capability::of)
.map(o -> new Content(o, chance, maxChance, tierChanceBoost, slotName, uiName)).toList());
return this;
}
public <T> GTRecipeBuilder inputs(RecipeCapability<T> capability, Object obj) {
var t = (perTick ? tickInput : input);
if (t.get(capability) != null && t.get(capability).size() >= recipeType.getMaxInputs(capability)) {
GTCEu.LOGGER.warn("Trying to add more inputs than RecipeType can support, id: {}, Max {}{}Inputs: {}",
id, (perTick ? "Tick " : ""), capability.name, recipeType.getMaxInputs(capability));
}
(perTick ? tickInput : input).computeIfAbsent(capability, c -> new ArrayList<>())
.add(new Content(capability.of(obj), chance, maxChance, tierChanceBoost, slotName, uiName));
return this;
}
public <T> GTRecipeBuilder inputs(RecipeCapability<T> capability, Object... obj) {
var t = (perTick ? tickInput : input);
if (t.get(capability) != null && t.get(capability).size() + obj.length > recipeType.getMaxInputs(capability)) {
GTCEu.LOGGER.warn("Trying to add more inputs than RecipeType can support, id: {}, Max {}{}Inputs: {}",
id, (perTick ? "Tick " : ""), capability.name, recipeType.getMaxInputs(capability));
}
(perTick ? tickInput : input).computeIfAbsent(capability, c -> new ArrayList<>()).addAll(Arrays.stream(obj)
.map(capability::of)
.map(o -> new Content(o, chance, maxChance, tierChanceBoost, slotName, uiName)).toList());
return this;
}
public <T> GTRecipeBuilder outputs(RecipeCapability<T> capability, Object obj) {
var t = (perTick ? tickOutput : output);
if (t.get(capability) != null && t.get(capability).size() >= recipeType.getMaxOutputs(capability)) {
GTCEu.LOGGER.warn("Trying to add more outputs than RecipeType can support, id: {}, Max {}{}Outputs: {}",
id, (perTick ? "Tick " : ""), capability.name, recipeType.getMaxOutputs(capability));
}
(perTick ? tickOutput : output).computeIfAbsent(capability, c -> new ArrayList<>())
.add(new Content(capability.of(obj), chance, maxChance, tierChanceBoost, slotName, uiName));
return this;
}
public <T> GTRecipeBuilder outputs(RecipeCapability<T> capability, Object... obj) {
var t = (perTick ? tickOutput : output);
if (t.get(capability) != null && t.get(capability).size() + obj.length > recipeType.getMaxOutputs(capability)) {
GTCEu.LOGGER.warn("Trying to add more outputs than RecipeType can support, id: {}, Max {}{}Outputs: {}",
id, (perTick ? "Tick " : ""), capability.name, recipeType.getMaxOutputs(capability));
}
(perTick ? tickOutput : output).computeIfAbsent(capability, c -> new ArrayList<>()).addAll(Arrays.stream(obj)
.map(capability::of)
.map(o -> new Content(o, chance, maxChance, tierChanceBoost, slotName, uiName)).toList());
return this;
}
public GTRecipeBuilder addCondition(RecipeCondition condition) {
conditions.add(condition);
return this;
}
public GTRecipeBuilder inputEU(long eu) {
return input(EURecipeCapability.CAP, eu);
}
public GTRecipeBuilder EUt(long eu) {
if (eu == 0) {
GTCEu.LOGGER.error("EUt can't be explicitly set to 0, id: {}", id);
}
var lastPerTick = perTick;
perTick = true;
if (eu > 0) {
tickInput.remove(EURecipeCapability.CAP);
inputEU(eu);
} else if (eu < 0) {
tickOutput.remove(EURecipeCapability.CAP);
outputEU(-eu);
}
perTick = lastPerTick;
return this;
}
public GTRecipeBuilder outputEU(long eu) {
return output(EURecipeCapability.CAP, eu);
}
public GTRecipeBuilder inputCWU(int cwu) {
return input(CWURecipeCapability.CAP, cwu);
}
public GTRecipeBuilder CWUt(int cwu) {
if (cwu == 0) {
GTCEu.LOGGER.error("CWUt can't be explicitly set to 0, id: {}", id);
}
var lastPerTick = perTick;
perTick = true;
if (cwu > 0) {
tickInput.remove(CWURecipeCapability.CAP);
inputCWU(cwu);
} else if (cwu < 0) {
tickOutput.remove(CWURecipeCapability.CAP);
outputCWU(cwu);
}
perTick = lastPerTick;
return this;
}
public GTRecipeBuilder totalCWU(int cwu) {
this.durationIsTotalCWU(true);
this.hideDuration(true);
this.duration(cwu);
return this;
}
public GTRecipeBuilder outputCWU(int cwu) {
return output(CWURecipeCapability.CAP, cwu);
}
public GTRecipeBuilder inputItems(Object input) {
if (input instanceof Item item) {
return inputItems(item);
} else if (input instanceof Supplier<?> supplier && supplier.get() instanceof ItemLike item) {
return inputItems(item.asItem());
} else if (input instanceof ItemStack stack) {
return inputItems(stack);
} else if (input instanceof Ingredient ingredient) {
return inputItems(ingredient);
} else if (input instanceof UnificationEntry entry) {
return inputItems(entry);
} else if (input instanceof TagKey<?> tag) {
return inputItems((TagKey<Item>) tag);
} else if (input instanceof MachineDefinition machine) {
return inputItems(machine);
} else {
GTCEu.LOGGER.error(
"Input item is not one of: Item, Supplier<Item>, ItemStack, Ingredient, UnificationEntry, TagKey<Item>, MachineDefinition, id: {}",
id);
return this;
}
}
public GTRecipeBuilder inputItems(Object input, int count) {
if (input instanceof Item item) {
return inputItems(item, count);
} else if (input instanceof Supplier<?> supplier && supplier.get() instanceof ItemLike item) {
return inputItems(item.asItem(), count);
} else if (input instanceof ItemStack stack) {
return inputItems(stack.copyWithCount(count));
} else if (input instanceof Ingredient ingredient) {
return inputItems(ingredient, count);
} else if (input instanceof UnificationEntry entry) {
return inputItems(entry, count);
} else if (input instanceof TagKey<?> tag) {
return inputItems((TagKey<Item>) tag, count);
} else if (input instanceof MachineDefinition machine) {
return inputItems(machine, count);
} else {
GTCEu.LOGGER.error(
"Input item is not one of: Item, Supplier<Item>, ItemStack, Ingredient, UnificationEntry, TagKey<Item>, MachineDefinition, id: {}",
id);
return this;
}
}
public GTRecipeBuilder inputItems(Ingredient inputs) {
return input(ItemRecipeCapability.CAP, inputs);
}
public GTRecipeBuilder inputItems(Ingredient... inputs) {
return input(ItemRecipeCapability.CAP, inputs);
}
public GTRecipeBuilder inputItems(ItemStack input) {
if (input.isEmpty()) {
GTCEu.LOGGER.error("Input items is empty, id: {}", id);
}
return input(ItemRecipeCapability.CAP, SizedIngredient.create(input));
}
public GTRecipeBuilder inputItems(ItemStack... inputs) {
for (ItemStack itemStack : inputs) {
if (itemStack.isEmpty()) {
GTCEu.LOGGER.error("Input item is empty, id: {}", id);
}
}
return input(ItemRecipeCapability.CAP,
Arrays.stream(inputs).map(SizedIngredient::create).toArray(Ingredient[]::new));
}
public GTRecipeBuilder inputItems(TagKey<Item> tag, int amount) {
if (amount == 0) {
GTCEu.LOGGER.error("Item Count is 0, id: {}", id);
}
return inputItems(SizedIngredient.create(tag, amount));
}
public GTRecipeBuilder inputItems(TagKey<Item> tag) {
return inputItems(tag, 1);
}
public GTRecipeBuilder inputItems(Item input, int amount) {
return inputItems(new ItemStack(input, amount));
}
public GTRecipeBuilder inputItems(Item input) {
return inputItems(SizedIngredient.create(new ItemStack(input)));
}
public GTRecipeBuilder inputItems(Supplier<? extends Item> input) {
return inputItems(input.get());
}
public GTRecipeBuilder inputItems(Supplier<? extends Item> input, int amount) {
return inputItems(new ItemStack(input.get(), amount));
}
public GTRecipeBuilder inputItems(TagPrefix orePrefix, Material material) {
return inputItems(orePrefix, material, 1);
}
public GTRecipeBuilder inputItems(UnificationEntry input) {
if (input.material == null) {
GTCEu.LOGGER.error("Unification Entry material is null, id: {}, TagPrefix: {}", id, input.tagPrefix);
}
return inputItems(input.tagPrefix, input.material, 1);
}
public GTRecipeBuilder inputItems(UnificationEntry input, int count) {
if (input.material == null) {
GTCEu.LOGGER.error("Unification Entry material is null, id: {}, TagPrefix: {}", id, input.tagPrefix);
}
return inputItems(input.tagPrefix, input.material, count);
}
public GTRecipeBuilder inputItems(TagPrefix orePrefix, Material material, int count) {
TagKey<Item> tag = ChemicalHelper.getTag(orePrefix, material);
if (tag == null) {
var item = ChemicalHelper.get(orePrefix, material, count);
if (item.isEmpty()) {
GTCEu.LOGGER.error(
"Tried to set input item stack that doesn't exist, id: {}, TagPrefix: {}, Material: {}, Count: {}",
id, orePrefix, material, count);
}
return inputItems(item);
}
return inputItems(tag, count);
}
public GTRecipeBuilder inputItems(MachineDefinition machine) {
return inputItems(machine, 1);
}
public GTRecipeBuilder inputItems(MachineDefinition machine, int count) {
return inputItems(machine.asStack(count));
}
public GTRecipeBuilder outputItems(Object input) {
if (input instanceof Item item) {
return outputItems(item);
} else if (input instanceof Supplier<?> supplier && supplier.get() instanceof ItemLike item) {
return outputItems(item.asItem());
} else if (input instanceof ItemStack stack) {
return outputItems(stack);
} else if (input instanceof UnificationEntry entry) {
return outputItems(entry);
} else if (input instanceof MachineDefinition machine) {
return outputItems(machine);
} else {
GTCEu.LOGGER.error(
"Output item is not one of: Item, Supplier<Item>, ItemStack, Ingredient, UnificationEntry, TagKey<Item>, MachineDefinition, id: {}",
id);
return this;
}
}
public GTRecipeBuilder outputItems(Object input, int count) {
if (input instanceof Item item) {
return outputItems(item, count);
} else if (input instanceof Supplier<?> supplier && supplier.get() instanceof ItemLike item) {
return outputItems(item.asItem(), count);
} else if (input instanceof ItemStack stack) {
return outputItems(stack.copyWithCount(count));
} else if (input instanceof UnificationEntry entry) {
return outputItems(entry, count);
} else if (input instanceof MachineDefinition machine) {
return outputItems(machine, count);
} else {
GTCEu.LOGGER.error(
"Output item is not one of: Item, Supplier<Item>, ItemStack, Ingredient, UnificationEntry, TagKey<Item>, MachineDefinition, id: {}",
id);
return this;
}
}
public GTRecipeBuilder outputItems(Ingredient... inputs) {
return output(ItemRecipeCapability.CAP, inputs);
}
public GTRecipeBuilder outputItems(ItemStack output) {
if (output.isEmpty()) {
GTCEu.LOGGER.error("Output items is empty, id: {}", id);
}
return output(ItemRecipeCapability.CAP, SizedIngredient.create(output));
}
public GTRecipeBuilder outputItems(ItemStack... outputs) {
for (ItemStack itemStack : outputs) {
if (itemStack.isEmpty()) {
GTCEu.LOGGER.error("Output items is empty, id: {}", id);
}
}
return output(ItemRecipeCapability.CAP,
Arrays.stream(outputs).map(SizedIngredient::create).toArray(Ingredient[]::new));
}
public GTRecipeBuilder outputItems(Item output, int amount) {
return outputItems(new ItemStack(output, amount));
}
public GTRecipeBuilder outputItems(Item output) {
return outputItems(new ItemStack(output));
}
public GTRecipeBuilder outputItems(Supplier<? extends ItemLike> input) {
return outputItems(new ItemStack(input.get().asItem()));
}
public GTRecipeBuilder outputItems(Supplier<? extends ItemLike> input, int amount) {
return outputItems(new ItemStack(input.get().asItem(), amount));
}
public GTRecipeBuilder outputItems(TagPrefix orePrefix, Material material) {
return outputItems(orePrefix, material, 1);
}
public GTRecipeBuilder outputItems(TagPrefix orePrefix, Material material, int count) {
var item = ChemicalHelper.get(orePrefix, material, count);
if (item.isEmpty()) {
GTCEu.LOGGER.error("Tried to set output item stack that doesn't exist, TagPrefix: {}, Material: {}",
orePrefix, material);
}
return outputItems(item);
}
public GTRecipeBuilder outputItems(UnificationEntry entry) {
if (entry.material == null) {
GTCEu.LOGGER.error("Unification Entry material is null, id: {}, TagPrefix: {}", id, entry.tagPrefix);
}
return outputItems(entry.tagPrefix, entry.material);
}
public GTRecipeBuilder outputItems(UnificationEntry entry, int count) {
if (entry.material == null) {
GTCEu.LOGGER.error("Unification Entry material is null, id: {}, TagPrefix: {}", id, entry.tagPrefix);
}
return outputItems(entry.tagPrefix, entry.material, count);
}
public GTRecipeBuilder outputItems(MachineDefinition machine) {
return outputItems(machine, 1);
}
public GTRecipeBuilder outputItems(MachineDefinition machine, int count) {
return outputItems(machine.asStack(count));
}
public GTRecipeBuilder outputItemsRanged(ItemStack output, IntProvider intProvider) {
return outputItems(IntProviderIngredient.create(SizedIngredient.create(output), intProvider));
}
public GTRecipeBuilder outputItemsRanged(Item input, IntProvider intProvider) {
return outputItemsRanged(new ItemStack(input), intProvider);
}
public GTRecipeBuilder outputItemsRanged(Supplier<? extends ItemLike> output, IntProvider intProvider) {
return outputItemsRanged(new ItemStack(output.get().asItem()), intProvider);
}
public GTRecipeBuilder outputItemsRanged(TagPrefix orePrefix, Material material, IntProvider intProvider) {
var item = ChemicalHelper.get(orePrefix, material, 1);
if (item.isEmpty()) {
GTCEu.LOGGER.error("Tried to set output ranged item stack that doesn't exist, TagPrefix: {}, Material: {}",
orePrefix, material);
}
return outputItemsRanged(item, intProvider);
}
public GTRecipeBuilder outputItemsRanged(MachineDefinition machine, IntProvider intProvider) {
return outputItemsRanged(machine.asStack(), intProvider);
}
public GTRecipeBuilder notConsumable(ItemStack itemStack) {
int lastChance = this.chance;
this.chance = 0;
inputItems(itemStack);
this.chance = lastChance;
return this;
}
public GTRecipeBuilder notConsumable(Ingredient ingredient) {
int lastChance = this.chance;
this.chance = 0;
inputItems(ingredient);
this.chance = lastChance;
return this;
}
public GTRecipeBuilder notConsumable(Item item) {
int lastChance = this.chance;
this.chance = 0;
inputItems(item);
this.chance = lastChance;
return this;
}
public GTRecipeBuilder notConsumable(Supplier<? extends Item> item) {
int lastChance = this.chance;
this.chance = 0;
inputItems(item);
this.chance = lastChance;
return this;
}
public GTRecipeBuilder notConsumable(TagPrefix orePrefix, Material material) {
int lastChance = this.chance;
this.chance = 0;
inputItems(orePrefix, material);
this.chance = lastChance;
return this;
}
public GTRecipeBuilder notConsumable(TagPrefix orePrefix, Material material, int count) {
int lastChance = this.chance;
this.chance = 0;
inputItems(orePrefix, material, count);
this.chance = lastChance;
return this;
}
public GTRecipeBuilder notConsumableFluid(FluidStack fluid) {
return notConsumableFluid(FluidIngredient.of(
TagUtil.createFluidTag(BuiltInRegistries.FLUID.getKey(fluid.getFluid()).getPath()), fluid.getAmount()));
}
public GTRecipeBuilder notConsumableFluid(FluidIngredient ingredient) {
int lastChance = this.chance;
this.chance = 0;
inputFluids(ingredient);
this.chance = lastChance;
return this;
}
public GTRecipeBuilder circuitMeta(int configuration) {
if (configuration < 0 || configuration > IntCircuitBehaviour.CIRCUIT_MAX) {
GTCEu.LOGGER.error("Circuit configuration must be in the bounds 0 - 32");
}
return notConsumable(IntCircuitIngredient.circuitInput(configuration));
}
public GTRecipeBuilder chancedInput(ItemStack stack, int chance, int tierChanceBoost) {
if (0 >= chance || chance > ChanceLogic.getMaxChancedValue()) {
GTCEu.LOGGER.error("Chance cannot be less or equal to 0 or more than {}. Actual: {}.",
ChanceLogic.getMaxChancedValue(), chance, new Throwable());
return this;
}
int lastChance = this.chance;
int lastTierChanceBoost = this.tierChanceBoost;
this.chance = chance;
this.tierChanceBoost = tierChanceBoost;
inputItems(stack);
this.chance = lastChance;
this.tierChanceBoost = lastTierChanceBoost;
return this;
}
public GTRecipeBuilder chancedInput(FluidStack stack, int chance, int tierChanceBoost) {
if (0 >= chance || chance > ChanceLogic.getMaxChancedValue()) {
GTCEu.LOGGER.error("Chance cannot be less or equal to 0 or more than {}. Actual: {}.",
ChanceLogic.getMaxChancedValue(), chance, new Throwable());
return this;
}
int lastChance = this.chance;
int lastTierChanceBoost = this.tierChanceBoost;
this.chance = chance;
this.tierChanceBoost = tierChanceBoost;
inputFluids(stack);
this.chance = lastChance;
this.tierChanceBoost = lastTierChanceBoost;
return this;
}
public GTRecipeBuilder chancedOutput(ItemStack stack, int chance, int tierChanceBoost) {
if (0 >= chance || chance > ChanceLogic.getMaxChancedValue()) {
GTCEu.LOGGER.error("Chance cannot be less or equal to 0 or more than {}. Actual: {}.",
ChanceLogic.getMaxChancedValue(), chance, new Throwable());
return this;
}
int lastChance = this.chance;
int lastTierChanceBoost = this.tierChanceBoost;
this.chance = chance;
this.tierChanceBoost = tierChanceBoost;
outputItems(stack);
this.chance = lastChance;
this.tierChanceBoost = lastTierChanceBoost;
return this;
}
public GTRecipeBuilder chancedOutput(FluidStack stack, int chance, int tierChanceBoost) {
if (0 >= chance || chance > ChanceLogic.getMaxChancedValue()) {
GTCEu.LOGGER.error("Chance cannot be less or equal to 0 or more than {}. Actual: {}.",
ChanceLogic.getMaxChancedValue(), chance, new Throwable());
return this;
}
int lastChance = this.chance;
int lastTierChanceBoost = this.tierChanceBoost;
this.chance = chance;
this.tierChanceBoost = tierChanceBoost;
outputFluids(stack);
this.chance = lastChance;
this.tierChanceBoost = lastTierChanceBoost;
return this;
}
public GTRecipeBuilder chancedOutput(TagPrefix tag, Material mat, int chance, int tierChanceBoost) {
return chancedOutput(ChemicalHelper.get(tag, mat), chance, tierChanceBoost);
}
public GTRecipeBuilder chancedOutput(TagPrefix tag, Material mat, int count, int chance, int tierChanceBoost) {
return chancedOutput(ChemicalHelper.get(tag, mat, count), chance, tierChanceBoost);
}
public GTRecipeBuilder chancedOutput(ItemStack stack, String fraction, int tierChanceBoost) {
if (stack.isEmpty()) {
return this;
}
String[] split = fraction.split("/");
if (split.length != 2) {
GTCEu.LOGGER.error("Fraction was not parsed correctly! Expected format is \"1/3\". Actual: \"{}\".",
fraction, new Throwable());
return this;
}
int chance;
int maxChance;
try {
chance = Integer.parseInt(split[0]);
maxChance = Integer.parseInt(split[1]);
} catch (NumberFormatException e) {
GTCEu.LOGGER.error("Fraction was not parsed correctly! Expected format is \"1/3\". Actual: \"{}\".",
fraction, new Throwable());
return this;
}
if (0 >= chance || chance > ChanceLogic.getMaxChancedValue()) {
GTCEu.LOGGER.error("Chance cannot be less or equal to 0 or more than {}. Actual: {}.",
ChanceLogic.getMaxChancedValue(), chance, new Throwable());
return this;
}
if (chance >= maxChance || maxChance > ChanceLogic.getMaxChancedValue()) {
GTCEu.LOGGER.error("Max Chance cannot be less or equal to Chance or more than {}. Actual: {}.",
ChanceLogic.getMaxChancedValue(), maxChance, new Throwable());
return this;
}
int scalar = Math.floorDiv(ChanceLogic.getMaxChancedValue(), maxChance);
chance *= scalar;
maxChance *= scalar;
int lastChance = this.chance;
int lastMaxChance = this.maxChance;
int lastTierChanceBoost = this.tierChanceBoost;
this.chance = chance;
this.maxChance = maxChance;
this.tierChanceBoost = tierChanceBoost;
outputItems(stack);
this.chance = lastChance;
this.maxChance = lastMaxChance;
this.tierChanceBoost = lastTierChanceBoost;
return this;
}
public GTRecipeBuilder chancedOutput(TagPrefix prefix, Material material, int count, String fraction,
int tierChanceBoost) {
return chancedOutput(ChemicalHelper.get(prefix, material, count), fraction, tierChanceBoost);
}
public GTRecipeBuilder chancedOutput(TagPrefix prefix, Material material, String fraction, int tierChanceBoost) {
return chancedOutput(prefix, material, 1, fraction, tierChanceBoost);
}
public GTRecipeBuilder chancedOutput(Item item, int count, String fraction, int tierChanceBoost) {
return chancedOutput(new ItemStack(item, count), fraction, tierChanceBoost);
}
public GTRecipeBuilder chancedOutput(Item item, String fraction, int tierChanceBoost) {
return chancedOutput(item, 1, fraction, tierChanceBoost);
}
public GTRecipeBuilder chancedFluidOutput(FluidStack stack, String fraction, int tierChanceBoost) {
if (stack.isEmpty()) {
return this;
}
String[] split = fraction.split("/");
if (split.length != 2) {
GTCEu.LOGGER.error("Fraction was not parsed correctly! Expected format is \"1/3\". Actual: \"{}\".",
fraction, new Throwable());
return this;
}
int chance;
int maxChance;
try {
chance = Integer.parseInt(split[0]);
maxChance = Integer.parseInt(split[1]);
} catch (NumberFormatException e) {
GTCEu.LOGGER.error("Fraction was not parsed correctly! Expected format is \"1/3\". Actual: \"{}\".",
fraction, new Throwable());
return this;
}
if (0 >= chance || chance > ChanceLogic.getMaxChancedValue()) {
GTCEu.LOGGER.error("Chance cannot be less or equal to 0 or more than {}. Actual: {}.",
ChanceLogic.getMaxChancedValue(), chance, new Throwable());
return this;
}
if (chance >= maxChance || maxChance > ChanceLogic.getMaxChancedValue()) {
GTCEu.LOGGER.error("Max Chance cannot be less or equal to Chance or more than {}. Actual: {}.",
ChanceLogic.getMaxChancedValue(), maxChance, new Throwable());
return this;
}
int scalar = Math.floorDiv(ChanceLogic.getMaxChancedValue(), maxChance);
chance *= scalar;
maxChance *= scalar;
int lastChance = this.chance;
int lastMaxChance = this.maxChance;
int lastTierChanceBoost = this.tierChanceBoost;
this.chance = chance;
this.maxChance = maxChance;
this.tierChanceBoost = tierChanceBoost;
outputFluids(stack);
this.chance = lastChance;
this.maxChance = lastMaxChance;
this.tierChanceBoost = lastTierChanceBoost;
return this;
}
/**
* Set a chanced output logic for a specific capability.
* all capabilities default to OR logic if not set.
*
* @param cap the {@link RecipeCapability} to set the logic for
* @param logic the {@link ChanceLogic} to use
* @return this builder
*/
public GTRecipeBuilder chancedOutputLogic(RecipeCapability<?> cap, ChanceLogic logic) {
this.outputChanceLogic.put(cap, logic);
return this;
}
public GTRecipeBuilder chancedItemOutputLogic(ChanceLogic logic) {
return chancedOutputLogic(ItemRecipeCapability.CAP, logic);
}
public GTRecipeBuilder chancedFluidOutputLogic(ChanceLogic logic) {
return chancedOutputLogic(FluidRecipeCapability.CAP, logic);
}
public GTRecipeBuilder chancedInputLogic(RecipeCapability<?> cap, ChanceLogic logic) {
this.inputChanceLogic.put(cap, logic);
return this;
}
public GTRecipeBuilder chancedItemInputLogic(ChanceLogic logic) {
return chancedInputLogic(ItemRecipeCapability.CAP, logic);
}
public GTRecipeBuilder chancedFluidInputLogic(ChanceLogic logic) {
return chancedInputLogic(FluidRecipeCapability.CAP, logic);
}
public GTRecipeBuilder chancedTickOutputLogic(RecipeCapability<?> cap, ChanceLogic logic) {
this.tickOutputChanceLogic.put(cap, logic);
return this;
}
public GTRecipeBuilder chancedTickInputLogic(RecipeCapability<?> cap, ChanceLogic logic) {
this.tickInputChanceLogic.put(cap, logic);
return this;
}
public GTRecipeBuilder inputFluids(FluidStack input) {
return input(FluidRecipeCapability.CAP, FluidIngredient.of(
TagUtil.createFluidTag(BuiltInRegistries.FLUID.getKey(input.getFluid()).getPath()), input.getAmount()));
}
public GTRecipeBuilder inputFluids(FluidStack... inputs) {
return input(FluidRecipeCapability.CAP, Arrays.stream(inputs).map(fluid -> FluidIngredient.of(
TagUtil.createFluidTag(BuiltInRegistries.FLUID.getKey(fluid.getFluid()).getPath()),
fluid.getAmount())).toArray(FluidIngredient[]::new));
}
public GTRecipeBuilder inputFluids(FluidIngredient... inputs) {
return input(FluidRecipeCapability.CAP, inputs);
}
public GTRecipeBuilder outputFluids(FluidStack output) {
return output(FluidRecipeCapability.CAP, FluidIngredient.of(output));
}
public GTRecipeBuilder outputFluids(FluidStack... outputs) {
return output(FluidRecipeCapability.CAP,
Arrays.stream(outputs).map(FluidIngredient::of).toArray(FluidIngredient[]::new));
}
public GTRecipeBuilder outputFluids(FluidIngredient... outputs) {
return output(FluidRecipeCapability.CAP, outputs);
}
public GTRecipeBuilder inputStress(float stress) {
return input(StressRecipeCapability.CAP, stress);
}
public GTRecipeBuilder outputStress(float stress) {
return output(StressRecipeCapability.CAP, stress);
}
//////////////////////////////////////
// ********** DATA ***********//
//////////////////////////////////////
public GTRecipeBuilder addData(String key, Tag data) {
this.data.put(key, data);
return this;
}
public GTRecipeBuilder addData(String key, int data) {
this.data.putInt(key, data);
return this;
}
public GTRecipeBuilder addData(String key, long data) {
this.data.putLong(key, data);
return this;
}
public GTRecipeBuilder addData(String key, String data) {
this.data.putString(key, data);
return this;
}
public GTRecipeBuilder addData(String key, Float data) {
this.data.putFloat(key, data);
return this;
}
public GTRecipeBuilder addData(String key, boolean data) {
this.data.putBoolean(key, data);
return this;
}
public GTRecipeBuilder blastFurnaceTemp(int blastTemp) {
return addData("ebf_temp", blastTemp);
}
public GTRecipeBuilder explosivesAmount(int explosivesAmount) {
return inputItems(new ItemStack(Blocks.TNT, explosivesAmount));
}
public GTRecipeBuilder explosivesType(ItemStack explosivesType) {
return inputItems(explosivesType);
}
public GTRecipeBuilder solderMultiplier(int multiplier) {
return addData("solder_multiplier", multiplier);
}
public GTRecipeBuilder disableDistilleryRecipes(boolean flag) {
return addData("disable_distillery", flag);
}
public GTRecipeBuilder fusionStartEU(long eu) {
return addData("eu_to_start", eu);
}
public GTRecipeBuilder researchScan(boolean isScan) {
return addData("scan_for_research", isScan);
}