aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/core/material/MaterialGenerator.java
blob: f21c40411f12e66eb1304dafbe163e2188c032cd (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
package gtPlusPlus.core.material;

import static gtPlusPlus.api.recipe.GTPPRecipeMaps.chemicalDehydratorRecipes;

import java.util.ArrayList;
import java.util.Set;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

import gregtech.api.enums.GTValues;
import gregtech.api.util.GTUtility;
import gtPlusPlus.api.interfaces.RunnableWithInfo;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.block.base.BasicBlock.BlockTypes;
import gtPlusPlus.core.block.base.BlockBaseModular;
import gtPlusPlus.core.block.base.BlockBaseOre;
import gtPlusPlus.core.item.base.BaseItemComponent;
import gtPlusPlus.core.item.base.BaseItemComponent.ComponentTypes;
import gtPlusPlus.core.item.base.bolts.BaseItemBolt;
import gtPlusPlus.core.item.base.dusts.BaseItemDust;
import gtPlusPlus.core.item.base.dusts.BaseItemDust.DustState;
import gtPlusPlus.core.item.base.gears.BaseItemGear;
import gtPlusPlus.core.item.base.ingots.BaseItemIngot;
import gtPlusPlus.core.item.base.ingots.BaseItemIngotHot;
import gtPlusPlus.core.item.base.nugget.BaseItemNugget;
import gtPlusPlus.core.item.base.ore.BaseItemCentrifugedCrushedOre;
import gtPlusPlus.core.item.base.ore.BaseItemCrushedOre;
import gtPlusPlus.core.item.base.ore.BaseItemImpureDust;
import gtPlusPlus.core.item.base.ore.BaseItemPurifiedCrushedOre;
import gtPlusPlus.core.item.base.ore.BaseItemPurifiedDust;
import gtPlusPlus.core.item.base.ore.BaseItemRawOre;
import gtPlusPlus.core.item.base.plates.BaseItemPlate;
import gtPlusPlus.core.item.base.plates.BaseItemPlateDense;
import gtPlusPlus.core.item.base.plates.BaseItemPlateDouble;
import gtPlusPlus.core.item.base.rings.BaseItemRing;
import gtPlusPlus.core.item.base.rods.BaseItemRod;
import gtPlusPlus.core.item.base.rods.BaseItemRodLong;
import gtPlusPlus.core.item.base.rotors.BaseItemRotor;
import gtPlusPlus.core.item.base.screws.BaseItemScrew;
import gtPlusPlus.core.material.nuclear.MaterialsFluorides;
import gtPlusPlus.core.material.state.MaterialState;
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.minecraft.FluidUtils;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGenAlloySmelter;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGenAssembler;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGenBlastSmelter;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGenDustGeneration;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGenExtruder;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGenFluidCanning;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGenFluids;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGenFluorite;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGenMaterialProcessing;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGenMetalRecipe;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGenOre;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGenPlasma;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGenPlates;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGenRecycling;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGenShapedCrafting;

public class MaterialGenerator {

    public static final ArrayList<Set<RunnableWithInfo<Material>>> mRecipeMapsToGenerate = new ArrayList<>();

    @SuppressWarnings("unused")
    private static volatile Item temp;

    @SuppressWarnings("unused")
    private static volatile Block tempBlock;

    @Deprecated
    public static boolean addFluidCannerRecipe(ItemStack aEmpty, ItemStack aFullContainer, FluidStack aFluidIn,
        FluidStack rFluidOut) {
        return addFluidCannerRecipe(aEmpty, aFullContainer, aFluidIn, rFluidOut, null, null);
    }

    @Deprecated
    public static boolean addFluidCannerRecipe(ItemStack aEmpty, ItemStack aFullContainer, FluidStack aFluidIn,
        FluidStack rFluidOut, Integer aTime, Integer aEu) {

        RecipeGenFluidCanning g = new RecipeGenFluidCanning(false, aEmpty, aFullContainer, aFluidIn, null, null, 0);
        return g != null && g.valid();
    }

    public static void generate(final Material matInfo) {
        generate(matInfo, true);
    }

    public static void generate(final Material matInfo, final boolean generateEverything) {
        generate(matInfo, generateEverything, true);
    }

    public static boolean generate(final Material matInfo, final boolean generateEverything,
        final boolean generateBlastSmelterRecipes) {
        try {
            final String unlocalizedName = matInfo.getUnlocalizedName();
            final String materialName = matInfo.getLocalizedName();
            final short[] C = matInfo.getRGBA();
            final int Colour = Utils.rgbtoHexValue(C[0], C[1], C[2]);
            final boolean hotIngot = matInfo.requiresBlastFurnace();
            int materialTier = matInfo.vTier; // TODO

            if ((materialTier > 10) || (materialTier <= 0)) {
                materialTier = 2;
            }

            int sRadiation = 0;
            if (ItemUtils.isRadioactive(materialName) || (matInfo.vRadiationLevel != 0)) {
                sRadiation = matInfo.vRadiationLevel;
            }

            if (matInfo.getState() == MaterialState.SOLID) {
                if (generateEverything) {
                    if (sRadiation >= 1) {
                        tempBlock = new BlockBaseModular(matInfo, BlockTypes.STANDARD);
                        temp = new BaseItemIngot(matInfo);

                        temp = new BaseItemDust(matInfo);
                        temp = new BaseItemNugget(matInfo);
                        temp = new BaseItemPlate(matInfo);
                        temp = new BaseItemRod(matInfo);
                        temp = new BaseItemRodLong(matInfo);
                    } else {
                        tempBlock = new BlockBaseModular(matInfo, BlockTypes.STANDARD);
                        tempBlock = new BlockBaseModular(matInfo, BlockTypes.FRAME);
                        temp = new BaseItemIngot(matInfo);
                        if (hotIngot) {
                            temp = new BaseItemIngotHot(matInfo);
                        }
                        temp = new BaseItemDust(matInfo);
                        temp = new BaseItemNugget(matInfo);
                        temp = new BaseItemPlate(matInfo);
                        temp = new BaseItemPlateDouble(matInfo);
                        temp = new BaseItemBolt(matInfo);
                        temp = new BaseItemRod(matInfo);
                        temp = new BaseItemRodLong(matInfo);
                        temp = new BaseItemRing(matInfo);
                        temp = new BaseItemScrew(matInfo);
                        temp = new BaseItemRotor(matInfo);
                        temp = new BaseItemGear(matInfo);
                        temp = new BaseItemPlateDense(matInfo);
                    }
                } else {
                    tempBlock = new BlockBaseModular(matInfo, BlockTypes.STANDARD);

                    temp = new BaseItemIngot(matInfo);
                    temp = new BaseItemDust(matInfo);
                    temp = new BaseItemNugget(matInfo);
                    temp = new BaseItemPlate(matInfo);
                    temp = new BaseItemPlateDouble(matInfo);
                }
            } else if (matInfo.getState() == MaterialState.LIQUID) {
                if (generateEverything) {
                    tempBlock = new BlockBaseModular(matInfo, BlockTypes.STANDARD);
                }
                temp = new BaseItemIngot(matInfo);
                temp = new BaseItemDust(matInfo);
                temp = new BaseItemNugget(matInfo);
                temp = new BaseItemPlate(matInfo);
                temp = new BaseItemPlateDouble(matInfo);
            } else if (matInfo.getState() == MaterialState.GAS) {
                temp = new BaseItemDust(matInfo);
                FluidUtils.generateGas(unlocalizedName, materialName, matInfo.getMeltingPointK(), C, true);
            } else if (matInfo.getState() == MaterialState.PURE_GAS) {
                FluidUtils.generateGas(unlocalizedName, materialName, matInfo.getMeltingPointK(), C, true);
                return true;
            } else if (matInfo.getState() == MaterialState.PURE_LIQUID) {
                FluidUtils.generateFluidNoPrefix(unlocalizedName, materialName, matInfo.getMeltingPointK(), C);
                return true;
            } else if (matInfo.getState() == MaterialState.ORE) {

            }

            // Add A jillion Recipes - old code
            new RecipeGenAlloySmelter(matInfo);
            new RecipeGenAssembler(matInfo);
            if (generateBlastSmelterRecipes) {
                new RecipeGenBlastSmelter(matInfo);
            }
            new RecipeGenMetalRecipe(matInfo);
            new RecipeGenExtruder(matInfo);
            new RecipeGenFluids(matInfo);
            new RecipeGenPlates(matInfo);
            new RecipeGenShapedCrafting(matInfo);
            new RecipeGenMaterialProcessing(matInfo);

            new RecipeGenDustGeneration(matInfo);
            new RecipeGenRecycling(matInfo);
            new RecipeGenPlasma(matInfo);

            return true;

        } catch (final Throwable t) {
            Logger.MATERIALS(matInfo.getLocalizedName() + " failed to generate.");
            return false;
        }
    }

    public static void generateDusts(final Material matInfo) {
        final String unlocalizedName = matInfo.getUnlocalizedName();
        final String materialName = matInfo.getLocalizedName();
        final short[] C = matInfo.getRGBA();
        final int Colour = Utils.rgbtoHexValue(C[0], C[1], C[2]);
        int materialTier = matInfo.vTier; // TODO

        if ((materialTier > 10) || (materialTier <= 0)) {
            materialTier = 2;
        }

        int sRadiation = 0;
        if (ItemUtils.isRadioactive(materialName) || (matInfo.vRadiationLevel != 0)) {
            sRadiation = matInfo.vRadiationLevel;
        }

        if (matInfo.getState() == MaterialState.SOLID) {
            temp = new BaseItemDust(matInfo);
        }

        // Add A jillion Recipes - old code
        try {
            RecipeGenDustGeneration.addMixerRecipe_Standalone(matInfo);
            new RecipeGenFluids(matInfo);
            new RecipeGenMaterialProcessing(matInfo);
        } catch (Throwable t) {
            Logger.MATERIALS("Failed to generate some recipes for " + materialName);
            Logger.ERROR("Failed to generate some recipes for " + materialName);
            t.printStackTrace();
        }
        // RecipeGen_Recycling.generateRecipes(matInfo);
    }

    public static void generateNuclearMaterial(final Material matInfo) {
        generateNuclearMaterial(matInfo, true);
    }

    public static void generateNuclearDusts(final Material matInfo) {
        generateNuclearDusts(matInfo, true);
    }

    public static void generateNuclearDusts(final Material matInfo, boolean generateDehydratorRecipe) {
        generateNuclearMaterial(matInfo, false, true, false, false, true);
        if (generateDehydratorRecipe && matInfo.getFluid() != null && matInfo.getDust(0) != null) {
            GTValues.RA.stdBuilder()
                .itemInputs(GTUtility.getIntegratedCircuit(20))
                .itemOutputs(matInfo.getDust(1))
                .fluidInputs(matInfo.getFluidStack(144))
                .eut(matInfo.vVoltageMultiplier)
                .duration(10 * (matInfo.vVoltageMultiplier / 5))
                .addTo(chemicalDehydratorRecipes);
        } else {
            Logger.INFO(
                "Nuclear Dehydrator: Did not generate recipe for " + matInfo.getLocalizedName()
                    + " | Null Fluid? "
                    + (matInfo.getFluid() == null)
                    + " | Null Dust? "
                    + (matInfo.getDust(0) == null));
        }
    }

    public static void generateNuclearMaterial(final Material matInfo, final boolean generatePlates) {
        generateNuclearMaterial(matInfo, true, true, true, generatePlates, true);
    }

    public static void generateNuclearMaterial(final Material matInfo, final boolean generateBlock,
        final boolean generateDusts, final boolean generateIngot, final boolean generatePlates,
        final boolean disableOptionalRecipes) {
        try {

            if (generateBlock) {
                tempBlock = new BlockBaseModular(matInfo, BlockTypes.STANDARD);
            }
            if (generateDusts) {
                temp = new BaseItemDust(matInfo);
            }
            if (generateIngot) {
                temp = new BaseItemIngot(matInfo);
                temp = new BaseItemNugget(matInfo);
            }

            if (generatePlates) {
                temp = new BaseItemPlate(matInfo);
                temp = new BaseItemPlateDouble(matInfo);
                new RecipeGenPlates(matInfo);
                new RecipeGenExtruder(matInfo);
                new RecipeGenAssembler(matInfo);
            }

            if (!disableOptionalRecipes) {
                new RecipeGenShapedCrafting(matInfo);
                new RecipeGenMaterialProcessing(matInfo);
                new RecipeGenRecycling(matInfo);
            }

            new RecipeGenFluids(matInfo);
            new RecipeGenMetalRecipe(matInfo);
            new RecipeGenDustGeneration(matInfo, disableOptionalRecipes);
            new RecipeGenPlasma(matInfo);

        } catch (final Throwable t) {
            Logger.MATERIALS(matInfo.getLocalizedName() + " failed to generate.");
        }
    }

    public static void generateOreMaterial(final Material matInfo) {
        generateOreMaterial(matInfo, true, true, true, matInfo.getRGBA());
    }

    @SuppressWarnings("unused")
    public static void generateOreMaterial(final Material matInfo, boolean generateOre, boolean generateDust,
        boolean generateSmallTinyDusts, short[] customRGB) {
        try {

            if (matInfo == null) {
                Logger.DEBUG_MATERIALS("Invalid Material while constructing null material.");
                return;
            }

            final String unlocalizedName = matInfo.getUnlocalizedName();
            final String materialName = matInfo.getLocalizedName();
            final Integer Colour = Utils.rgbtoHexValue(customRGB[0], customRGB[1], customRGB[2]);

            if (Colour == null) {
                Logger.DEBUG_MATERIALS("Invalid Material while constructing " + materialName + ".");
                return;
            }

            int sRadiation = 0;
            if (matInfo.vRadiationLevel > 0) {
                sRadiation = matInfo.vRadiationLevel;
            }

            if (generateOre) {
                tempBlock = new BlockBaseOre(matInfo, BlockTypes.ORE);
            }

            DustState aState = new DustState(generateDust, generateSmallTinyDusts, generateSmallTinyDusts);

            if (!aState.generatesDust()) {
                if (aState.generatesSmallDust()) {
                    temp = new BaseItemComponent(matInfo, ComponentTypes.DUSTSMALL);
                }
                if (aState.generatesTinyDust()) {
                    temp = new BaseItemComponent(matInfo, ComponentTypes.DUSTTINY);
                }
            } else {
                temp = new BaseItemDust(aState, matInfo);
            }

            temp = new BaseItemCrushedOre(matInfo);
            temp = new BaseItemCentrifugedCrushedOre(matInfo);
            temp = new BaseItemPurifiedCrushedOre(matInfo);
            temp = new BaseItemImpureDust(matInfo);
            temp = new BaseItemPurifiedDust(matInfo);
            temp = new BaseItemRawOre(matInfo);

            Logger.MATERIALS(
                "Generated all ore components for " + matInfo.getLocalizedName()
                    + ", now generating processing recipes.");

            if (matInfo == MaterialsFluorides.FLUORITE) {
                new RecipeGenFluorite(matInfo);
            } else {
                new RecipeGenOre(matInfo);
            }

        } catch (final Throwable t) {
            Logger.MATERIALS(
                "[Error] " + (matInfo != null ? matInfo.getLocalizedName() : "Null Material") + " failed to generate.");
            t.printStackTrace();
        }
    }

    public static boolean generateOreMaterialWithAllExcessComponents(final Material matInfo) {
        try {
            if (matInfo == null) {
                Logger.DEBUG_MATERIALS("Invalid Material while constructing null material.");
                return false;
            }
            final short[] C = matInfo.getRGBA();
            final Integer Colour = Utils.rgbtoHexValue(C[0], C[1], C[2]);

            tempBlock = new BlockBaseOre(matInfo, BlockTypes.ORE);
            tempBlock = new BlockBaseModular(matInfo, BlockTypes.STANDARD);
            temp = new BaseItemIngot(matInfo);
            temp = new BaseItemDust(matInfo);
            temp = new BaseItemNugget(matInfo);
            temp = new BaseItemPlate(matInfo);
            temp = new BaseItemPlateDouble(matInfo);

            temp = new BaseItemCrushedOre(matInfo);
            temp = new BaseItemCentrifugedCrushedOre(matInfo);
            temp = new BaseItemPurifiedCrushedOre(matInfo);
            temp = new BaseItemImpureDust(matInfo);
            temp = new BaseItemPurifiedDust(matInfo);
            temp = new BaseItemRawOre(matInfo);

            Logger.MATERIALS(
                "Generated all ore & base components for " + matInfo.getLocalizedName()
                    + ", now generating processing recipes.");

            new RecipeGenOre(matInfo, true);
            new RecipeGenAlloySmelter(matInfo);
            new RecipeGenAssembler(matInfo);
            new RecipeGenBlastSmelter(matInfo);
            new RecipeGenMetalRecipe(matInfo);
            new RecipeGenExtruder(matInfo);
            new RecipeGenFluids(matInfo);
            new RecipeGenPlates(matInfo);
            new RecipeGenShapedCrafting(matInfo);
            new RecipeGenMaterialProcessing(matInfo);
            new RecipeGenDustGeneration(matInfo);
            new RecipeGenRecycling(matInfo);
            new RecipeGenPlasma(matInfo);
            return true;
        } catch (final Throwable t) {
            Logger.MATERIALS(matInfo.getLocalizedName() + " failed to generate.");
            t.printStackTrace();
            return false;
        }
    }
}