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

import static gregtech.api.util.GTRecipeBuilder.SECONDS;
import static gtPlusPlus.api.recipe.GTPPRecipeMaps.fishPondRecipes;

import java.util.ArrayList;

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

import gregtech.api.enums.GTValues;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;

public class FishPondFakeRecipe {

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

    @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<>();
        mega.put(fish);
        mega.put(junk);
        mega.put(treasure);

        int mType = 14;
        for (ArrayList<WeightedRandomFishable> f : mega.values()) {
            for (WeightedRandomFishable weightedRandomFishable : f) {
                if (weightedRandomFishable != null) {
                    WeightedRandomFishable u = weightedRandomFishable;
                    try {
                        ItemStack t = (ItemStack) ReflectionUtils
                            .getField(WeightedRandomFishable.class, "field_150711_b")
                            .get(u);
                        GTValues.RA.stdBuilder()
                            .itemInputs(GTUtility.getIntegratedCircuit(mType))
                            .itemOutputs(t)
                            .duration(5 * SECONDS)
                            .eut(0)
                            .ignoreCollision()
                            .addTo(fishPondRecipes);
                        Logger.INFO("Fishing [" + mType + "]: " + ItemUtils.getArrayStackNames(new ItemStack[] { t }));
                    } catch (IllegalArgumentException | IllegalAccessException e1) {
                        Logger.INFO("Error generating Fish Pond Recipes. [2]");
                        e1.printStackTrace();
                    }
                }
            }
            mType++;
        }

        return true;
    }
}