aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pers/gwyog/gtneioreplugin/util/GT5OreSmallHelper.java
blob: a730b3d1484c0a84ca1ab7cdeeca4713630f0a41 (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
package pers.gwyog.gtneioreplugin.util;

import gregtech.api.GregTech_API;
import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.world.GT_Worldgen;
import gregtech.common.GT_Worldgen_GT_Ore_SmallPieces;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.minecraft.item.ItemStack;

public class GT5OreSmallHelper {
    private static final int SMALL_ORE_BASE_META = 16000;
    public static boolean restrictBiomeSupport = false;
    public static boolean gcBasicSupport = false;
    public static List<ItemStack> oreSmallList = new ArrayList<>();
    public static HashMap<String, OreSmallWrapper> mapOreSmallWrapper = new HashMap<>();
    public static HashMap<String, Short> mapOreDropUnlocalizedNameToOreMeta = new HashMap<>();
    public static HashMap<Short, List<ItemStack>> mapOreMetaToOreDrops = new HashMap<>();
    public static HashMap<OreSmallWrapper, String> bufferedDims = new HashMap<>();

    public GT5OreSmallHelper() {
        checkExtraSupport();
        ItemStack stack;
        Materials material;
        short meta;
        for (GT_Worldgen worldGen : GregTech_API.sWorldgenList)
            if (worldGen.mWorldGenName.startsWith("ore.small.") && worldGen instanceof GT_Worldgen_GT_Ore_SmallPieces) {
                GT_Worldgen_GT_Ore_SmallPieces worldGenSmallPieces = (GT_Worldgen_GT_Ore_SmallPieces) worldGen;
                meta = worldGenSmallPieces.mMeta;
                if (meta < 0) break;
                material = GregTech_API.sGeneratedMaterials[meta];
                mapOreSmallWrapper.put(worldGen.mWorldGenName, new OreSmallWrapper(worldGenSmallPieces));
                if (!mapOreMetaToOreDrops.containsKey(meta)) {
                    List<ItemStack> stackList = new ArrayList<>();
                    stack = GT_OreDictUnificator.get(
                            OrePrefixes.gemExquisite,
                            material,
                            GT_OreDictUnificator.get(OrePrefixes.gem, material, 1L),
                            1L);
                    if (stack != null && !mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) {
                        mapOreDropUnlocalizedNameToOreMeta.put(stack.getUnlocalizedName(), meta);
                        stackList.add(stack);
                    }
                    stack = GT_OreDictUnificator.get(
                            OrePrefixes.gemFlawless,
                            material,
                            GT_OreDictUnificator.get(OrePrefixes.gem, material, 1L),
                            1L);
                    if (stack != null && !mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) {
                        mapOreDropUnlocalizedNameToOreMeta.put(stack.getUnlocalizedName(), meta);
                        stackList.add(stack);
                    }
                    stack = GT_OreDictUnificator.get(OrePrefixes.gem, material, 1L);
                    if (stack != null && !mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) {
                        mapOreDropUnlocalizedNameToOreMeta.put(stack.getUnlocalizedName(), meta);
                        stackList.add(stack);
                    }
                    stack = GT_OreDictUnificator.get(
                            OrePrefixes.gemFlawed,
                            material,
                            GT_OreDictUnificator.get(OrePrefixes.crushed, material, 1L),
                            1L);
                    if (stack != null && !mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) {
                        mapOreDropUnlocalizedNameToOreMeta.put(stack.getUnlocalizedName(), meta);
                        stackList.add(stack);
                    }
                    stack = GT_OreDictUnificator.get(OrePrefixes.crushed, material, 1L);
                    if (stack != null && !mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) {
                        mapOreDropUnlocalizedNameToOreMeta.put(stack.getUnlocalizedName(), meta);
                        stackList.add(stack);
                    }
                    stack = GT_OreDictUnificator.get(
                            OrePrefixes.gemChipped,
                            material,
                            GT_OreDictUnificator.get(OrePrefixes.dustImpure, material, 1L),
                            1L);
                    if (stack != null && !mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) {
                        mapOreDropUnlocalizedNameToOreMeta.put(stack.getUnlocalizedName(), meta);
                        stackList.add(stack);
                    }
                    stack = GT_OreDictUnificator.get(OrePrefixes.dustImpure, material, 1L);
                    if (stack != null && !mapOreDropUnlocalizedNameToOreMeta.containsKey(stack.getUnlocalizedName())) {
                        mapOreDropUnlocalizedNameToOreMeta.put(stack.getUnlocalizedName(), meta);
                        stackList.add(stack);
                    }
                    oreSmallList.add(new ItemStack(GregTech_API.sBlockOres1, 1, meta + SMALL_ORE_BASE_META));
                    mapOreMetaToOreDrops.put(meta, stackList);
                }
            }
        for (OreSmallWrapper oreSmallWrapper : mapOreSmallWrapper.values()) {
            bufferedDims.put(oreSmallWrapper, GT5CFGHelper.GT5CFGSmallOres(oreSmallWrapper.oreGenName));
        }
    }

    private static void checkExtraSupport() {
        Class<?> clazzGTOreSmall = null;
        try {
            clazzGTOreSmall = Class.forName("gregtech.common" + ".GT_Worldgen_GT_Ore_SmallPieces");
        } catch (ClassNotFoundException e) {
        }
        if (clazzGTOreSmall != null) {
            try {
                Field fieldRestrictBiome = clazzGTOreSmall.getField("mRestrictBiome");
                restrictBiomeSupport = true;
            } catch (Exception e) {
            }
            try {
                Field fieldGCMoon = clazzGTOreSmall.getField("mMoon");
                Field fieldGCMars = clazzGTOreSmall.getField("mMars");
                gcBasicSupport = true;
            } catch (Exception e) {
            }
        }
    }

    public static Materials[] getDroppedDusts() {
        return new Materials[] {
            Materials.Stone,
            Materials.Netherrack,
            Materials.Endstone,
            Materials.GraniteBlack,
            Materials.GraniteRed,
            Materials.Marble,
            Materials.Basalt,
            Materials.Stone
        };
    }

    public static class OreSmallWrapper {
        public String oreGenName;
        public short oreMeta;
        public String worldGenHeightRange;
        public short amountPerChunk;
        public String restrictBiome;

        public OreSmallWrapper(GT_Worldgen_GT_Ore_SmallPieces worldGen) {
            this.oreGenName = worldGen.mWorldGenName;
            this.oreMeta = worldGen.mMeta;
            this.worldGenHeightRange = worldGen.mMinY + "-" + worldGen.mMaxY;
            this.amountPerChunk = worldGen.mAmount;
        }

        public List<ItemStack> getMaterialDrops(int maximumIndex) {
            List<ItemStack> stackList = new ArrayList<>();
            for (int i = 0; i < maximumIndex; i++)
                stackList.add(new ItemStack(GregTech_API.sBlockOres1, 1, oreMeta + SMALL_ORE_BASE_META + i * 1000));
            return stackList;
        }
    }
}