aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/xmod/gregtech/HANDLER_GT.java
blob: c0652c2a6de9193a75c9dfe05d6ab6d23c24417c (plain)
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
package gtPlusPlus.xmod.gregtech;

import static gtPlusPlus.core.recipe.common.CI.bits;
import static gtPlusPlus.core.util.minecraft.MaterialUtils.getMaterialName;

import cpw.mods.fml.common.event.FMLLoadCompleteEvent;
import gregtech.api.GregTech_API;
import gregtech.api.enums.Element;
import gregtech.api.enums.ItemList;
import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.items.GT_MetaGenerated_Tool;
import gregtech.api.util.GTPP_Recipe;
import gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map;
import gregtech.api.util.GT_Config;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_ModHandler.RecipeBits;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Recipe.GT_Recipe_Map;
import gregtech.api.util.GT_Utility;
import gregtech.common.items.GT_MetaGenerated_Tool_01;
import gregtech.common.items.behaviors.Behaviour_DataOrb;
import gtPlusPlus.api.helpers.GregtechPlusPlus_API.Multiblock_API;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.api.objects.data.Pair;
import gtPlusPlus.api.objects.minecraft.multi.NoEUBonusMultiBehaviour;
import gtPlusPlus.api.objects.minecraft.multi.NoOutputBonusMultiBehaviour;
import gtPlusPlus.api.objects.minecraft.multi.NoSpeedBonusMultiBehaviour;
import gtPlusPlus.australia.gen.gt.WorldGen_GT_Australia;
import gtPlusPlus.core.handler.COMPAT_HANDLER;
import gtPlusPlus.core.handler.OldCircuitHandler;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.lib.CORE.ConfigSwitches;
import gtPlusPlus.core.lib.LoadedMods;
import gtPlusPlus.core.material.ELEMENT;
import gtPlusPlus.core.recipe.common.CI;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.core.util.minecraft.MaterialUtils;
import gtPlusPlus.core.util.minecraft.RecipeUtils;
import gtPlusPlus.core.util.reflect.AddGregtechRecipe;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.everglades.gen.gt.WorldGen_GT;
import gtPlusPlus.xmod.gregtech.api.enums.CustomOrePrefix;
import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList;
import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials;
import gtPlusPlus.xmod.gregtech.api.util.GTPP_Config;
import gtPlusPlus.xmod.gregtech.api.world.GTPP_Worldgen;
import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy;
import gtPlusPlus.xmod.gregtech.common.StaticFields59;
import gtPlusPlus.xmod.gregtech.common.blocks.fluid.GregtechFluidHandler;
import gtPlusPlus.xmod.gregtech.common.computer.GT_ComputerCube_Setup;
import gtPlusPlus.xmod.gregtech.common.computer.GT_Computercube_Description;
import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechTools;
import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.GregtechMTE_ElementalDuplicator;
import gtPlusPlus.xmod.gregtech.loaders.Gregtech_Blocks;
import gtPlusPlus.xmod.gregtech.loaders.ProcessingAngleGrinder;
import gtPlusPlus.xmod.gregtech.loaders.ProcessingElectricButcherKnife;
import gtPlusPlus.xmod.gregtech.loaders.ProcessingElectricLighter;
import gtPlusPlus.xmod.gregtech.loaders.ProcessingElectricSnips;
import gtPlusPlus.xmod.gregtech.loaders.ProcessingToolHeadChoocher;
import gtPlusPlus.xmod.gregtech.loaders.misc.AddCustomMachineToPA;
import gtPlusPlus.xmod.gregtech.loaders.recipe.RecipeLoader_AlgaeFarm;
import gtPlusPlus.xmod.gregtech.loaders.recipe.RecipeLoader_MolecularTransformer;
import gtPlusPlus.xmod.gregtech.recipes.RecipesToRemove;
import gtPlusPlus.xmod.gregtech.registration.gregtech.GregtechConduits;
import gtPlusPlus.xmod.gregtech.registration.gregtech.GregtechNitroDieselFix;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

public class HANDLER_GT {

    public static GT_Config mMaterialProperties = null;

    public static GTPP_Config sCustomWorldgenFile = null;
    public static final List<WorldGen_GT> sWorldgenListEverglades = new ArrayList<WorldGen_GT>();
    public static final List<WorldGen_GT_Australia> sWorldgenListAustralia = new ArrayList<WorldGen_GT_Australia>();
    public static final List<GTPP_Worldgen> sCustomWorldgenList = new ArrayList<GTPP_Worldgen>();
    public static GT_MetaGenerated_Tool sMetaGeneratedToolInstance;

