aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/util/FishPondFakeRecipe.java
blob: 57e210a8f2a5a6c11992639b5d75b4070ec7ac51 (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
package gregtech.api.util;

import java.util.ArrayList;

import net.minecraft.item.ItemStack;
import net.minecraft.util.WeightedRandomFishable;
import net.minecraftforge.common.FishingHooks;
import net.minecraftforge.fluids.FluidStack;

import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.core.recipe.common.CI;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;

public class FishPondFakeRecipe {

    public static ArrayList<WeightedRandomFishable> fish = new ArrayList<WeightedRandomFishable>();
    public static ArrayList<WeightedRandomFishable> junk = new ArrayList<WeightedRandomFishable>();
    public static ArrayList<WeightedRandomFishable> treasure = new ArrayList<WeightedRandomFishable>();

    @SuppressWarnings("unchecked")
    public static boolean generateFishPondRecipes() {

        try {
            fish = (ArrayList<WeightedRandomFishable>) ReflectionUtils.getField(FishingHooks.class, "fish").get(null);
            junk = (ArrayList<WeightedRandomFishable>) ReflectionUtils.getField(FishingHooks.class, "junk").get(null);
            treasure = (ArrayList<WeightedRandomFishable>) ReflectionUtils.getField(FishingHooks.class, "treasure")
                    .get(null);
        } catch (IllegalArgumentException | IllegalAccessException e) {
            Logger.INFO("Error generating Fish Pond Recipes. [1]");
            e.printStackTrace();
        }

        AutoMap<ArrayList<WeightedRandomFishable>> mega = new AutoMap<ArrayList<WeightedRandomFishable>>();
        mega.put(fish);
        mega.put(junk);
        mega.put(treasure);

        int mType = 14;
        for (ArrayList<WeightedRandomFishable> f : mega.values()) {
            for (int e = 0; e < f.size(); e++) {
                if (f.get(e) != null) {
                    WeightedRandomFishable u = f.get(e);
                    try {
                        ItemStack t = (ItemStack) ReflectionUtils
                                .getField(WeightedRandomFishable.class, "field_150711_b").get(u);
                        addNewFishPondLoot(mType, new ItemStack[] { t }, new int[] { 10000 });
                    } catch (IllegalArgumentException | IllegalAccessException e1) {
                        Logger.INFO("Error generating Fish Pond Recipes. [2]");
                        e1.printStackTrace();
                    }
                }
            }
            mType++;
        }

        return true;
    }

    public static void addNewFishPondLoot(int circuit, ItemStack[] outputItems, int[] chances) {
        GTPP_Recipe x = new GTPP_Recipe(
                true,
                new ItemStack[] { CI.getNumberedCircuit(circuit) },
                outputItems,
                null,
                chances,
                new FluidStack[] { null },
                new FluidStack[] { null },
                100, // 1 Tick
                0, // No Eu produced
                0);
        Logger.INFO("Fishing [" + circuit + "]: " + ItemUtils.getArrayStackNames(outputItems));
        GTPP_Recipe.GTPP_Recipe_Map.sFishPondRecipes.addRecipe(x, false, false, false);
    }
}