aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/xmod/gregtech/loaders/recipe/RecipeLoaderAlgaeFarm.java
blob: d5fe3011738229fc59929d4bfd6efb76f3b0f43f (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
package gtPlusPlus.xmod.gregtech.loaders.recipe;

import java.util.ArrayList;
import java.util.HashMap;

import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

import gregtech.api.enums.GTValues;
import gregtech.api.util.GTRecipe;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.WeightedCollection;
import gtPlusPlus.core.item.chemistry.AgriculturalChem;
import gtPlusPlus.core.util.math.MathUtils;
import gtPlusPlus.core.util.minecraft.ItemUtils;

public class RecipeLoaderAlgaeFarm {

    private static final HashMap<Integer, ArrayList<GTRecipe>> mRecipeCache = new HashMap<>();
    private static final HashMap<Integer, ArrayList<GTRecipe>> mRecipeCompostCache = new HashMap<>();

    public static void generateRecipes() {
        for (int i = 0; i < 15; i++) {
            getTieredRecipeFromCache(i, false);
        }
        for (int i = 0; i < 15; i++) {
            getTieredRecipeFromCache(i, true);
        }
    }

    public static GTRecipe getTieredRecipeFromCache(int aTier, boolean aCompost) {
        HashMap<Integer, ArrayList<GTRecipe>> aMap = aCompost ? mRecipeCompostCache : mRecipeCache;
        String aComp = aCompost ? "(Compost)" : "";

        ArrayList<GTRecipe> aTemp = aMap.get(aTier);
        if (aTemp == null || aTemp.isEmpty()) {
            aTemp = new ArrayList<>();
            aMap.put(aTier, aTemp);
            Logger.INFO("Tier " + aTier + aComp + " had no recipes, initialising new map.");
        }
        if (aTemp.size() < 500) {
            Logger
                .INFO("Tier " + aTier + aComp + " has less than 500 recipes, generating " + (500 - aTemp.size()) + ".");
            for (int i = aTemp.size(); i < 500; i++) {
                aTemp.add(generateBaseRecipe(aCompost, aTier));
            }
        }
        int aIndex = MathUtils.randInt(0, aTemp.isEmpty() ? 1 : aTemp.size());
        Logger.INFO("Using recipe with index of " + aIndex + ". " + aComp);
        return aTemp.get(aIndex);
    }

    public static int compostForTier(int aTier) {
        return aTier > 1 ? (int) Math.min(64, Math.pow(2, aTier - 1)) : 1;
    }

    private static GTRecipe generateBaseRecipe(boolean aUsingCompost, int aTier) {

        // Type Safety
        if (aTier < 0) {
            return null;
        }

        WeightedCollection<Float> aOutputTimeMulti = new WeightedCollection<>();
        for (int i = 100; i > 0; i--) {
            float aValue = 0;
            if (i < 10) {
                aValue = 3f;
            } else if (i < 20) {
                aValue = 2f;
            } else {
                aValue = 1f;
            }
            aOutputTimeMulti.put(i, aValue);
        }

        final int[] aDurations = new int[] { 2000, 1800, 1600, 1400, 1200, 1000, 512, 256, 128, 64, 32, 16, 8, 4, 2,
            1 };

        ItemStack[] aInputs = new ItemStack[] {};

        if (aUsingCompost) {
            // Make it use 4 compost per tier if we have some available
            // Compost consumption maxes out at 1 stack per cycle
            ItemStack aCompost = ItemUtils.getSimpleStack(AgriculturalChem.mCompost, compostForTier(aTier));
            aInputs = new ItemStack[] { aCompost };
            // Boost Tier by one if using compost so it gets a speed boost
            aTier++;
        }

        // We set these elsewhere
        ItemStack[] aOutputs = getOutputsForTier(aTier);

        GTRecipe tRecipe = new GTRecipe(
            false,
            aInputs,
            aOutputs,
            (Object) null,
            new int[] {},
            new FluidStack[] { GTValues.NF },
            new FluidStack[] { GTValues.NF },
            (int) (aDurations[aTier] * aOutputTimeMulti.get() / 2), // Time
            0,
            0);

        tRecipe.mSpecialValue = tRecipe.hashCode();

        return tRecipe;
    }

    private static ItemStack[] getOutputsForTier(int aTier) {
        ArrayList<ItemStack> aOutputMap = new ArrayList<>();

        // Add loot relevant to tier and also add any from lower tiers.

        if (aTier >= 0) {
            aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mAlgaeBiosmass, 2));
            aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mAlgaeBiosmass, 4));
            if (MathUtils.randInt(0, 10) > 9) {
                aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, 2));
            }
        }

        if (aTier >= 1) {
            aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mAlgaeBiosmass, 4));
            aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, 2));
            if (MathUtils.randInt(0, 10) > 9) {
                aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, 4));
            }
        }
        if (aTier >= 2) {
            aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, 2));
            aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, 3));
            if (MathUtils.randInt(0, 10) > 9) {
                aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, 8));
            }
        }
        if (aTier >= 3) {
            aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, 4));
            aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, 1));
            if (MathUtils.randInt(0, 10) > 9) {
                aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, 4));
            }
        }
        if (aTier >= 4) {
            aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, 2));
            aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, 3));
            if (MathUtils.randInt(0, 10) > 9) {
                aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mGoldenBrownAlgaeBiosmass, 4));
            }
        }
        if (aTier >= 5) {
            aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, 4));
            aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mGoldenBrownAlgaeBiosmass, 2));
            if (MathUtils.randInt(0, 10) > 9) {
                aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mRedAlgaeBiosmass, 4));
            }
        }
        // Tier 6 is Highest for outputs
        if (aTier >= 6) {
            aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mGoldenBrownAlgaeBiosmass, 4));
            aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mRedAlgaeBiosmass, 2));
            if (MathUtils.randInt(0, 10) > 9) {
                aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mRedAlgaeBiosmass, 8));
            }
        }

        // Iterate a special loop at higher tiers to provide more Red/Gold Algae.
        for (int i2 = 0; i2 < 20; i2++) {
            if (aTier >= (6 + i2)) {
                int aMulti = i2 + 1;
                aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, aMulti * 4));
                aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, aMulti * 3));
                aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mGoldenBrownAlgaeBiosmass, aMulti * 2));
                aOutputMap.add(ItemUtils.getSimpleStack(AgriculturalChem.mRedAlgaeBiosmass, aMulti));
            } else {
                i2 = 20;
            }
        }

        // Map the AutoMap contents to an Itemstack Array.
        ItemStack[] aOutputs = new ItemStack[aOutputMap.size()];
        for (int i = 0; i < aOutputMap.size(); i++) {
            aOutputs[i] = aOutputMap.get(i);
        }

        // Return filled ItemStack Array.
        return aOutputs;
    }
}