    public static void preInit() {

        if (mMaterialProperties != null) {
            GT_Materials.init(mMaterialProperties);
        }

        if (ConfigSwitches.enableOldGTcircuits && !CORE.GTNH) {
            OldCircuitHandler.preInit();
        }

        GregtechFluidHandler.run();
    }

    public static void init() {

        // Load General Blocks and set up some Basic Meta Tile Entity states
        Gregtech_Blocks.run();

        // Add Custom Pipes, Wires and Cables.
        GregtechConduits.run();

        // Register Tile Entities
        COMPAT_HANDLER.registerGregtechMachines();

        // Only loads if the config option is true (default: true)
        if (CORE.ConfigSwitches.enableSkookumChoochers) {
            sMetaGeneratedToolInstance = MetaGeneratedGregtechTools.getInstance();
        }

        if (ConfigSwitches.enableOldGTcircuits && !CORE.GTNH) {
            OldCircuitHandler.init();
        }

        // Generates recipes for all gregtech smelting and alloy smelting combinations.
        // RecipeGen_BlastSmelterGT.generateRecipes();
        // new RecipeGen_BlastSmelterGT_Ex();

    }

    public static void postInit() {

        // Only loads if the config option is true (default: true)
        if (CORE.ConfigSwitches.enableSkookumChoochers) {
            new ProcessingToolHeadChoocher().run();
        }
        new ProcessingAngleGrinder().run();
        new ProcessingElectricSnips().run();
        new ProcessingElectricButcherKnife().run();
        new ProcessingElectricLighter().run();

        if (CORE.ConfigSwitches.enableNitroFix) {
            GregtechNitroDieselFix.run();
        }

        if (ConfigSwitches.enableOldGTcircuits && !CORE.GTNH) {
            OldCircuitHandler.postInit();
        }

        // Register custom singles to the PA
        AddCustomMachineToPA.register();

        // Register the No-Bonus Special Behaviour.
        Multiblock_API.registerSpecialMultiBehaviour(new NoOutputBonusMultiBehaviour());
        Multiblock_API.registerSpecialMultiBehaviour(new NoSpeedBonusMultiBehaviour());
        Multiblock_API.registerSpecialMultiBehaviour(new NoEUBonusMultiBehaviour());

        // Register some custom recipe maps for any enabled multiblocks.
        // MultiblockRecipeMapHandler.run();

        if (GregtechItemList.Circuit_BioRecipeSelector.hasBeenSet()) {
            for (int i = 1; i <= 24; i++) {
                GregTech_API.registerConfigurationCircuit(CI.getNumberedBioCircuit(i), 0);
            }
        }

        if (GregtechItemList.Circuit_T3RecipeSelector.hasBeenSet()) {
            for (int i = 1; i <= 24; i++) {
                GregTech_API.registerConfigurationCircuit(CI.getNumberedAdvancedCircuit(i), 3);
            }
        }
    }

    public static void onLoadComplete(FMLLoadCompleteEvent event) {
        removeCrudeTurbineRotors();
        // cleanAssemblyLineRecipeMap();
        if (ConfigSwitches.enableHarderRecipesForHighTierCasings) {
            removeOldHighTierCasingRecipes();
        }
        RecipesToRemove.go();
        convertPyroToCokeOven();
        generateElementalDuplicatorRecipes();
        Meta_GT_Proxy.fixIC2FluidNames();
        GT_Computercube_Description.addStandardDescriptions();
        GT_ComputerCube_Setup.init();
        RecipeLoader_AlgaeFarm.generateRecipes();
        if (LoadedMods.AdvancedSolarPanel) {
            RecipeLoader_MolecularTransformer.run();
        }
    }

    public static void addNewOrePrefixes() {
        for (CustomOrePrefix aPrefixTest : CustomOrePrefix.values()) {
            Logger.INFO("Adding " + aPrefixTest.name() + " to OrePrefixes Enum.");
            Logger.INFO("Injecting: " + aPrefixTest.addToEnum());
        }
    }

