-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathRecipeBuilder.java
More file actions
1200 lines (1017 loc) · 44.7 KB
/
RecipeBuilder.java
File metadata and controls
1200 lines (1017 loc) · 44.7 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
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 gregtech.api.recipes;
import gregtech.api.GTValues;
import gregtech.api.fluids.store.FluidStorageKey;
import gregtech.api.items.metaitem.MetaItem;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.multiblock.CleanroomType;
import gregtech.api.recipes.category.GTRecipeCategory;
import gregtech.api.recipes.chance.output.ChancedOutputList;
import gregtech.api.recipes.chance.output.ChancedOutputLogic;
import gregtech.api.recipes.chance.output.impl.ChancedFluidOutput;
import gregtech.api.recipes.chance.output.impl.ChancedItemOutput;
import gregtech.api.recipes.ingredients.GTRecipeFluidInput;
import gregtech.api.recipes.ingredients.GTRecipeInput;
import gregtech.api.recipes.ingredients.GTRecipeItemInput;
import gregtech.api.recipes.ingredients.GTRecipeOreInput;
import gregtech.api.recipes.ingredients.IntCircuitIngredient;
import gregtech.api.recipes.ingredients.nbtmatch.NBTCondition;
import gregtech.api.recipes.ingredients.nbtmatch.NBTMatcher;
import gregtech.api.recipes.properties.RecipeProperty;
import gregtech.api.recipes.properties.RecipePropertyStorage;
import gregtech.api.recipes.properties.RecipePropertyStorageImpl;
import gregtech.api.recipes.properties.impl.CleanroomProperty;
import gregtech.api.recipes.properties.impl.DimensionProperty;
import gregtech.api.unification.OreDictUnifier;
import gregtech.api.unification.material.Material;
import gregtech.api.unification.ore.OrePrefix;
import gregtech.api.unification.stack.ItemMaterialInfo;
import gregtech.api.util.EnumValidationResult;
import gregtech.api.util.GTLog;
import gregtech.api.util.GTUtility;
import gregtech.api.util.Mods;
import gregtech.api.util.ValidationResult;
import gregtech.common.ConfigHolder;
import gregtech.integration.groovy.GroovyScriptModule;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.Optional;
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient;
import crafttweaker.CraftTweakerAPI;
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.MustBeInvokedByOverriders;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* @see Recipe
*/
@SuppressWarnings("unchecked")
public class RecipeBuilder<R extends RecipeBuilder<R>> {
protected RecipeMap<R> recipeMap;
protected final List<GTRecipeInput> inputs;
protected final List<ItemStack> outputs;
protected final List<ChancedItemOutput> chancedOutputs;
protected final List<GTRecipeInput> fluidInputs;
protected final List<FluidStack> fluidOutputs;
protected final List<ChancedFluidOutput> chancedFluidOutputs;
protected ChancedOutputLogic chancedOutputLogic = ChancedOutputLogic.OR;
protected ChancedOutputLogic chancedFluidOutputLogic = ChancedOutputLogic.OR;
protected int duration;
protected long EUt;
protected boolean hidden = false;
protected GTRecipeCategory category;
protected boolean isCTRecipe = false;
protected int parallel = 0;
protected EnumValidationResult recipeStatus = EnumValidationResult.VALID;
protected RecipePropertyStorage recipePropertyStorage = RecipePropertyStorage.EMPTY;
protected boolean recipePropertyStorageErrored = false;
protected boolean ignoreAllBuildActions = false;
protected Map<ResourceLocation, RecipeBuildAction<R>> ignoredBuildActions;
private boolean withItemRecycling;
protected RecipeBuilder() {
this.inputs = new ArrayList<>();
this.outputs = new ArrayList<>();
this.chancedOutputs = new ArrayList<>();
this.fluidInputs = new ArrayList<>();
this.fluidOutputs = new ArrayList<>();
this.chancedFluidOutputs = new ArrayList<>();
}
public RecipeBuilder(Recipe recipe, RecipeMap<R> recipeMap) {
this.recipeMap = recipeMap;
this.inputs = new ArrayList<>(recipe.getInputs());
this.outputs = new ArrayList<>(recipe.getOutputs());
this.chancedOutputs = new ArrayList<>(recipe.getChancedOutputs().getChancedEntries());
this.fluidInputs = new ArrayList<>(recipe.getFluidInputs());
this.fluidOutputs = GTUtility.copyFluidList(recipe.getFluidOutputs());
this.chancedFluidOutputs = new ArrayList<>(recipe.getChancedFluidOutputs().getChancedEntries());
this.duration = recipe.getDuration();
this.EUt = recipe.getEUt();
this.hidden = recipe.isHidden();
this.category = recipe.getRecipeCategory();
this.recipePropertyStorage = recipe.propertyStorage().copy();
}
@SuppressWarnings("CopyConstructorMissesField")
protected RecipeBuilder(RecipeBuilder<R> recipeBuilder) {
this.recipeMap = recipeBuilder.recipeMap;
this.inputs = new ArrayList<>(recipeBuilder.getInputs());
this.outputs = new ArrayList<>(recipeBuilder.getOutputs());
this.chancedOutputs = new ArrayList<>(recipeBuilder.chancedOutputs);
this.fluidInputs = new ArrayList<>(recipeBuilder.getFluidInputs());
this.fluidOutputs = GTUtility.copyFluidList(recipeBuilder.getFluidOutputs());
this.chancedFluidOutputs = new ArrayList<>(recipeBuilder.chancedFluidOutputs);
this.chancedOutputLogic = recipeBuilder.chancedOutputLogic;
this.chancedFluidOutputLogic = recipeBuilder.chancedFluidOutputLogic;
this.duration = recipeBuilder.duration;
this.EUt = recipeBuilder.EUt;
this.hidden = recipeBuilder.hidden;
this.category = recipeBuilder.category;
this.recipePropertyStorage = recipeBuilder.recipePropertyStorage.copy();
this.ignoreAllBuildActions = recipeBuilder.ignoreAllBuildActions;
if (recipeBuilder.ignoredBuildActions != null) {
this.ignoredBuildActions = new Object2ObjectOpenHashMap<>(recipeBuilder.ignoredBuildActions);
}
this.withItemRecycling = recipeBuilder.hasItemRecycling();
}
public R cleanroom(@Nullable CleanroomType cleanroom) {
if (ConfigHolder.machines.enableCleanroom && cleanroom != null) {
this.applyProperty(CleanroomProperty.getInstance(), cleanroom);
}
return (R) this;
}
public R dimension(int dimensionID) {
return dimension(dimensionID, false);
}
public R dimension(int dimensionID, boolean toBlackList) {
DimensionProperty.DimensionPropertyList dimensionIDs = getCompleteDimensionIDs();
if (dimensionIDs == null) {
dimensionIDs = new DimensionProperty.DimensionPropertyList();
this.applyProperty(DimensionProperty.getInstance(), dimensionIDs);
}
dimensionIDs.add(dimensionID, toBlackList);
return (R) this;
}
public @Nullable DimensionProperty.DimensionPropertyList getCompleteDimensionIDs() {
return this.recipePropertyStorage.get(DimensionProperty.getInstance(), null);
}
public @NotNull IntList getDimensionIDs() {
return this.recipePropertyStorage.get(DimensionProperty.getInstance(),
DimensionProperty.DimensionPropertyList.EMPTY_LIST).whiteListDimensions;
}
public @NotNull IntList getBlockedDimensionIDs() {
return this.recipePropertyStorage.get(DimensionProperty.getInstance(),
DimensionProperty.DimensionPropertyList.EMPTY_LIST).blackListDimensions;
}
@MustBeInvokedByOverriders
public boolean applyPropertyCT(@NotNull String key, @NotNull Object value) {
if (key.equals(DimensionProperty.KEY)) {
if (value instanceof DimensionProperty.DimensionPropertyList list) {
DimensionProperty.DimensionPropertyList dimensionIDs = getCompleteDimensionIDs();
if (dimensionIDs == null) {
dimensionIDs = new DimensionProperty.DimensionPropertyList();
this.applyProperty(DimensionProperty.getInstance(), dimensionIDs);
}
dimensionIDs.merge(list);
return true;
}
return false;
} else if (key.equals(CleanroomProperty.KEY)) {
if (value instanceof CleanroomType) {
this.cleanroom((CleanroomType) value);
} else if (value instanceof String) {
this.cleanroom(CleanroomType.getByName((String) value));
} else {
return false;
}
return true;
}
return false;
}
public final boolean applyProperty(@NotNull RecipeProperty<?> property, @NotNull Object value) {
if (this.recipePropertyStorage == RecipePropertyStorage.EMPTY) {
this.recipePropertyStorage = new RecipePropertyStorageImpl();
}
boolean stored = this.recipePropertyStorage.store(property, value);
if (!stored) {
this.recipePropertyStorageErrored = true;
}
return stored;
}
public R input(GTRecipeInput input) {
if (input.getAmount() < 0) {
GTLog.logger.error("Count cannot be less than 0. Actual: {}.", input.getAmount(), new Throwable());
} else {
this.inputs.add(input);
}
return (R) this;
}
public R input(String oredict) {
return input(new GTRecipeOreInput(oredict));
}
public R input(String oredict, int count) {
return input(new GTRecipeOreInput(oredict, count));
}
public R input(OrePrefix orePrefix, Material material) {
return input(new GTRecipeOreInput(orePrefix, material));
}
public R input(OrePrefix orePrefix, Material material, int count) {
return input(new GTRecipeOreInput(orePrefix, material, count));
}
public R input(Item item) {
return input(new GTRecipeItemInput(new ItemStack(item)));
}
public R input(Item item, int count) {
return input(new GTRecipeItemInput(new ItemStack(item), count));
}
public R input(Item item, int count, int meta) {
return input(new GTRecipeItemInput(new ItemStack(item, count, meta)));
}
public R input(Item item, int count, @SuppressWarnings("unused") boolean wild) {
return input(new GTRecipeItemInput(new ItemStack(item, count, GTValues.W)));
}
public R input(Block block) {
return input(block, 1);
}
public R input(Block block, int count) {
return input(new GTRecipeItemInput(new ItemStack(block, count)));
}
public R input(Block block, int count, int meta) {
return input(new GTRecipeItemInput(new ItemStack(block, count, meta)));
}
public R input(Block block, int count, @SuppressWarnings("unused") boolean wild) {
return input(new GTRecipeItemInput(new ItemStack(block, count, GTValues.W)));
}
public R input(MetaItem<?>.MetaValueItem item, int count) {
return input(new GTRecipeItemInput(item.getStackForm(count)));
}
public R input(MetaItem<?>.MetaValueItem item) {
return input(new GTRecipeItemInput(item.getStackForm()));
}
public R input(MetaTileEntity mte) {
return input(new GTRecipeItemInput(mte.getStackForm()));
}
public R input(MetaTileEntity mte, int amount) {
return input(new GTRecipeItemInput(mte.getStackForm(amount)));
}
public R inputNBT(GTRecipeInput input, NBTMatcher matcher, NBTCondition condition) {
if (input.getAmount() < 0) {
GTLog.logger.error("Count cannot be less than 0. Actual: {}.", input.getAmount(), new Throwable());
return (R) this;
}
if (matcher == null) {
GTLog.logger.error("NBTMatcher must not be null", new Throwable());
return (R) this;
}
if (condition == null) {
GTLog.logger.error("NBTCondition must not be null", new Throwable());
return (R) this;
}
this.inputs.add(input.setNBTMatchingCondition(matcher, condition));
return (R) this;
}
public R inputNBT(String oredict, NBTMatcher matcher, NBTCondition condition) {
return inputNBT(new GTRecipeOreInput(oredict), matcher, condition);
}
public R inputNBT(String oredict, int count, NBTMatcher matcher, NBTCondition condition) {
return inputNBT(new GTRecipeOreInput(oredict, count), matcher, condition);
}
public R inputNBT(OrePrefix orePrefix, Material material, NBTMatcher matcher, NBTCondition condition) {
return inputNBT(new GTRecipeOreInput(orePrefix, material), matcher, condition);
}
public R inputNBT(OrePrefix orePrefix, Material material, int count, NBTMatcher matcher, NBTCondition condition) {
return inputNBT(new GTRecipeOreInput(orePrefix, material, count), matcher, condition);
}
public R inputNBT(Item item, NBTMatcher matcher, NBTCondition condition) {
return inputNBT(new ItemStack(item), matcher, condition);
}
public R inputNBT(Item item, int count, NBTMatcher matcher, NBTCondition condition) {
return inputNBT(new ItemStack(item, count), matcher, condition);
}
public R inputNBT(Item item, int count, int meta, NBTMatcher matcher, NBTCondition condition) {
return inputNBT(new ItemStack(item, count, meta), matcher, condition);
}
public R inputNBT(Item item, int count, @SuppressWarnings("unused") boolean wild, NBTMatcher matcher,
NBTCondition condition) {
return inputNBT(new ItemStack(item, count, GTValues.W), matcher, condition);
}
public R inputNBT(Block block, NBTMatcher matcher, NBTCondition condition) {
return inputNBT(block, 1, matcher, condition);
}
public R inputNBT(Block block, int count, NBTMatcher matcher, NBTCondition condition) {
return inputNBT(new ItemStack(block, count), matcher, condition);
}
public R inputNBT(Block block, int count, @SuppressWarnings("unused") boolean wild, NBTMatcher matcher,
NBTCondition condition) {
return inputNBT(new ItemStack(block, count, GTValues.W), matcher, condition);
}
public R inputNBT(MetaItem<?>.MetaValueItem item, int count, NBTMatcher matcher, NBTCondition condition) {
return inputNBT(item.getStackForm(count), matcher, condition);
}
public R inputNBT(MetaItem<?>.MetaValueItem item, NBTMatcher matcher, NBTCondition condition) {
return inputNBT(item.getStackForm(), matcher, condition);
}
public R inputNBT(MetaTileEntity mte, NBTMatcher matcher, NBTCondition condition) {
return inputNBT(mte.getStackForm(), matcher, condition);
}
public R inputNBT(MetaTileEntity mte, int amount, NBTMatcher matcher, NBTCondition condition) {
return inputNBT(mte.getStackForm(amount), matcher, condition);
}
/**
* NBT tags are stripped from the input stack and are not automatically checked.
*
* @param stack the itemstack to input.
* @param matcher the matcher for the stack's nbt
* @param condition the condition for the stack's nbt
* @return this
*/
public R inputNBT(@NotNull ItemStack stack, NBTMatcher matcher, NBTCondition condition) {
return inputNBT(new GTRecipeItemInput(stack), matcher, condition);
}
public R inputs(ItemStack input) {
if (input == null || input.isEmpty()) {
GTLog.logger.error("Input cannot be null or empty. Input: {}", input, new Throwable());
recipeStatus = EnumValidationResult.INVALID;
} else {
this.inputs.add(new GTRecipeItemInput(input));
}
return (R) this;
}
public R inputs(ItemStack... inputs) {
for (ItemStack input : inputs) {
if (input == null || input.isEmpty()) {
GTLog.logger.error("Inputs cannot contain null or empty ItemStacks. Inputs: {}", input,
new Throwable());
recipeStatus = EnumValidationResult.INVALID;
continue;
}
this.inputs.add(new GTRecipeItemInput(input));
}
return (R) this;
}
public R inputStacks(Collection<ItemStack> inputs) {
for (ItemStack input : inputs) {
if (input == null || input.isEmpty()) {
GTLog.logger.error("Input cannot contain null or empty ItemStacks. Inputs: {}", input, new Throwable());
recipeStatus = EnumValidationResult.INVALID;
continue;
}
this.inputs.add(new GTRecipeItemInput(input));
}
return (R) this;
}
public R inputs(GTRecipeInput input) {
if (input.getAmount() < 0) {
GTLog.logger.error("Input count cannot be less than 0. Actual: {}.", input.getAmount(), new Throwable());
recipeStatus = EnumValidationResult.INVALID;
} else {
this.inputs.add(input);
}
return (R) this;
}
public R inputs(GTRecipeInput... inputs) {
for (GTRecipeInput input : inputs) {
if (input.getAmount() < 0) {
GTLog.logger.error("Input count cannot be less than 0. Actual: {}.", input.getAmount(),
new Throwable());
recipeStatus = EnumValidationResult.INVALID;
continue;
}
this.inputs.add(input);
}
return (R) this;
}
public R inputIngredients(Collection<GTRecipeInput> inputs) {
for (GTRecipeInput input : inputs) {
if (input.getAmount() < 0) {
GTLog.logger.error("Count cannot be less than 0. Actual: {}.", input.getAmount(), new Throwable());
recipeStatus = EnumValidationResult.INVALID;
continue;
}
this.inputs.add(input);
}
return (R) this;
}
public R clearInputs() {
this.inputs.clear();
return (R) this;
}
public R notConsumable(GTRecipeInput gtRecipeIngredient) {
return input(gtRecipeIngredient.setNonConsumable());
}
public R notConsumable(ItemStack itemStack) {
return input(new GTRecipeItemInput(itemStack).setNonConsumable());
}
public R notConsumable(OrePrefix prefix, Material material, int amount) {
return input(new GTRecipeOreInput(prefix, material, amount).setNonConsumable());
}
public R notConsumable(OrePrefix prefix, Material material) {
return notConsumable(prefix, material, 1);
}
public R notConsumable(MetaItem<?>.MetaValueItem item) {
return input(new GTRecipeItemInput(item.getStackForm(), 1).setNonConsumable());
}
public R notConsumable(Fluid fluid, int amount) {
return fluidInputs(new GTRecipeFluidInput(fluid, amount).setNonConsumable());
}
public R notConsumable(Fluid fluid) {
return fluidInputs(new GTRecipeFluidInput(fluid, 1).setNonConsumable());
}
public R notConsumable(FluidStack fluidStack) {
return fluidInputs(new GTRecipeFluidInput(fluidStack).setNonConsumable());
}
public R circuitMeta(int circuitNumber) {
if (IntCircuitIngredient.CIRCUIT_MIN > circuitNumber || circuitNumber > IntCircuitIngredient.CIRCUIT_MAX) {
GTLog.logger.error("Integrated Circuit Number cannot be less than {} and more than {}",
IntCircuitIngredient.CIRCUIT_MIN, IntCircuitIngredient.CIRCUIT_MAX, new Throwable());
recipeStatus = EnumValidationResult.INVALID;
return (R) this;
}
return input(IntCircuitIngredient.circuitInput(circuitNumber));
}
public R output(OrePrefix orePrefix, Material material) {
return outputs(OreDictUnifier.get(orePrefix, material, 1));
}
public R output(OrePrefix orePrefix, Material material, int count) {
return outputs(OreDictUnifier.get(orePrefix, material, count));
}
public R output(Item item) {
return output(item, 1);
}
public R output(Item item, int count) {
return outputs(new ItemStack(item, count));
}
public R output(Item item, int count, int meta) {
return outputs(new ItemStack(item, count, meta));
}
public R output(Block item) {
return output(item, 1);
}
public R output(Block item, int count) {
return outputs(new ItemStack(item, count));
}
public R output(Block item, int count, int meta) {
return outputs(new ItemStack(item, count, meta));
}
public R output(MetaItem<?>.MetaValueItem item, int count) {
return outputs(item.getStackForm(count));
}
public R output(MetaItem<?>.MetaValueItem item) {
return output(item, 1);
}
public R output(MetaTileEntity mte) {
return output(mte, 1);
}
public R output(MetaTileEntity mte, int amount) {
return outputs(mte.getStackForm(amount));
}
public R outputs(ItemStack output) {
if (output != null && !output.isEmpty()) {
this.outputs.add(output);
}
return (R) this;
}
public R outputs(ItemStack... outputs) {
return outputs(Arrays.asList(outputs));
}
public R outputs(Collection<ItemStack> outputs) {
outputs = new ArrayList<>(outputs);
outputs.removeIf(stack -> stack == null || stack.isEmpty());
this.outputs.addAll(outputs);
return (R) this;
}
public R clearOutputs() {
this.outputs.clear();
return (R) this;
}
public R fluidInput(@NotNull Fluid fluid) {
return fluidInputs(new GTRecipeFluidInput(fluid, 1));
}
public R fluidInput(@NotNull Fluid fluid, int amount) {
return fluidInputs(new GTRecipeFluidInput(fluid, amount));
}
public R fluidInputs(Collection<GTRecipeInput> fluidIngredients) {
this.fluidInputs.addAll(fluidIngredients);
return (R) this;
}
public R fluidInputs(GTRecipeInput fluidIngredient) {
this.fluidInputs.add(fluidIngredient);
return (R) this;
}
public R fluidInputs(FluidStack input) {
if (input != null && input.amount > 0) {
this.fluidInputs.add(new GTRecipeFluidInput(input));
} else if (input != null) {
GTLog.logger.error("Fluid Input count cannot be less than 1. Actual: {}.", input.amount,
new IllegalArgumentException());
} else {
GTLog.logger.error("FluidStack cannot be null.");
}
return (R) this;
}
public R fluidInputs(@NotNull Material material, int amount) {
return fluidInputs(material.getFluid(amount));
}
public R fluidInputs(@NotNull Material material, @NotNull FluidStorageKey storageKey, int amount) {
return fluidInputs(material.getFluid(storageKey, amount));
}
public R fluidInputs(FluidStack... fluidStacks) {
ArrayList<GTRecipeInput> fluidIngredients = new ArrayList<>();
for (FluidStack fluidStack : fluidStacks) {
if (fluidStack != null && fluidStack.amount > 0) {
fluidIngredients.add(new GTRecipeFluidInput(fluidStack));
} else if (fluidStack != null) {
GTLog.logger.error("Fluid Input count cannot be less than 1. Actual: {}.", fluidStack.amount,
new Throwable());
} else {
GTLog.logger.error("FluidStack cannot be null.");
}
}
this.fluidInputs.addAll(fluidIngredients);
return (R) this;
}
public R clearFluidInputs() {
this.fluidInputs.clear();
return (R) this;
}
public R fluidOutputs(@NotNull Fluid fluid) {
return fluidOutputs(new FluidStack(fluid, 1));
}
public R fluidOutputs(@NotNull Fluid fluid, int amount) {
return fluidOutputs(new FluidStack(fluid, amount));
}
public R fluidOutputs(FluidStack output) {
if (output != null && output.amount > 0) {
this.fluidOutputs.add(output);
}
return (R) this;
}
public R fluidOutputs(@NotNull Material material, int amount) {
return fluidOutputs(material.getFluid(amount));
}
public R fluidOutputs(@NotNull Material material, @NotNull FluidStorageKey storageKey, int amount) {
return fluidOutputs(material.getFluid(storageKey, amount));
}
public R fluidOutputs(FluidStack... outputs) {
return fluidOutputs(Arrays.asList(outputs));
}
public R fluidOutputs(Collection<FluidStack> outputs) {
outputs = new ArrayList<>(outputs);
outputs.removeIf(o -> o == null || o.amount <= 0);
this.fluidOutputs.addAll(outputs);
return (R) this;
}
public R clearFluidOutputs() {
this.fluidOutputs.clear();
return (R) this;
}
public R chancedOutput(ItemStack stack, int chance, int tierChanceBoost) {
if (stack == null || stack.isEmpty()) {
return (R) this;
}
if (0 >= chance || chance > ChancedOutputLogic.getMaxChancedValue()) {
GTLog.logger.error("Chance cannot be less or equal to 0 or more than {}. Actual: {}.",
ChancedOutputLogic.getMaxChancedValue(), chance, new Throwable());
recipeStatus = EnumValidationResult.INVALID;
return (R) this;
}
this.chancedOutputs.add(new ChancedItemOutput(stack.copy(), chance, tierChanceBoost));
return (R) this;
}
public R chancedOutput(OrePrefix prefix, Material material, int count, int chance, int tierChanceBoost) {
return chancedOutput(OreDictUnifier.get(prefix, material, count), chance, tierChanceBoost);
}
public R chancedOutput(OrePrefix prefix, Material material, int chance, int tierChanceBoost) {
return chancedOutput(prefix, material, 1, chance, tierChanceBoost);
}
public R chancedOutput(MetaItem<?>.MetaValueItem item, int count, int chance, int tierChanceBoost) {
return chancedOutput(item.getStackForm(count), chance, tierChanceBoost);
}
public R chancedOutput(MetaItem<?>.MetaValueItem item, int chance, int tierChanceBoost) {
return chancedOutput(item, 1, chance, tierChanceBoost);
}
public R chancedOutputs(List<ChancedItemOutput> chancedOutputs) {
for (ChancedItemOutput output : chancedOutputs) {
this.chancedOutputs.add(output.copy());
}
return (R) this;
}
public R clearChancedOutput() {
this.chancedOutputs.clear();
return (R) this;
}
public R chancedOutputLogic(@NotNull ChancedOutputLogic logic) {
this.chancedOutputLogic = logic;
return (R) this;
}
public R chancedFluidOutput(FluidStack stack, int chance, int tierChanceBoost) {
if (stack == null || stack.amount == 0) {
return (R) this;
}
if (0 >= chance || chance > ChancedOutputLogic.getMaxChancedValue()) {
GTLog.logger.error("Chance cannot be less or equal to 0 or more than {}. Actual: {}.",
ChancedOutputLogic.getMaxChancedValue(), chance, new Throwable());
recipeStatus = EnumValidationResult.INVALID;
return (R) this;
}
this.chancedFluidOutputs.add(new ChancedFluidOutput(stack.copy(), chance, tierChanceBoost));
return (R) this;
}
public R chancedFluidOutputs(List<ChancedFluidOutput> chancedOutputs) {
for (ChancedFluidOutput output : chancedOutputs) {
this.chancedFluidOutputs.add(output.copy());
}
return (R) this;
}
public R clearChancedFluidOutputs() {
this.chancedFluidOutputs.clear();
return (R) this;
}
public R chancedFluidOutputLogic(@NotNull ChancedOutputLogic logic) {
this.chancedFluidOutputLogic = logic;
return (R) this;
}
@Optional.Method(modid = Mods.Names.GROOVY_SCRIPT)
public R inputs(IIngredient ingredient) {
return input(ofGroovyIngredient(ingredient));
}
@Optional.Method(modid = Mods.Names.GROOVY_SCRIPT)
public R inputs(IIngredient... ingredients) {
for (IIngredient ingredient : ingredients) {
inputs(ingredient);
}
return (R) this;
}
@Optional.Method(modid = Mods.Names.GROOVY_SCRIPT)
public R inputs(Collection<IIngredient> ingredients) {
for (IIngredient ingredient : ingredients) {
inputs(ingredient);
}
return (R) this;
}
@Optional.Method(modid = Mods.Names.GROOVY_SCRIPT)
public R notConsumable(IIngredient ingredient) {
return notConsumable(ofGroovyIngredient(ingredient));
}
@Optional.Method(modid = Mods.Names.GROOVY_SCRIPT)
private static GTRecipeInput ofGroovyIngredient(IIngredient ingredient) {
if (ingredient instanceof OreDictIngredient) {
return new GTRecipeOreInput(((OreDictIngredient) ingredient).getOreDict(), ingredient.getAmount());
}
Object oIngredient = ingredient;
if (oIngredient instanceof ItemStack) {
return new GTRecipeItemInput((ItemStack) oIngredient);
}
if (ingredient instanceof FluidStack) {
return new GTRecipeFluidInput((FluidStack) ingredient);
}
throw new IllegalArgumentException("Could not add groovy ingredient " + ingredient + " to recipe!");
}
/**
* Copies the chanced outputs of a Recipe numberOfOperations times, so every chanced output
* gets an individual roll, instead of an all or nothing situation
*
* @param chancedOutputsFrom The original recipe before any parallel multiplication
* @param numberOfOperations The number of parallel operations that have been performed
*/
public void chancedOutputsMultiply(Recipe chancedOutputsFrom, int numberOfOperations) {
for (ChancedItemOutput entry : chancedOutputsFrom.getChancedOutputs().getChancedEntries()) {
int chance = entry.getChance();
int boost = entry.getChanceBoost();
// Add individual chanced outputs per number of parallel operations performed, to mimic regular recipes.
// This is done instead of simply batching the chanced outputs by the number of parallel operations
// performed
for (int i = 0; i < numberOfOperations; i++) {
this.chancedOutput(entry.getIngredient().copy(), chance, boost);
}
}
for (ChancedFluidOutput entry : chancedOutputsFrom.getChancedFluidOutputs().getChancedEntries()) {
int chance = entry.getChance();
int boost = entry.getChanceBoost();
// Add individual chanced outputs per number of parallel operations performed, to mimic regular recipes.
// This is done instead of simply batching the chanced outputs by the number of parallel operations
// performed
for (int i = 0; i < numberOfOperations; i++) {
this.chancedFluidOutput(entry.getIngredient().copy(), chance, boost);
}
}
}
/**
* Appends the passed {@link Recipe} onto the inputs and outputs, multiplied by the amount specified by multiplier
* The duration of the multiplied {@link Recipe} is also added to the current duration
*
* @param recipe The Recipe to be multiplied
* @param multiplier Amount to multiply the recipe by
* @param multiplyDuration Whether duration should be multiplied instead of EUt
* @return the builder holding the multiplied recipe
*/
public R append(Recipe recipe, int multiplier, boolean multiplyDuration) {
for (Map.Entry<RecipeProperty<?>, Object> property : recipe.propertyStorage().entrySet()) {
this.applyPropertyCT(property.getKey().getKey(), property.getValue());
}
// Create holders for the various parts of the new multiplied Recipe
List<GTRecipeInput> newRecipeInputs = new ArrayList<>();
List<GTRecipeInput> newFluidInputs = new ArrayList<>();
List<ItemStack> outputItems = new ArrayList<>();
List<FluidStack> outputFluids = new ArrayList<>();
// Populate the various holders of the multiplied Recipe
multiplyInputsAndOutputs(newRecipeInputs, newFluidInputs, outputItems, outputFluids, recipe, multiplier);
// Build the new Recipe with multiplied components
this.inputIngredients(newRecipeInputs);
this.fluidInputs(newFluidInputs);
this.outputs(outputItems);
this.fluidOutputs(outputFluids);
chancedOutputsMultiply(recipe, multiplier);
this.EUt(multiplyDuration ? recipe.getEUt() : this.EUt + recipe.getEUt() * multiplier);
this.duration(multiplyDuration ? this.duration + recipe.getDuration() * multiplier : recipe.getDuration());
if (this.parallel == 0) {
this.parallel = multiplier;
} else if (multiplyDuration) {
this.parallel += multiplier;
} else {
this.parallel *= multiplier;
}
return (R) this;
}
protected static void multiplyInputsAndOutputs(List<GTRecipeInput> newRecipeInputs,
List<GTRecipeInput> newFluidInputs,
List<ItemStack> outputItems,
List<FluidStack> outputFluids,
Recipe recipe,
int numberOfOperations) {
recipe.getInputs().forEach(ri -> {
if (ri.isNonConsumable()) {
newRecipeInputs.add(ri);
} else {
newRecipeInputs.add(ri.copyWithAmount(ri.getAmount() * numberOfOperations));
}
});
recipe.getFluidInputs().forEach(fi -> {
if (fi.isNonConsumable()) {
newFluidInputs.add(fi);
} else {
newFluidInputs.add(fi.copyWithAmount(fi.getAmount() * numberOfOperations));
}
});
recipe.getOutputs().forEach(itemStack -> outputItems.add(copyItemStackWithCount(itemStack,
itemStack.getCount() * numberOfOperations)));
recipe.getFluidOutputs().forEach(fluidStack -> outputFluids.add(copyFluidStackWithAmount(fluidStack,
fluidStack.amount * numberOfOperations)));
}
public int getParallel() {
return parallel;
}
protected static ItemStack copyItemStackWithCount(ItemStack itemStack, int count) {
ItemStack itemCopy = itemStack.copy();
itemCopy.setCount(count);
return itemCopy;
}
protected static FluidStack copyFluidStackWithAmount(FluidStack fluidStack, int count) {
FluidStack fluidCopy = fluidStack.copy();
fluidCopy.amount = count;
return fluidCopy;
}
public R duration(int duration) {
this.duration = duration;
return (R) this;
}
public R EUt(long EUt) {
this.EUt = EUt;
return (R) this;
}
public R hidden() {
this.hidden = true;
return (R) this;
}
public R category(@NotNull GTRecipeCategory category) {
this.category = category;
return (R) this;
}
public R isCTRecipe() {
this.isCTRecipe = true;
return (R) this;
}
public R setRecipeMap(RecipeMap<R> recipeMap) {
this.recipeMap = recipeMap;
return (R) this;
}
public R copy() {
return (R) new RecipeBuilder<>(this);
}
/**
* Only use if you absolutely don't want the recipe to be run through any build actions.
* Instead, you should blacklist specific actions with {@link #ignoreBuildAction(ResourceLocation)}
*/
public R ignoreAllBuildActions() {
this.ignoreAllBuildActions = true;
return (R) this;
}
public R ignoreBuildAction(ResourceLocation buildActionName) {
if (ignoredBuildActions == null) {
ignoredBuildActions = new Object2ObjectOpenHashMap<>();
} else if (!recipeMap.getBuildActions().containsKey(buildActionName)) {
GTLog.logger.error("Recipe map {} does not contain build action {}!", recipeMap, buildActionName,
new Throwable());
return (R) this;
} else if (ignoredBuildActions.containsKey(buildActionName)) {
return (R) this;
}
ignoredBuildActions.put(buildActionName, recipeMap.getBuildActions().get(buildActionName));
return (R) this;
}
/**
* Generate Recycling Data based on this recipe's Items
*/
public R withRecycling() {
this.withItemRecycling = true;
return (R) this;
}
public ValidationResult<Recipe> build() {
EnumValidationResult result = recipePropertyStorageErrored ? EnumValidationResult.INVALID : validate();
return ValidationResult.newResult(result, new Recipe(inputs, outputs,
new ChancedOutputList<>(this.chancedOutputLogic, chancedOutputs),
fluidInputs, fluidOutputs,
new ChancedOutputList<>(this.chancedFluidOutputLogic, chancedFluidOutputs),
duration, EUt, hidden, isCTRecipe, recipePropertyStorage, category));
}
protected EnumValidationResult validate() {
if (GroovyScriptModule.isCurrentlyRunning()) {
GroovyLog.Msg msg = GroovyLog.msg("Error adding GregTech " + recipeMap.unlocalizedName + " recipe").error();
validateGroovy(msg);
return msg.postIfNotEmpty() ? EnumValidationResult.SKIP : EnumValidationResult.VALID;
}
if (EUt == 0) {
GTLog.logger.error("EU/t cannot be equal to 0", new Throwable());
if (isCTRecipe) {
CraftTweakerAPI.logError("EU/t cannot be equal to 0", new Throwable());
}
recipeStatus = EnumValidationResult.INVALID;
}