aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/detrav/utils/GTppHelper.java
blob: 483e8cfd5ecb5623d8b1e9eda9ef72f75e1715af (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
package detrav.utils;

import java.lang.reflect.Field;
import java.util.HashMap;

import net.minecraft.block.Block;

import gregtech.GTMod;
import gtPlusPlus.core.block.base.BlockBaseOre;
import gtPlusPlus.core.material.Material;
import gtPlusPlus.core.material.MaterialMisc;
import gtPlusPlus.core.material.MaterialsAlloy;
import gtPlusPlus.core.material.MaterialsElements;
import gtPlusPlus.core.material.MaterialsOres;
import gtPlusPlus.core.material.nuclear.MaterialsFluorides;

public class GTppHelper {

    private static boolean initialized;
    private static final HashMap<Short, Material> decodeoresGTpp = new HashMap<>();
    private static final HashMap<Material, Short> encodeoresGTpp = new HashMap<>();

    private static void generate_OreIDs() {
        short n = 0;
        final Field[] fields = MaterialsOres.class.getFields();
        for (; n < fields.length; ++n) {
            try {
                final Object o = fields[n].get(null);
                if (o instanceof Material m) {
                    Short i = (short) (n + 1);
                    decodeoresGTpp.put(i, m);
                    encodeoresGTpp.put(m, i);
                }
            } catch (Exception e) {
                GTMod.GT_FML_LOGGER
                    .error("Exception caught when trying to generate GT++ ore ids for detrav ore scanner", e);
            }
        }
        // Manually add ores from other places than the ore class
        // Fluorite
        decodeoresGTpp.put((short) (++n + 1), MaterialsFluorides.FLUORITE);
        encodeoresGTpp.put(MaterialsFluorides.FLUORITE, (short) (n + 1));
        // Rare Earths
        decodeoresGTpp.put((short) (++n + 1), MaterialMisc.RARE_EARTH_LOW);
        encodeoresGTpp.put(MaterialMisc.RARE_EARTH_LOW, (short) (n + 1));
        decodeoresGTpp.put((short) (++n + 1), MaterialMisc.RARE_EARTH_MID);
        encodeoresGTpp.put(MaterialMisc.RARE_EARTH_MID, (short) (n + 1));
        decodeoresGTpp.put((short) (++n + 1), MaterialMisc.RARE_EARTH_HIGH);
        encodeoresGTpp.put(MaterialMisc.RARE_EARTH_HIGH, (short) (n + 1));
        // Koboldite
        decodeoresGTpp.put((short) (++n + 1), MaterialsAlloy.KOBOLDITE);
        encodeoresGTpp.put(MaterialsAlloy.KOBOLDITE, (short) (n + 1));
        // Runite
        decodeoresGTpp.put((short) (++n + 1), MaterialsElements.STANDALONE.RUNITE);
        encodeoresGTpp.put(MaterialsElements.STANDALONE.RUNITE, (short) (n + 1));
        // Ancient granite
        decodeoresGTpp.put((short) (++n + 1), MaterialsElements.STANDALONE.GRANITE);
        encodeoresGTpp.put(MaterialsElements.STANDALONE.GRANITE, (short) (n + 1));
    }

    public static short getMetaFromBlock(Block block) {
        if (!initialized) {
            generate_OreIDs();
            initialized = true;
        }
        return (short) (GTppHelper.encodeoresGTpp.get(((BlockBaseOre) block).getMaterialEx()) + 7000);
    }

    public static Material getMatFromMeta(int meta) {
        if (!initialized) {
            generate_OreIDs();
            initialized = true;
        }
        return GTppHelper.decodeoresGTpp.get((short) (meta - 7000));
    }

    public static boolean isGTppBlock(Block block) {
        return block instanceof BlockBaseOre;
    }

    public static String getGTppVeinName(Block block) {
        return block.getLocalizedName();
    }

}