    private static void generateElementalDuplicatorRecipes() {
        for (GT_Recipe aRecipe : GT_Recipe_Map.sReplicatorFakeRecipes.mRecipeList) {
            Object aDataOrb = aRecipe.mSpecialItems;
            if (aDataOrb != null) {
                ItemStack aOutput = aRecipe.mOutputs[0];
                if (aOutput != null) {
                    FluidStack aFluid = aRecipe.mFluidInputs[0];
                    if (aFluid != null && aFluid.amount > 0) {
                        ItemStack tDataOrb = GregtechMTE_ElementalDuplicator.getSpecialSlotStack(aRecipe);
                        Materials tMaterial = Element.get(Behaviour_DataOrb.getDataName(tDataOrb))
                                .mLinkedMaterials
                                .get(0);
                        FluidStack aOutputFluid = null;
                        ItemStack aOutputItem = null;
                        if (tMaterial != null) {
                            boolean aUsingFluid = false;
                            if ((aOutputItem = GT_OreDictUnificator.get(OrePrefixes.dust, tMaterial, 1L)) == null) {
                                if ((aOutputItem = GT_OreDictUnificator.get(OrePrefixes.cell, tMaterial, 1L)) != null) {
                                    aOutputFluid = GT_Utility.getFluidForFilledItem(aOutputItem, true);
                                    aUsingFluid = true;
                                }
                            }
                            GTPP_Recipe aNewRecipe = new GTPP_Recipe(
                                    false,
                                    new ItemStack[] {},
                                    new ItemStack[] {!aUsingFluid ? aOutputItem : null},
                                    aRecipe.mSpecialItems,
                                    null,
                                    aRecipe.mFluidInputs,
                                    new FluidStack[] {aUsingFluid ? aOutputFluid : null},
                                    aRecipe.mDuration,
                                    aRecipe.mEUt,
                                    aRecipe.mFluidInputs[0].amount);
                            GTPP_Recipe_Map.sElementalDuplicatorRecipes.add(aNewRecipe);

                            Logger.INFO("[EM] Generated recipe for " + tMaterial.mLocalizedName + ", Outputs "
                                    + (aUsingFluid ? "Fluid" : "Dust"));
                        }
                    } else {
                        Logger.INFO("[EM] Bad UU Requirement. " + RecipeUtils.getRecipeInfo(aRecipe));
                    }
                } else {
                    Logger.INFO("[EM] Bad Output. " + RecipeUtils.getRecipeInfo(aRecipe));
                }
            } else {
                Logger.INFO("[EM] Bad Data Orb. " + RecipeUtils.getRecipeInfo(aRecipe));
            }
        }
        int aSize = GTPP_Recipe_Map.sElementalDuplicatorRecipes.mRecipeList.size();
        Logger.INFO("[EM] Generated " + aSize + "/" + GT_Recipe_Map.sReplicatorFakeRecipes.mRecipeList.size()
                + " Replicator recipes.");
    }

    private static void convertPyroToCokeOven() {
        if (ReflectionUtils.doesFieldExist(GT_Recipe.GT_Recipe_Map.class, "sPyrolyseRecipes")) {
            int aCount = 0;
            GT_Recipe_Map aMap = StaticFields59.getPyrolyseRecipeMap();
            if (aMap != null) {
                for (GT_Recipe g : aMap.mRecipeList) {
                    if (AddGregtechRecipe.importPyroRecipe(g)) {
                        aCount++;
                    }
                }
                Logger.INFO("Converted " + aCount + " Pyrolyse recipes into Industrial Coke Oven recipes.");
            }
        }
    }

    private static GT_Recipe replaceItemInRecipeWithAnother(
            GT_Recipe aRecipe, ItemStack aExisting, ItemStack aNewItem) {
        ItemStack[] aInputItemsCopy = aRecipe.mInputs;
        String aOutputName = ItemUtils.getItemName(aRecipe.mOutputs[0]);
        boolean aDidChange = false;
        Logger.INFO("Attempting to Modify Recipe for " + aOutputName);
        for (int i = 0; i < aRecipe.mInputs.length; i++) {
            ItemStack aCurrentInputSlot = aRecipe.mInputs[i];
            if (aCurrentInputSlot != null) {
                if (GT_Utility.areStacksEqual(aCurrentInputSlot, aExisting, true)) {
                    aInputItemsCopy[i] = ItemUtils.getSimpleStack(aNewItem, aCurrentInputSlot.stackSize);
                    aDidChange = true;
                }
            }
        }
        if (aDidChange) {
            aRecipe.mInputs = aInputItemsCopy;
            Logger.INFO("Modifed Recipe for " + aOutputName);
            return aRecipe;
        } else {
            Logger.INFO("Failed to Modify Recipe for " + aOutputName);
            return aRecipe;
        }
    }

    private static void updateRecipeMap(GT_Recipe aOld, GT_Recipe aNew, GT_Recipe_Map aMap) {
        RecipeUtils.removeGtRecipe(aOld, aMap);
        RecipeUtils.addGtRecipe(aNew, aMap);
        Logger.INFO("Updating recipe map: " + aMap.mNEIName);
        Logger.INFO("Removed Recipe with hash: " + aOld.hashCode());
        Logger.INFO("Added Recipe with hash: " + aNew.hashCode());
    }

