aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/bartworks/API/GlassTier.java
blob: 64612549c9ae48f4dd79f628df65fbbc10401c88 (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
package bartworks.API;

import static cpw.mods.fml.common.registry.GameRegistry.findBlock;

import java.util.HashMap;
import java.util.Objects;

import net.minecraft.block.Block;

import org.jetbrains.annotations.NotNull;

public class GlassTier {

    private static final HashMap<BlockMetaPair, Integer> glasses = new HashMap<>();

    /**
     * @param modname              The modid owning the block
     * @param unlocalisedBlockName The name of the block itself
     * @param meta                 The meta of the block
     * @param tier                 the glasses Tier = Voltage tier (MIN 3)
     */
    public static void addCustomGlass(String modname, String unlocalisedBlockName, int meta, int tier) {
        Block block = findBlock(modname, unlocalisedBlockName);
        if (block != null) {
            addCustomGlass(block, meta, tier);
        } else {
            new IllegalArgumentException(
                "Block: " + unlocalisedBlockName
                    + " of the Mod: "
                    + modname
                    + " was NOT found when attempting to register a glass!").printStackTrace();
        }
    }

    public static void addCustomGlass(@NotNull Block block, int meta, int tier) {
        Objects.requireNonNull(block, "Glass block cannot be null");
        GlassTier.glasses.put(new BlockMetaPair(block, (byte) meta), tier);
    }

    public static HashMap<BlockMetaPair, Integer> getGlassMap() {
        return glasses;
    }

    public static int getGlassTier(Block block, int meta) {
        return glasses.getOrDefault(new BlockMetaPair(block, (byte) meta), 0);
    }

    public static class BlockMetaPair {

        private final Block block;
        private final int meta;

        public BlockMetaPair(Block block, int aByte) {
            this.block = block;
            this.meta = aByte;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || this.getClass() != o.getClass()) return false;
            BlockMetaPair that = (BlockMetaPair) o;
            return Objects.equals(this.getBlock(), that.getBlock()) && Objects.equals(this.getMeta(), that.getMeta());
        }

        @Override
        public int hashCode() {
            return Objects.hash(this.getBlock(), this.getMeta());
        }

        public Block getBlock() {
            return this.block;
        }

        public int getMeta() {
            return this.meta;
        }
    }
}