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
|
package gregtech.api.util;
import static gregtech.api.enums.GT_Values.*;
import static gregtech.api.enums.Materials.*;
import static gregtech.api.enums.Materials.Void;
import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sHammerRecipes;
import static gregtech.api.util.GT_RecipeBuilder.SECONDS;
import static gregtech.api.util.GT_RecipeBuilder.TICKS;
import static gregtech.api.util.GT_RecipeConstants.UniversalArcFurnace;
import static gregtech.api.util.GT_Utility.calculateRecipeEU;
import java.lang.reflect.Field;
import java.util.*;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.SetMultimap;
import cpw.mods.fml.relauncher.ReflectionHelper;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.enums.*;
import gregtech.api.objects.ItemData;
import gregtech.api.objects.MaterialStack;
import ic2.api.reactor.IReactorComponent;
/**
* Class for Automatic Recipe registering.
*/
public class GT_RecipeRegistrator {
/**
* List of Materials, which are used in the Creation of Sticks. All Rod Materials are automatically added to this
* List.
*/
public static final List<Materials> sRodMaterialList = new ArrayList<>();
private static final ItemStack sMt1 = new ItemStack(Blocks.dirt, 1, 0), sMt2 = new ItemStack(Blocks.dirt, 1, 0);
private static final String s_H = "h", s_F = "f", s_I = "I", s_P = "P", s_R = "R";
private static final RecipeShape[] sShapes = new RecipeShape[] {
new RecipeShape(sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1, null),
new RecipeShape(sMt1, null, sMt1, sMt1, null, sMt1, sMt1, sMt1, sMt1),
new RecipeShape(null, sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1),
new RecipeShape(sMt1, sMt1, sMt1, sMt1, null, sMt1, null, null, null),
new RecipeShape(sMt1, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1),
new RecipeShape(sMt1, sMt1, sMt1, sMt1, null, sMt1, sMt1, null, sMt1),
new RecipeShape(null, null, null, sMt1, null, sMt1, sMt1, null, sMt1),
new RecipeShape(null, sMt1, null, null, sMt1, null, null, sMt2, null),
new RecipeShape(sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2, null),
new RecipeShape(null, sMt1, null, null, sMt2, null, null, sMt2, null),
new RecipeShape(sMt1, sMt1, null, sMt1, sMt2, null, null, sMt2, null),
new RecipeShape(null, sMt1, sMt1, null, sMt2, sMt1, null, sMt2, null),
new RecipeShape(sMt1, sMt1, null, null, sMt2, null, null, sMt2, null),
new RecipeShape(null, sMt1, sMt1, null, sMt2, null, null, sMt2, null),
new RecipeShape(null, sMt1, null, sMt1, null, null, null, sMt1, sMt2),
new RecipeShape(null, sMt1, null, null, null, sMt1, sMt2, sMt1, null),
new RecipeShape(null, sMt1, null, sMt1, null, sMt1, null, null, sMt2),
new RecipeShape(null, sMt1, null, sMt1, null, sMt1, sMt2, null, null),
new RecipeShape(null, sMt2, null, null, sMt1, null, null, sMt1, null),
new RecipeShape(null, sMt2, null, null, sMt2, null, sMt1, sMt1, sMt1),
new RecipeShape(null, sMt2, null, null, sMt2, null, null, sMt1, null),
new RecipeShape(null, sMt2, null, sMt1, sMt2, null, sMt1, sMt1, null),
new RecipeShape(null, sMt2, null, null, sMt2, sMt1, null, sMt1, sMt1),
new RecipeShape(null, sMt2, null, null, sMt2, null, sMt1, sMt1, null),
new RecipeShape(sMt1, null, null, null, sMt2, null, null, null, sMt2),
new RecipeShape(null, null, sMt1, null, sMt2, null, sMt2, null, null),
new RecipeShape(sMt1, null, null, null, sMt2, null, null, null, null),
new RecipeShape(null, null, sMt1, null, sMt2, null, null, null, null),
new RecipeShape(sMt1, sMt2, null, null, null, null, null, null, null),
new RecipeShape(sMt2, sMt1, null, null, null, null, null, null, null),
new RecipeShape(sMt1, null, null, sMt2, null, null, null, null, null),
new RecipeShape(sMt2, null, null, sMt1, null, null, null, null, null),
new RecipeShape(sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, null, sMt2, null),
new RecipeShape(sMt1, sMt1, null, sMt1, sMt1, sMt2, sMt1, sMt1, null),
new RecipeShape(null, sMt1, sMt1, sMt2, sMt1, sMt1, null, sMt1, sMt1),
new RecipeShape(null, sMt2, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1),
new RecipeShape(sMt1, sMt1, sMt1, sMt1, sMt2, sMt1, null, sMt2, null),
new RecipeShape(sMt1, sMt1, null, sMt1, sMt2, sMt2, sMt1, sMt1, null),
new RecipeShape(null, sMt1, sMt1, sMt2, sMt2, sMt1, null, sMt1, sMt1),
new RecipeShape(null, sMt2, null, sMt1, sMt2, sMt1, sMt1, sMt1, sMt1),
new RecipeShape(sMt1, null, null, null, sMt1, null, null, null, null),
new RecipeShape(null, sMt1, null, sMt1, null, null, null, null, null),
new RecipeShape(sMt1, sMt1, null, sMt2, null, sMt1, sMt2, null, null),
new RecipeShape(null, sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2) };
public static final Field SHAPED_ORE_RECIPE_WIDTH = ReflectionHelper.findField(ShapedOreRecipe.class, "width");
public static final Field SHAPED_ORE_RECIPE_HEIGHT = ReflectionHelper.findField(ShapedOreRecipe.class, "height");
private static volatile Map<RecipeShape, List<IRecipe>> indexedRecipeListCache;
private static final String[][] sShapesA = new String[][] { null, null, null,
{ "Helmet", s_P + s_P + s_P, s_P + s_H + s_P },
{ "ChestPlate", s_P + s_H + s_P, s_P + s_P + s_P, s_P + s_P + s_P },
{ "Pants", s_P + s_P + s_P, s_P + s_H + s_P, s_P + " " + s_P }, { "Boots", s_P + " " + s_P, s_P + s_H + s_P },
{ "Sword", " " + s_P + " ", s_F + s_P + s_H, " " + s_R + " " },
{ "Pickaxe", s_P + s_I + s_I, s_F + s_R + s_H, " " + s_R + " " },
{ "Shovel", s_F + s_P + s_H, " " + s_R + " ", " " + s_R + " " },
{ "Axe", s_P + s_I + s_H, s_P + s_R + " ", s_F + s_R + " " },
{ "Axe", s_P + s_I + s_H, s_P + s_R + " ", s_F + s_R + " " },
{ "Hoe", s_P + s_I + s_H, s_F + s_R + " ", " " + s_R + " " },
{ "Hoe", s_P + s_I + s_H, s_F + s_R + " ", " " + s_R + " " },
{ "Sickle", " " + s_P + " ", s_P + s_F + " ", s_H + s_P + s_R },
{ "Sickle", " " + s_P + " ", s_P + s_F + " ", s_H + s_P + s_R },
{ "Sickle", " " + s_P + " ", s_P + s_F + " ", s_H + s_P + s_R },
{ "Sickle", " " + s_P + " ", s_P + s_F + " ", s_H + s_P + s_R },
{ "Sword", " " + s_R + " ", s_F + s_P + s_H, " " + s_P + " " },
{ "Pickaxe", " " + s_R + " ", s_F + s_R + s_H, s_P + s_I + s_I },
{ "Shovel", " " + s_R + " ", " " + s_R + " ", s_F + s_P + s_H },
{ "Axe", s_F + s_R + " ", s_P + s_R + " ", s_P + s_I + s_H },
{ "Axe", s_F + s_R + " ", s_P + s_R + " ", s_P + s_I + s_H },
{ "Hoe", " " + s_R + " ", s_F + s_R + " ", s_P + s_I + s_H },
{ "Hoe", " " + s_R + " ", s_F + s_R + " ", s_P + s_I + s_H },
{ "Spear", s_P + s_H + " ", s_F + s_R + " ", " " + " " + s_R },
{ "Spear", s_P + s_H + " ", s_F + s_R + " ", " " + " " + s_R }, { "Knive", s_H + s_P, s_R + s_F },
{ "Knive", s_F + s_H, s_P + s_R }, { "Knive", s_F + s_H, s_P + s_R }, { "Knive", s_P + s_F, s_R + s_H },
{ "Knive", s_P + s_F, s_R + s_H }, null, null, null, null,
{ "WarAxe", s_P + s_P + s_P, s_P + s_R + s_P, s_F + s_R + s_H }, null, null, null,
{ "Shears", s_H + s_P, s_P + s_F }, { "Shears", s_H + s_P, s_P + s_F },
{ "Scythe", s_I + s_P + s_H, s_R + s_F + s_P, s_R + " " + " " },
{ "Scythe", s_H + s_P + s_I, s_P + s_F + s_R, " " + " " + s_R } };
public static volatile int VERSION = 509;
static {
// flush the cache on post load finish
GregTech_API.sAfterGTPostload.add(() -> indexedRecipeListCache = null);
}
public static void registerMaterialRecycling(ItemStack aStack, Materials aMaterial, long aMaterialAmount,
MaterialStack aByproduct) {
if (GT_Utility.isStackInvalid(aStack)) return;
if (aByproduct != null) {
aByproduct = aByproduct.clone();
aByproduct.mAmount /= aStack.stackSize;
}
GT_OreDictUnificator.addItemData(
GT_Utility.copyAmount(1, aStack),
new ItemData(aMaterial, aMaterialAmount / aStack.stackSize, aByproduct));
}
public static void registerMaterialRecycling(ItemStack aStack, ItemData aData) {
if (GT_Utility.isStackInvalid(aStack) || GT_Utility.areStacksEqual(new ItemStack(Items.blaze_rod), aStack)
|| aData == null
|| !aData.hasValidMaterialData()
|| !aData.mMaterial.mMaterial.mAutoGenerateRecycleRecipes
|| aData.mMaterial.mAmount <= 0
|| GT_Utility.getFluidForFilledItem(aStack, false) != null
|| aData.mMaterial.mMaterial.mSubTags.contains(SubTag.NO_RECIPES)) return;
registerReverseMacerating(GT_Utility.copyAmount(1, aStack), aData, aData.mPrefix == null);
registerReverseSmelting(
GT_Utility.copyAmount(1, aStack),
aData.mMaterial.mMaterial,
aData.mMaterial.mAmount,
true);
registerReverseFluidSmelting(
GT_Utility.copyAmount(1, aStack),
aData.mMaterial.mMaterial,
aData.mMaterial.mAmount,
aData.getByProduct(0));
registerReverseArcSmelting(GT_Utility.copyAmount(1, aStack), aData);
}
/**
* @param aStack the stack to be recycled.
* @param aMaterial the Material.
* @param aMaterialAmount the amount of it in Material Units.
*/
public static void registerReverseFluidSmelting(ItemStack aStack, Materials aMaterial, long aMaterialAmount,
MaterialStack aByproduct) {
if (aStack == null || aMaterial == null
|| aMaterial.mSmeltInto.mStandardMoltenFluid == null
|| !aMaterial.contains(SubTag.SMELTING_TO_FLUID)
|| (L * aMaterialAmount) / (M * aStack.stackSize) <= 0) return;
ItemData tData = GT_OreDictUnificator.getItemData(aStack);
boolean tHide = aStack.getUnlocalizedName()
.startsWith("gt.blockmachines") && (GT_Mod.gregtechproxy.mHideRecyclingRecipes);
if (GT_Mod.gregtechproxy.mHideRecyclingRecipes && tData != null
&& tData.hasValidPrefixData()
&& !(tData.mPrefix == OrePrefixes.dust || tData.mPrefix == OrePrefixes.ingot
|| tData.mPrefix == OrePrefixes.block | tData.mPrefix == OrePrefixes.plate)) {
tHide = true;
}
// boolean tHide = (aMaterial != Materials.Iron && aMaterial!=
// Materials.Redstone)&&(GT_Mod.gregtechproxy.mHideRecyclingRecipes);
// if(tHide && tData!=null&&tData.hasValidPrefixData()&&tData.mPrefix==OrePrefixes.ingot){
// tHide=false;
// }
RA.addFluidSmelterRecipe(
GT_Utility.copyAmount(1, aStack),
aByproduct == null
|| (tData != null && tData.hasValidPrefixData() && tData.mPrefix == OrePrefixes.toolHeadDrill)
? null
: aByproduct.mMaterial.contains(SubTag.NO_SMELTING) || !aByproduct.mMaterial.contains(SubTag.METAL)
? aByproduct.mMaterial.contains(SubTag.FLAMMABLE)
? GT_OreDictUnificator.getDust(Materials.Ash, aByproduct.mAmount / 2)
: aByproduct.mMaterial.contains(SubTag.UNBURNABLE)
? GT_OreDictUnificator
.getDustOrIngot(aByproduct.mMaterial.mSmeltInto, aByproduct.mAmount)
: null
: GT_OreDictUnificator.getIngotOrDust(aByproduct.mMaterial.mSmeltInto, aByproduct.mAmount),
aMaterial.mSmeltInto.getMolten((L * aMaterialAmount) / (M * aStack.stackSize)),
10000,
(int) Math.max(1, (24 * aMaterialAmount) / M),
Math.max(8, (int) Math.sqrt(2 * aMaterial.mSmeltInto.mStandardMoltenFluid.getTemperature())),
tHide);
}
/**
* @param aStack the stack to be recycled.
* @param aMaterial the Material.
* @param aMaterialAmount the amount of it in Material Units.
* @param aAllowAlloySmelter if it is allowed to be recycled inside the Alloy Smelter.
*/
public static void registerReverseSmelting(ItemStack aStack, Materials aMaterial, long aMaterialAmount,
boolean aAllowAlloySmelter) {
if (aStack == null || aMaterial == null
|| aMaterialAmount <= 0
|| aMaterial.contains(SubTag.NO_SMELTING)
|| (aMaterialAmount > M && aMaterial.contains(SubTag.METAL))
|| (aMaterial.getProcessingMaterialTierEU() > TierEU.IV)) return;
if (aMaterial == Materials.Naquadah || aMaterial == Materials.NaquadahEnriched) return;
aMaterialAmount /= aStack.stackSize;
boolean tHide = (aMaterial != Materials.Iron) && (GT_Mod.gregtechproxy.mHideRecyclingRecipes);
if (aAllowAlloySmelter) GT_ModHandler.addSmeltingAndAlloySmeltingRecipe(
GT_Utility.copyAmount(1, aStack),
GT_OreDictUnificator.getIngot(aMaterial.mSmeltInto, aMaterialAmount),
tHide);
else GT_ModHandler.addSmeltingRecipe(
GT_Utility.copyAmount(1, aStack),
GT_OreDictUnificator.getIngot(aMaterial.mSmeltInto, aMaterialAmount));
}
public static void registerReverseArcSmelting(ItemStack aStack, Materials aMaterial, long aMaterialAmount,
MaterialStack aByProduct01, MaterialStack aByProduct02, MaterialStack aByProduct03) {
registerReverseArcSmelting(
aStack,
new ItemData(
aMaterial == null ? null : new MaterialStack(aMaterial, aMaterialAmount),
aByProduct01,
aByProduct02,
aByProduct03));
}
public static void registerReverseArcSmelting(ItemStack aStack, ItemData aData) {
if (aStack == null || aData == null) return;
aData = new ItemData(aData);
if (!aData.hasValidMaterialData()) return;
boolean tIron = false;
for (MaterialStack tMaterial : aData.getAllMaterialStacks()) {
if (tMaterial.mMaterial == Materials.Iron || tMaterial.mMaterial == Materials.Copper
|| tMaterial.mMaterial == Materials.WroughtIron
|| tMaterial.mMaterial == Materials.AnnealedCopper) tIron = true;
if (tMaterial.mMaterial.contains(SubTag.UNBURNABLE)) {
tMaterial.mMaterial = tMaterial.mMaterial.mSmeltInto.mArcSmeltInto;
continue;
}
if (tMaterial.mMaterial.contains(SubTag.EXPLOSIVE)) {
tMaterial.mMaterial = Materials.Ash;
tMaterial.mAmount /= 16;
continue;
}
if (tMaterial.mMaterial.contains(SubTag.FLAMMABLE)) {
tMaterial.mMaterial = Materials.Ash;
tMaterial.mAmount /= 8;
continue;
}
if (tMaterial.mMaterial.contains(SubTag.NO_SMELTING)) {
tMaterial.mAmount = 0;
continue;
}
if (tMaterial.mMaterial.contains(SubTag.METAL)) {
if (GT_Mod.gregtechproxy.mArcSmeltIntoAnnealed) {
tMaterial.mMaterial = tMaterial.mMaterial.mSmeltInto.mArcSmeltInto;
} else {
tMaterial.mMaterial = tMaterial.mMaterial.mSmeltInto.mSmeltInto;
}
continue;
}
tMaterial.mAmount = 0;
}
aData = new ItemData(aData);
if (aData.mByProducts.length > 3) for (MaterialStack tMaterial : aData.getAllMaterialStacks()) {
if (tMaterial.mMaterial == Materials.Ash) tMaterial.mAmount = 0;
}
aData = new ItemData(aData);
if (!aData.hasValidMaterialData()) return;
long tAmount = 0;
for (MaterialStack tMaterial : aData.getAllMaterialStacks())
tAmount += tMaterial.mAmount * tMaterial.mMaterial.getMass();
boolean tHide = !tIron && GT_Mod.gregtechproxy.mHideRecyclingRecipes;
if (aData.mPrefix == OrePrefixes.toolHeadDrill) {
GT_RecipeBuilder recipeBuilder = GT_Values.RA.stdBuilder();
recipeBuilder.itemInputs(aStack)
.itemOutputs(GT_OreDictUnificator.getIngotOrDust(aData.mMaterial))
.fluidInputs(Materials.Oxygen.getGas((int) Math.max(16, tAmount / M)))
.noFluidOutputs()
.duration(((int) Math.max(16, tAmount / M)) * TICKS)
.eut(90);
if (tHide) {
recipeBuilder.hidden();
}
recipeBuilder.addTo(UniversalArcFurnace);
} else {
ArrayList<ItemStack> outputs = new ArrayList<ItemStack>();
if (GT_OreDictUnificator.getIngotOrDust(aData.mMaterial) != null) {
outputs.add(GT_OreDictUnificator.getIngotOrDust(aData.mMaterial));
}
for (int i = 0; i < 8; i++) {
if (GT_OreDictUnificator.getIngotOrDust(aData.getByProduct(i)) != null) {
outputs.add(GT_OreDictUnificator.getIngotOrDust(aData.getByProduct(i)));
}
}
if (outputs.size() != 0) {
ItemStack[] outputsArray = outputs.toArray(new ItemStack[outputs.size()]);
GT_RecipeBuilder recipeBuilder = GT_Values.RA.stdBuilder();
recipeBuilder.itemInputs(aStack)
.itemOutputs(outputsArray)
.fluidInputs(Materials.Oxygen.getGas((int) Math.max(16, tAmount / M)))
.noFluidOutputs()
.duration(((int) Math.max(16, tAmount / M)) * TICKS)
.eut(90);
if (tHide) {
recipeBuilder.hidden();
}
recipeBuilder.addTo(UniversalArcFurnace);
}
}
}
public static void registerReverseMacerating(ItemStack aStack, Materials aMaterial, long aMaterialAmount,
MaterialStack aByProduct01, MaterialStack aByProduct02, MaterialStack aByProduct03, boolean aAllowHammer) {
registerReverseMacerating(
aStack,
new ItemData(
aMaterial == null ? null : new MaterialStack(aMaterial, aMaterialAmount),
aByProduct01,
aByProduct02,
aByProduct03),
aAllowHammer);
}
public static void registerReverseMacerating(ItemStack aStack, ItemData aData, boolean aAllowHammer) {
if (aStack == null || aData == null) return;
aData = new ItemData(aData);
if (!aData.hasValidMaterialData()) return;
for (MaterialStack tMaterial : aData.getAllMaterialStacks())
tMaterial.mMaterial = tMaterial.mMaterial.mMacerateInto;
aData = new ItemData(aData);
if (!aData.hasValidMaterialData()) return;
long tAmount = 0;
for (MaterialStack tMaterial : aData.getAllMaterialStacks())
tAmount += tMaterial.mAmount * tMaterial.mMaterial.getMass();
boolean tHide = (aData.mMaterial.mMaterial != Materials.Iron) && (GT_Mod.gregtechproxy.mHideRecyclingRecipes);
if (aData.mPrefix == OrePrefixes.toolHeadDrill) {
RA.addPulveriserRecipe(
aStack,
new ItemStack[] { GT_OreDictUnificator.getDust(aData.mMaterial) },
null,
aData.mMaterial.mMaterial == Materials.Marble ? 1 : (int) Math.max(16, tAmount / M),
4,
tHide);
} else {
RA.addPulveriserRecipe(
aStack,
new ItemStack[] { GT_OreDictUnificator.getDust(aData.mMaterial),
GT_OreDictUnificator.getDust(aData.getByProduct(0)),
GT_OreDictUnificator.getDust(aData.getByProduct(1)),
GT_OreDictUnificator.getDust(aData.getByProduct(2)) },
null,
aData.mMaterial.mMaterial == Materials.Marble ? 1 : (int) Math.max(16, tAmount / M),
4,
tHide);
}
if (!aAllowHammer) {
return;
}
for (MaterialStack tMaterial : aData.getAllMaterialStacks()) {
if (tMaterial.mMaterial.contains(SubTag.CRYSTAL) && !tMaterial.mMaterial.contains(SubTag.METAL)
&& tMaterial.mMaterial != Materials.Glass
&& GT_OreDictUnificator.getDust(aData.mMaterial) != null) {
GT_Values.RA.stdBuilder()
.itemInputs(GT_Utility.copyAmount(1, aStack))
.itemOutputs(GT_OreDictUnificator.getDust(aData.mMaterial))
.noFluidInputs()
.noFluidOutputs()
.duration(10 * SECONDS)
.eut(TierEU.RECIPE_LV)
.addTo(sHammerRecipes);
break;
}
}
}
/**
* Place Materials which you want to replace in Non-GT-Recipes here (warning HUGHE impact on loading times!)
*/
private static final Materials[] VANILLA_MATS = { Cobalt, Gold, Iron, Lead, FierySteel, Void, Bronze, Diamond, Ruby,
Sapphire, Steel, IronWood, Steeleaf, Knightmetal, Thaumium, DarkSteel, };
/**
* You give this Function a Material and it will scan almost everything for adding recycling Recipes and replacing
* Ingots, Gems etc.
*
* @param aMats Materials, for example an Ingot or a Gem.
* @param aPlate the Plate referenced to aMat
* @param aRecipeReplacing allows to replace the Recipe with a Plate variant
*/
public static synchronized void registerUsagesForMaterials(String aPlate, boolean aRecipeReplacing,
ItemStack... aMats) {
for (ItemStack aMat : aMats) {
aMat = GT_Utility.copyOrNull(aMat);
if (aMat == null) continue;
ItemData aItemData = GT_OreDictUnificator.getItemData(aMat);
if (aItemData == null || aItemData.mPrefix != OrePrefixes.ingot) aPlate = null;
if (aPlate != null && GT_OreDictUnificator.getFirstOre(aPlate, 1) == null) aPlate = null;
sMt1.func_150996_a(aMat.getItem());
sMt1.stackSize = 1;
Items.feather.setDamage(sMt1, Items.feather.getDamage(aMat));
sMt2.func_150996_a(new ItemStack(Blocks.dirt).getItem());
sMt2.stackSize = 1;
Items.feather.setDamage(sMt2, 0);
if (aItemData != null && aItemData.hasValidPrefixMaterialData()) {
for (RecipeShape tRecipe : sShapes) {
for (ItemStack tCrafted : GT_ModHandler.getRecipeOutputsBuffered(tRecipe.shape)) {
GT_OreDictUnificator.addItemData(
tCrafted,
new ItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tRecipe.amount1));
//
// GT_Log.out.println("###################################################################################");
// GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aPlate);
// GT_Log.out.println("registerUsagesForMaterials used aPlate:
// "+aMat.getUnlocalizedName());
// GT_Log.out.println("registerUsagesForMaterials used aPlate:
// "+aMat.getDisplayName());
//
// GT_Log.out.println("###################################################################################");
}
}
}
registerStickStuff(aPlate, aItemData, aRecipeReplacing);
}
}
private static List<IRecipe> getRecipeList(RecipeShape shape) {
boolean force = !GregTech_API.sPostloadStarted || GregTech_API.sPostloadFinished;
if (force || indexedRecipeListCache == null) {
synchronized (GT_RecipeRegistrator.class) {
if (indexedRecipeListCache == null || force) {
indexedRecipeListCache = createIndexedRecipeListCache();
}
}
}
return indexedRecipeListCache.get(shape);
}
private static Map<RecipeShape, List<IRecipe>> createIndexedRecipeListCache() {
Map<RecipeShape, List<IRecipe>> result = new IdentityHashMap<>();
@SuppressWarnings("unchecked")
ArrayList<IRecipe> allRecipeList = (ArrayList<IRecipe>) CraftingManager.getInstance()
.getRecipeList();
// filter using the empty slots in the shape.
// if the empty slots doesn't match, the recipe will definitely fail
SetMultimap<List<Integer>, RecipeShape> filter = HashMultimap.create();
for (RecipeShape shape : sShapes) {
for (List<Integer> list : shape.getEmptySlotsAllVariants()) {
filter.put(list, shape);
}
}
List<Integer> buffer = new ArrayList<>(9);
for (IRecipe tRecipe : allRecipeList) {
if (tRecipe instanceof ShapelessRecipes || tRecipe instanceof ShapelessOreRecipe) {
// we don't target shapeless recipes
continue;
}
buffer.clear();
ItemStack tStack = tRecipe.getRecipeOutput();
if (GT_Utility.isStackValid(tStack) && tStack.getMaxStackSize() == 1
&& tStack.getMaxDamage() > 0
&& !(tStack.getItem() instanceof ItemBlock)
&& !(tStack.getItem() instanceof IReactorComponent)
&& !GT_ModHandler.isElectricItem(tStack)
&& !GT_Utility.isStackInList(tStack, GT_ModHandler.sNonReplaceableItems)) {
if (tRecipe instanceof ShapedOreRecipe) {
ShapedOreRecipe tShapedRecipe = (ShapedOreRecipe) tRecipe;
if (checkRecipeShape(
buffer,
tShapedRecipe.getInput(),
getRecipeWidth(tShapedRecipe),
getRecipeHeight(tShapedRecipe))) {
for (RecipeShape s : filter.get(buffer)) {
result.computeIfAbsent(s, k -> new ArrayList<>())
.add(tRecipe);
}
}
} else if (tRecipe instanceof ShapedRecipes) {
ShapedRecipes tShapedRecipe = (ShapedRecipes) tRecipe;
if (checkRecipeShape(
buffer,
tShapedRecipe.recipeItems,
getRecipeWidth(tShapedRecipe),
getRecipeHeight(tShapedRecipe))) {
for (RecipeShape s : filter.get(buffer)) {
result.computeIfAbsent(s, k -> new ArrayList<>())
.add(tRecipe);
}
}
} else {
for (RecipeShape s : sShapes) {
// unknown recipe type. cannot determine empty slots. we choose to add to the recipe list for
// all shapes
result.computeIfAbsent(s, k -> new ArrayList<>())
.add(tRecipe);
}
}
}
}
return result;
}
private static boolean checkRecipeShape(List<Integer> emptySlotIndexesBuffer, Object[] input, int tRecipeWidth,
int tRecipeHeight) {
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
if (x >= tRecipeWidth || y >= tRecipeHeight) {
emptySlotIndexesBuffer.add(x + y * 3);
continue;
}
Object tObject = input[x + y * tRecipeWidth];
if (tObject == null) {
emptySlotIndexesBuffer.add(x + y * 3);
continue;
}
if (tObject instanceof ItemStack
&& (((ItemStack) tObject).getItem() == null || ((ItemStack) tObject).getMaxStackSize() < 2
|| ((ItemStack) tObject).getMaxDamage() > 0
|| ((ItemStack) tObject).getItem() instanceof ItemBlock)) {
return false;
}
if (tObject instanceof List && ((List<?>) tObject).isEmpty()) {
return false;
}
}
}
return true;
}
private static synchronized void registerStickStuff(String aPlate, ItemData aItemData, boolean aRecipeReplacing) {
ItemStack tStack;
for (Materials tMaterial : sRodMaterialList) {
ItemStack tMt2 = GT_OreDictUnificator.get(OrePrefixes.stick, tMaterial, 1);
if (tMt2 != null) {
sMt2.func_150996_a(tMt2.getItem());
sMt2.stackSize = 1;
Items.feather.setDamage(sMt2, Items.feather.getDamage(tMt2));
for (int i = 0; i < sShapes.length; i++) {
RecipeShape tRecipe = sShapes[i];
for (ItemStack tCrafted : GT_ModHandler
.getRecipeOutputs(getRecipeList(tRecipe), true, tRecipe.shape)) {
if (aItemData != null && aItemData.hasValidPrefixMaterialData())
GT_OreDictUnificator.addItemData(
tCrafted,
new ItemData(
aItemData.mMaterial.mMaterial,
aItemData.mMaterial.mAmount * tRecipe.amount1,
new MaterialStack(tMaterial, OrePrefixes.stick.mMaterialAmount * tRecipe.amount2)));
if (aRecipeReplacing && aPlate != null && sShapesA[i] != null && sShapesA[i].length > 1) {
assert aItemData != null;
if (GregTech_API.sRecipeFile.get(
ConfigCategories.Recipes.recipereplacements,
aItemData.mMaterial.mMaterial + "." + sShapesA[i][0],
true)) {
if (null != (tStack = GT_ModHandler.removeRecipe(tRecipe.shape))) {
switch (sShapesA[i].length) {
case 2 -> GT_ModHandler.addCraftingRecipe(
tStack,
GT_ModHandler.RecipeBits.BUFFERED,
new Object[] { sShapesA[i][1], s_P.charAt(0), aPlate, s_R.charAt(0),
OrePrefixes.stick.get(tMaterial), s_I.charAt(0), aItemData });
case 3 -> GT_ModHandler.addCraftingRecipe(
tStack,
GT_ModHandler.RecipeBits.BUFFERED,
new Object[] { sShapesA[i][1], sShapesA[i][2], s_P.charAt(0), aPlate,
s_R.charAt(0), OrePrefixes.stick.get(tMaterial), s_I.charAt(0),
aItemData });
default -> GT_ModHandler.addCraftingRecipe(
tStack,
GT_ModHandler.RecipeBits.BUFFERED,
new Object[] { sShapesA[i][1], sShapesA[i][2], sShapesA[i][3],
s_P.charAt(0), aPlate, s_R.charAt(0), OrePrefixes.stick.get(tMaterial),
s_I.charAt(0), aItemData });
}
}
}
}
}
}
}
}
}
/**
* Registers wiremill recipes for given material using integrated circuits.
*
* @param aMaterial material to register
* @param baseDuration base duration ticks for ingot -> 1x wire recipe
* @param aEUt EU/t for recipe If you provide a proper EU tier for recipe processing then aEUt will be
* overriden with it.
*/
public static void registerWiremillRecipes(Materials aMaterial, int baseDuration, int aEUt) {
registerWiremillRecipes(
aMaterial,
baseDuration,
calculateRecipeEU(aMaterial, aEUt),
OrePrefixes.ingot,
OrePrefixes.stick,
2);
}
/**
* Registers wiremill recipes for given material using integrated circuits.
*
* @param aMaterial material to register
* @param baseDuration base duration ticks for ingot -> 1x wire recipe
* @param aEUt EU/t for recipe
* @param prefix1 prefix corresponds to ingot
* @param prefix2 prefix corresponds to stick
* @param multiplier amount of wires created from 1 ingot
*/
public static void registerWiremillRecipes(Materials aMaterial, int baseDuration, int aEUt, OrePrefixes prefix1,
OrePrefixes prefix2, int multiplier) {
GT_Values.RA.addWiremillRecipe(
GT_OreDictUnificator.get(prefix1, aMaterial, 1L),
GT_Utility.getIntegratedCircuit(1),
GT_OreDictUnificator.get(OrePrefixes.wireGt01, aMaterial, multiplier),
baseDuration,
aEUt);
GT_Values.RA.addWiremillRecipe(
GT_OreDictUnificator.get(prefix1, aMaterial, 2L / multiplier),
GT_Utility.getIntegratedCircuit(2),
GT_OreDictUnificator.get(OrePrefixes.wireGt02, aMaterial, 1L),
(int) (baseDuration * 1.5f),
aEUt);
GT_Values.RA.addWiremillRecipe(
GT_OreDictUnificator.get(prefix1, aMaterial, 4L / multiplier),
GT_Utility.getIntegratedCircuit(4),
GT_OreDictUnificator.get(OrePrefixes.wireGt04, aMaterial, 1L),
baseDuration * 2,
aEUt);
GT_Values.RA.addWiremillRecipe(
GT_OreDictUnificator.get(prefix1, aMaterial, 8L / multiplier),
GT_Utility.getIntegratedCircuit(8),
GT_OreDictUnificator.get(OrePrefixes.wireGt08, aMaterial, 1L),
(int) (baseDuration * 2.5f),
aEUt);
GT_Values.RA.addWiremillRecipe(
GT_OreDictUnificator.get(prefix1, aMaterial, 12L / multiplier),
GT_Utility.getIntegratedCircuit(12),
GT_OreDictUnificator.get(OrePrefixes.wireGt12, aMaterial, 1L),
baseDuration * 3,
aEUt);
GT_Values.RA.addWiremillRecipe(
GT_OreDictUnificator.get(prefix1, aMaterial, 16L / multiplier),
GT_Utility.getIntegratedCircuit(16),
GT_OreDictUnificator.get(OrePrefixes.wireGt16, aMaterial, 1L),
(int) (baseDuration * 3.5f),
aEUt);
GT_Values.RA.addWiremillRecipe(
GT_OreDictUnificator.get(prefix2, aMaterial, 2L / multiplier),
GT_Utility.getIntegratedCircuit(1),
GT_OreDictUnificator.get(OrePrefixes.wireGt01, aMaterial, 1L),
baseDuration / 2,
aEUt);
GT_Values.RA.addWiremillRecipe(
GT_OreDictUnificator.get(prefix2, aMaterial, 4L / multiplier),
GT_Utility.getIntegratedCircuit(2),
GT_OreDictUnificator.get(OrePrefixes.wireGt02, aMaterial, 1L),
baseDuration,
aEUt);
GT_Values.RA.addWiremillRecipe(
GT_OreDictUnificator.get(prefix2, aMaterial, 8L / multiplier),
GT_Utility.getIntegratedCircuit(4),
GT_OreDictUnificator.get(OrePrefixes.wireGt04, aMaterial, 1L),
(int) (baseDuration * 1.5f),
aEUt);
GT_Values.RA.addWiremillRecipe(
GT_OreDictUnificator.get(prefix2, aMaterial, 16L / multiplier),
GT_Utility.getIntegratedCircuit(8),
GT_OreDictUnificator.get(OrePrefixes.wireGt08, aMaterial, 1L),
baseDuration * 2,
aEUt);
GT_Values.RA.addWiremillRecipe(
GT_OreDictUnificator.get(prefix2, aMaterial, 24L / multiplier),
GT_Utility.getIntegratedCircuit(12),
GT_OreDictUnificator.get(OrePrefixes.wireGt12, aMaterial, 1L),
(int) (baseDuration * 2.5f),
aEUt);
GT_Values.RA.addWiremillRecipe(
GT_OreDictUnificator.get(prefix2, aMaterial, 32L / multiplier),
GT_Utility.getIntegratedCircuit(16),
GT_OreDictUnificator.get(OrePrefixes.wireGt16, aMaterial, 1L),
baseDuration * 3,
aEUt);
GT_Values.RA.addWiremillRecipe(
GT_OreDictUnificator.get(prefix1, aMaterial, 1L),
GT_Utility.getIntegratedCircuit(3),
GT_OreDictUnificator.get(OrePrefixes.wireFine, aMaterial, 4L * multiplier),
baseDuration,
aEUt);
GT_Values.RA.addWiremillRecipe(
GT_OreDictUnificator.get(prefix2, aMaterial, 1L),
GT_Utility.getIntegratedCircuit(3),
GT_OreDictUnificator.get(OrePrefixes.wireFine, aMaterial, 2L * multiplier),
baseDuration / 2,
aEUt);
}
public static boolean hasVanillaRecipes(Materials materials) {
return Arrays.stream(VANILLA_MATS)
.anyMatch(mat -> mat == materials);
}
private static int getRecipeWidth(ShapedOreRecipe r) {
try {
return (int) SHAPED_ORE_RECIPE_WIDTH.get(r);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
private static int getRecipeHeight(ShapedOreRecipe r) {
try {
return (int) SHAPED_ORE_RECIPE_HEIGHT.get(r);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
private static int getRecipeHeight(ShapedRecipes r) {
return r.recipeHeight;
}
private static int getRecipeWidth(ShapedRecipes r) {
return r.recipeWidth;
}
private static class RecipeShape {
private final ItemStack[] shape;
private int amount1;
private int amount2;
public RecipeShape(ItemStack... shape) {
this.shape = shape;
for (ItemStack stack : shape) {
if (stack == sMt1) this.amount1++;
if (stack == sMt2) this.amount2++;
}
}
public List<List<Integer>> getEmptySlotsAllVariants() {
// "shake" the grid in 8 direction and see if the recipe shape is still valid
// also include the "no movement" case
ImmutableList.Builder<List<Integer>> b = ImmutableList.builder();
for (int i = -1; i < 2; i++) {
if (i != 0 && !isColClear(i + 1)) continue;
for (int j = -1; j < 2; j++) {
if (j != 0 && !isRowClear(j + 1)) continue;
b.add(getEmptySlots(i, j));
}
}
return b.build();
}
private boolean isRowClear(int row) {
for (int i = 0; i < 3; i++) {
if (shape[i + row * 3] != null) return false;
}
return true;
}
private boolean isColClear(int col) {
for (int i = 0; i < 3; i++) {
if (shape[col + i * 3] != null) return false;
}
return true;
}
private List<Integer> getEmptySlots(int offsetX, int offsetY) {
ImmutableList.Builder<Integer> b = ImmutableList.builder();
for (int i = 0; i < shape.length; i++) {
int mappedIndex = i - offsetX - offsetY * 3;
// empty slot if it either
// 1) map to a slot outside the original shape
// 2) map to an empty slot in original shape
if (mappedIndex < 0 || mappedIndex > 8 || shape[mappedIndex] == null) b.add(i);
}
return b.build();
}
}
}
|