    private static void removeOldHighTierCasingRecipes() {

        Logger.INFO("Trying to appropriately retier GT Machine Hulls/Casings from LuV+");
        final Object aHardCasingsTest = StaticFields59.getFieldFromGregtechProxy("mHardMachineCasings");

        boolean aHardCasings = aHardCasingsTest != null ? (boolean) aHardCasingsTest : false;

        Logger.INFO("Are Hard casings/hulls enabled within GT? "
                + (aHardCasingsTest == null ? "Version does not support config option" : aHardCasings));

        // Static objects to save memory
        ItemStack aCasing_LUV = CI.machineCasing_LuV;
        ItemStack aCasing_ZPM = CI.machineCasing_ZPM;
        ItemStack aCasing_UV = CI.machineCasing_UV;
        ItemStack aCasing_MAX = CI.machineCasing_MAX;

        ItemStack aHull_LUV = CI.machineHull_LuV;
        ItemStack aHull_ZPM = CI.machineHull_ZPM;
        ItemStack aHull_UV = CI.machineHull_UV;
        ItemStack aHull_MAX = CI.machineHull_MAX;

        int aTier_LUV = 5;
        int aTier_ZPM = 6;
        int aTier_UV = 7;
        // int aTier_MAX = 8;

        ItemStack[] aCasings = new ItemStack[] {aCasing_LUV, aCasing_ZPM, aCasing_UV, aCasing_MAX};
        ItemStack[] aHulls = new ItemStack[] {aHull_LUV, aHull_ZPM, aHull_UV, aHull_MAX};

        // Remove Hand Crafting Recipes

        // Casings
        Logger.INFO("Removing shaped crafting for Casings.");
        RecipeUtils.removeRecipeByOutput(aCasing_LUV);
        RecipeUtils.removeRecipeByOutput(aCasing_ZPM);
        RecipeUtils.removeRecipeByOutput(aCasing_UV);
        // RecipeUtils.removeRecipeByOutput(aCasing_MAX);

        // Hulls
        Logger.INFO("Removing shaped crafting for Hulls.");
        RecipeUtils.removeRecipeByOutput(aHull_LUV);
        RecipeUtils.removeRecipeByOutput(aHull_ZPM);
        RecipeUtils.removeRecipeByOutput(aHull_UV);
        // RecipeUtils.removeRecipeByOutput(aHull_MAX);

        // Modify Assembler Recipes
        Logger.INFO(
                "Attempting to modify existing Assembly recipes for Casings & Hulls, this should provide best compatibility.");
        int aUpdateCount = 0;

        AutoMap<Pair<GT_Recipe, GT_Recipe>> aDataToModify = new AutoMap<Pair<GT_Recipe, GT_Recipe>>();

        Outer:
        for (final GT_Recipe r : GT_Recipe.GT_Recipe_Map.sAssemblerRecipes.mRecipeList) {

            if (r != null && r.mOutputs != null && r.mOutputs.length > 0) {

                GT_Recipe aOldRecipeCopy = r;
                GT_Recipe aNewRecipe = r.copy();

                // Casings
                Inner:
                for (ItemStack aCasingObject : aCasings) {
                    if (GT_Utility.areStacksEqual(aOldRecipeCopy.mOutputs[0], aCasingObject)) {
                        String aOutputName = ItemUtils.getItemName(aOldRecipeCopy.mOutputs[0]);
                        Logger.INFO("Attempting to Modify Assembly Recipe for " + aOutputName);
                        // Replace Chrome
                        if (GT_Utility.areStacksEqual(aOldRecipeCopy.mOutputs[0], aCasing_LUV)) {
                            aNewRecipe = replaceItemInRecipeWithAnother(
                                    aOldRecipeCopy,
                                    ItemUtils.getItemStackOfAmountFromOreDict("plateChrome", 1),
                                    ELEMENT.getInstance().SELENIUM.getPlate(1));
                            aDataToModify.put(new Pair<GT_Recipe, GT_Recipe>(r, aNewRecipe));
                            aUpdateCount++;
                            continue Outer;
                        }
                        // Replace Iridium
                        else if (GT_Utility.areStacksEqual(aOldRecipeCopy.mOutputs[0], aCasing_ZPM)) {
                            aNewRecipe = replaceItemInRecipeWithAnother(
                                    aOldRecipeCopy,
                                    ItemUtils.getItemStackOfAmountFromOreDict("plateIridium", 1),
                                    CI.getPlate(aTier_ZPM, 1));
                            aDataToModify.put(new Pair<GT_Recipe, GT_Recipe>(r, aNewRecipe));
                            aUpdateCount++;
                            continue Outer;
                        }
                        // Replace Osmium
                        else if (GT_Utility.areStacksEqual(aOldRecipeCopy.mOutputs[0], aCasing_UV)) {
                            aNewRecipe = replaceItemInRecipeWithAnother(
                                    aOldRecipeCopy,
                                    ItemUtils.getItemStackOfAmountFromOreDict("plateOsmium", 1),
                                    CI.getPlate(aTier_UV, 1));
                            aDataToModify.put(new Pair<GT_Recipe, GT_Recipe>(r, aNewRecipe));
                            aUpdateCount++;
                            continue Outer;
                        }
                        // else if (aOldRecipeCopy.mOutputs[0] == aCasing_LUV) {
                        //	aOldRecipeCopy = replaceItemInRecipeWithAnother(aOldRecipeCopy,
                        // ItemUtils.getItemStackOfAmountFromOreDict("plateChrome", 8), CI.getPlate(aTier_MAX, 8));
                        //  updateRecipeMap(aOldRecipeCopy, aNewRecipe, GT_Recipe.GT_Recipe_Map.sAssemblerRecipes);
                        // }
                        else {
                            continue Inner;
                        }
                    }
                }

                // Hulls
                Inner:
                for (ItemStack aHullObject : aHulls) {
                    if (GT_Utility.areStacksEqual(aOldRecipeCopy.mOutputs[0], aHullObject)) {
                        String aOutputName = ItemUtils.getItemName(aOldRecipeCopy.mOutputs[0]);
                        Logger.INFO("Attempting to Modify Assembly Recipe for " + aOutputName);
                        // Replace Chrome
                        if (GT_Utility.areStacksEqual(aOldRecipeCopy.mOutputs[0], aHull_LUV)) {
                            aNewRecipe = replaceItemInRecipeWithAnother(
                                    aOldRecipeCopy,
                                    ItemUtils.getItemStackOfAmountFromOreDict("plateChrome", 1),
                                    ELEMENT.getInstance().SELENIUM.getPlate(1));
                            aDataToModify.put(new Pair<GT_Recipe, GT_Recipe>(r, aNewRecipe));
                            aUpdateCount++;
                            continue Outer;
                        }
                        // Replace Iridium
                        else if (GT_Utility.areStacksEqual(aOldRecipeCopy.mOutputs[0], aHull_ZPM)) {
                            aNewRecipe = replaceItemInRecipeWithAnother(
                                    aOldRecipeCopy,
                                    ItemUtils.getItemStackOfAmountFromOreDict("plateIridium", 1),
                                    CI.getPlate(aTier_ZPM, 1));
                            aDataToModify.put(new Pair<GT_Recipe, GT_Recipe>(r, aNewRecipe));
                            aUpdateCount++;
                            continue Outer;
                        }
                        // Replace Osmium
                        else if (GT_Utility.areStacksEqual(aOldRecipeCopy.mOutputs[0], aHull_UV)) {
                            aNewRecipe = replaceItemInRecipeWithAnother(
                                    aOldRecipeCopy,
                                    ItemUtils.getItemStackOfAmountFromOreDict("plateOsmium", 1),
                                    CI.getPlate(aTier_UV, 1));
                            aDataToModify.put(new Pair<GT_Recipe, GT_Recipe>(r, aNewRecipe));
                            aUpdateCount++;
                            continue Outer;
                        }
                        // else if (aOldRecipeCopy.mOutputs[0] == aHull_LUV) {
                        //	aOldRecipeCopy = replaceItemInRecipeWithAnother(aOldRecipeCopy,
                        // ItemUtils.getItemStackOfAmountFromOreDict("plateChrome", 8), CI.getPlate(aTier_MAX, 8));
                        //  updateRecipeMap(aOldRecipeCopy, aNewRecipe, GT_Recipe.GT_Recipe_Map.sAssemblerRecipes);
                        // }
                        else {
                            continue Inner;
                        }
                    }
                }
            }
        }

        Logger.INFO("There is " + aUpdateCount + " recipes flagged for update.");

        if (aUpdateCount > 0) {
            for (Pair<GT_Recipe, GT_Recipe> g : aDataToModify) {
                updateRecipeMap(g.getKey(), g.getValue(), GT_Recipe.GT_Recipe_Map.sAssemblerRecipes);
            }
            Logger.INFO("Modified " + aUpdateCount + " recipes.");
        }

        Logger.INFO("Adding new Shaped recipes for Casings.");
        GT_ModHandler.addCraftingRecipe(ItemList.Casing_LuV.get(1), bits, new Object[] {
            "PPP", "PwP", "PPP", 'P', ELEMENT.getInstance().SELENIUM.getPlate(1)
        });
        GT_ModHandler.addCraftingRecipe(
                ItemList.Casing_ZPM.get(1), bits, new Object[] {"PPP", "PwP", "PPP", 'P', CI.getPlate(aTier_ZPM, 1)});
        GT_ModHandler.addCraftingRecipe(
                ItemList.Casing_UV.get(1), bits, new Object[] {"PPP", "PwP", "PPP", 'P', CI.getPlate(aTier_UV, 1)});
        // GT_ModHandler.addCraftingRecipe(ItemList.Casing_MAX.get(1), bits, new Object[]{"PPP", "PwP", "PPP", 'P',
        // OrePrefixes.plate.get(Materials.Neutronium)});

        if (!aHardCasings) {
            Logger.INFO("Adding new easy Shaped recipes for Hulls.");
            GT_ModHandler.addCraftingRecipe(
                    ItemList.Hull_LuV.get(1), RecipeBits.NOT_REMOVABLE | RecipeBits.BUFFERED, new Object[] {
                        "CMC", 'M', ItemList.Casing_LuV, 'C', OrePrefixes.cableGt01.get(Materials.VanadiumGallium)
                    });
            GT_ModHandler.addCraftingRecipe(
                    ItemList.Hull_ZPM.get(1),
                    RecipeBits.NOT_REMOVABLE | RecipeBits.BUFFERED,
                    new Object[] {"CMC", 'M', ItemList.Casing_ZPM, 'C', OrePrefixes.cableGt01.get(Materials.Naquadah)});
            GT_ModHandler.addCraftingRecipe(
                    ItemList.Hull_UV.get(1), RecipeBits.NOT_REMOVABLE | RecipeBits.BUFFERED, new Object[] {
                        "CMC", 'M', ItemList.Casing_UV, 'C', OrePrefixes.wireGt04.get(Materials.NaquadahAlloy)
                    });
            /*GT_ModHandler.addCraftingRecipe(ItemList.Hull_MAX.get(1),
            RecipeBits.NOT_REMOVABLE | RecipeBits.BUFFERED, new Object[]{"CMC", 'M', ItemList.Casing_MAX, 'C',
                    OrePrefixes.wireGt01.get(Materials.Superconductor)});*/
        } else {

            Materials aPolytetrafluoroethylene = MaterialUtils.getMaterial("Polytetrafluoroethylene", "Plastic");

            Logger.INFO("Adding new hard Shaped recipes for Hulls.");
            GT_ModHandler.addCraftingRecipe(
                    ItemList.Hull_LuV.get(1), RecipeBits.NOT_REMOVABLE | RecipeBits.BUFFERED, new Object[] {
                        "PHP",
                        "CMC",
                        'M',
                        ItemList.Casing_LuV,
                        'C',
                        OrePrefixes.cableGt01.get(Materials.VanadiumGallium),
                        'H',
                        ELEMENT.getInstance().SELENIUM.getPlate(1),
                        'P',
                        OrePrefixes.plate.get(Materials.Plastic)
                    });
            GT_ModHandler.addCraftingRecipe(
                    ItemList.Hull_ZPM.get(1), RecipeBits.NOT_REMOVABLE | RecipeBits.BUFFERED, new Object[] {
                        "PHP",
                        "CMC",
                        'M',
                        ItemList.Casing_ZPM,
                        'C',
                        OrePrefixes.cableGt01.get(Materials.Naquadah),
                        'H',
                        CI.getPlate(aTier_ZPM, 1),
                        'P',
                        OrePrefixes.plate.get(aPolytetrafluoroethylene)
                    });
            GT_ModHandler.addCraftingRecipe(
                    ItemList.Hull_UV.get(1), RecipeBits.NOT_REMOVABLE | RecipeBits.BUFFERED, new Object[] {
                        "PHP",
                        "CMC",
                        'M',
                        ItemList.Casing_UV,
                        'C',
                        OrePrefixes.wireGt04.get(Materials.NaquadahAlloy),
                        'H',
                        CI.getPlate(aTier_UV, 1),
                        'P',
                        OrePrefixes.plate.get(aPolytetrafluoroethylene)
                    });
            /*GT_ModHandler.addCraftingRecipe(ItemList.Hull_MAX.get(1),
            RecipeBits.NOT_REMOVABLE | RecipeBits.BUFFERED,
            new Object[]{"PHP", "CMC", 'M', ItemList.Casing_MAX, 'C',
                    OrePrefixes.wireGt01.get(Materials.Superconductor), 'H',
                    OrePrefixes.plate.get(Materials.Neutronium), 'P',
                    OrePrefixes.plate.get(Materials.Polytetrafluoroethylene)});*/
        }

        // Casings

        /*GT_Values.RA.addAssemblerRecipe(GT_OreDictUnificator.get(OrePrefixes.plate, Materials.Chrome, 8L),
        		ItemList.Circuit_Integrated.getWithDamage(0L, 8L, new Object[0]),
        		ItemList.Casing_LuV.get(1), 50, 16);
        GT_Values.RA.addAssemblerRecipe(GT_OreDictUnificator.get(OrePrefixes.plate, Materials.Iridium, 8L),
        		ItemList.Circuit_Integrated.getWithDamage(0L, 8L, new Object[0]),
        		ItemList.Casing_ZPM.get(1), 50, 16);
        GT_Values.RA.addAssemblerRecipe(GT_OreDictUnificator.get(OrePrefixes.plate, Materials.Osmium, 8L),
        		ItemList.Circuit_Integrated.getWithDamage(0L, 8L, new Object[0]),
        		ItemList.Casing_UV.get(1), 50, 16);
        GT_Values.RA.addAssemblerRecipe(GT_OreDictUnificator.get(OrePrefixes.plate, Materials.Neutronium, 8L),
        		ItemList.Circuit_Integrated.getWithDamage(0L, 8L, new Object[0]),
        		ItemList.Casing_MAX.get(1), 50, 16);	*/

        // Hulls

        // Hard Hulls
        /*GT_Values.RA.addAssemblerRecipe(
        		GT_OreDictUnificator.get(OrePrefixes.cableGt01, Materials.VanadiumGallium, 2L),
        		ItemList.Casing_LuV.get(1), Materials.Plastic.getMolten(288L),
        		ItemList.Hull_LuV.get(1), 50, 16);
        GT_Values.RA.addAssemblerRecipe(GT_OreDictUnificator.get(OrePrefixes.cableGt01, Materials.Naquadah, 2L),
        		ItemList.Casing_ZPM.get(1), Materials.Polytetrafluoroethylene.getMolten(288L),
        		ItemList.Hull_ZPM.get(1), 50, 16);
        GT_Values.RA.addAssemblerRecipe(GT_OreDictUnificator.get(OrePrefixes.wireGt04, Materials.NaquadahAlloy, 2L),
        		ItemList.Casing_UV.get(1), Materials.Polytetrafluoroethylene.getMolten(288L),
        		ItemList.Hull_UV.get(1), 50, 16);
        GT_Values.RA.addAssemblerRecipe(
        		GT_OreDictUnificator.get(OrePrefixes.wireGt01, Materials.Superconductor, 2L),
        		ItemList.Casing_MAX.get(1), Materials.Polytetrafluoroethylene.getMolten(288L),
        		ItemList.Hull_MAX.get(1), 50, 16);*/

        // Easy Hulls
        /*GT_Values.RA.addAssemblerRecipe(
        		GT_OreDictUnificator.get(OrePrefixes.cableGt01, Materials.VanadiumGallium, 2L),
        		ItemList.Casing_LuV.get(1), ItemList.Hull_LuV.get(1), 50, 16);
        GT_Values.RA.addAssemblerRecipe(GT_OreDictUnificator.get(OrePrefixes.cableGt01, Materials.Naquadah, 2L),
        		ItemList.Casing_ZPM.get(1), ItemList.Hull_ZPM.get(1), 50, 16);
        GT_Values.RA.addAssemblerRecipe(GT_OreDictUnificator.get(OrePrefixes.wireGt04, Materials.NaquadahAlloy, 2L),
        		ItemList.Casing_UV.get(1), ItemList.Hull_UV.get(1), 50, 16);
        GT_Values.RA.addAssemblerRecipe(
        		GT_OreDictUnificator.get(OrePrefixes.wireGt01, Materials.Superconductor, 2L),
        		ItemList.Casing_MAX.get(1), ItemList.Hull_MAX.get(1), 50, 16);*/
    }

    private static int removeCrudeTurbineRotors() {
        int aRemoved = 0;
        int CUT = CORE.turbineCutoffBase;
        Item aU;
        Collection<GT_Recipe> aAssRecipes = GT_Recipe.GT_Recipe_Map.sAssemblerRecipes.mRecipeList;
        // 170, 172, 174, 176
        if (aAssRecipes.size() > 0 && (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK || CORE.GTNH)) {
            recipe:
            for (GT_Recipe aG : aAssRecipes) {
                if (aG.mOutputs != null && aG.mOutputs.length > 0) {
                    outputs:
                    for (ItemStack aI : aG.mOutputs) {
                        if (aI == null) {
                            continue;
                        }
                        aU = aI.getItem();
                        if (aU == null) {
                            continue;
                        }
                        if (aU instanceof GT_MetaGenerated_Tool_01) {
                            int aMeta = aI.getItemDamage();
                            // Logger.INFO("Found assembler recipe outputting a GT Tool with a meta value of "+aMeta);
                            if (aMeta >= 170 && aMeta <= 176) {
                                // Found a Turbine
                                int aCutoff = aMeta == 170
                                        ? CUT
                                        : (aMeta == 172 ? CUT * 2 : (aMeta == 174 ? CUT * 3 : CUT * 4));
                                String aType = aMeta == 170
                                        ? "Small "
                                        : (aMeta == 172 ? "" : (aMeta == 174 ? "Large " : "Huge "));
                                Materials aMainMaterial = GT_MetaGenerated_Tool.getPrimaryMaterial(aI);
                                Materials aSecondaryMaterial = GT_MetaGenerated_Tool.getSecondaryMaterial(aI);
                                long rotorDurabilityMax = GT_MetaGenerated_Tool.getToolMaxDamage(aI);
                                // Logger.INFO("Found "+aType+"Turbine made out of "+getMaterialName(aMainMaterial)+",
                                // using "+getMaterialName(aSecondaryMaterial));
                                if (rotorDurabilityMax < aCutoff) {
                                    Logger.WARNING("[Turbine Cleanup] " + getMaterialName(aMainMaterial) + " " + aType
                                            + "Turbines have " + rotorDurabilityMax
                                            + ", which is below the cutoff durability of " + aCutoff + ", disabling.");
                                    aG.mEnabled = false;
                                    aG.mHidden = true;
                                    aG.mCanBeBuffered = false;
                                    aRemoved++;
                                } else {
                                    break outputs;
                                }

                            } else {
                                continue outputs;
                            }
                        } else {
                            continue outputs;
                        }
                    }
                } else {
                    continue recipe;
                }
            }
        }

        Logger.INFO("Removed " + aRemoved + " useless Turbines.");

        return aRemoved;
    }

    /**
     * Should clean out any invalid Assembly Line recipes, if the map actually exists.
     * Prevents NPE's being thrown by GT's AL handler. (Fucking Annoying)
     * @return - Amount of Recipes removed, which were invalid in some way.
     */
    private static int cleanAssemblyLineRecipeMap() {
        GT_Recipe_Map g = StaticFields59.sAssemblylineVisualRecipes;
        if (g == null) {
            return 0;
        } else {
            AutoMap<GT_Recipe> aNewMap = new AutoMap<GT_Recipe>();
            AutoMap<GT_Recipe> aBadRecipeTempMap = new AutoMap<GT_Recipe>();
            for (GT_Recipe r : g.mRecipeList) {
                if (r != null) {
                    if (r.mOutputs == null || r.mOutputs.length == 0 || r.mOutputs[0] == null) {
                        aBadRecipeTempMap.put(r.copy());
                        continue;
                    } else {
                        aNewMap.put(r.copy());
                    }
                }
            }
            if (aNewMap.size() > 0) {
                g.mRecipeList.clear();
                for (GT_Recipe i : aNewMap) {
                    g.add(i);
                }
            }
            if (aBadRecipeTempMap.size() > 0) {
                Logger.INFO("Found " + aBadRecipeTempMap.size()
                        + " bad Assembly Line Recipes, attempting to dump all data about them.");
                Logger.INFO("This data should be given to the mod author for the recipe in question.");
                for (GT_Recipe i : aBadRecipeTempMap) {
                    if (i == null) {
                        Logger.INFO(
                                "Found NULL recipe. Impossible to determine who added this one. Please Report to Alkalus on Github.");
                    } else {
                        if (i.mOutputs == null || i.mOutputs.length == 0 || i.mOutputs[0] == null) {
                            Logger.INFO(
                                    "Found recipe with NULL output array, this will cause some issues. Attempting to determine other info about recipe.");
                            if (i.mInputs != null && i.mInputs.length > 0) {
                                Logger.INFO("Inputs: " + ItemUtils.getArrayStackNames(i.mInputs));
                            } else {
                                Logger.INFO("Recipe had no valid inputs.");
                            }
                            Logger.INFO("Time: " + i.mDuration);
                            Logger.INFO("EU/T: " + i.mEUt);
                            Logger.INFO("Special: " + i.mSpecialValue);
                        } else {
                            Logger.INFO("Found bad recipe, Attempting to determine other info.");
                            if (i.mInputs != null && i.mInputs.length > 0) {
                                Logger.INFO("Inputs: " + ItemUtils.getArrayStackNames(i.mInputs));
                            } else {
                                Logger.INFO("Recipe had no valid inputs.");
                            }
                            if (i.mOutputs != null && i.mOutputs.length > 0) {
                                Logger.INFO("Outputs: " + ItemUtils.getArrayStackNames(i.mOutputs));
                            } else {
                                Logger.INFO("Recipe had no valid outputs.");
                            }
                            Logger.INFO("Time: " + i.mDuration);
                            Logger.INFO("EU/T: " + i.mEUt);
                            Logger.INFO("Special: " + i.mSpecialValue);
                        }
                    }
                }
            } else {
                Logger.INFO("No bad Assembly Line recipes found, this is great news!");
            }
            return aBadRecipeTempMap.size();
        }
    }
}