aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/thatgravyboat/skyblockhud/textures/TextureObject.java
blob: 6403e18bcc897bc89cc84b99646306e56f541d08 (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
package com.thatgravyboat.skyblockhud.textures;

import com.google.gson.JsonObject;
import java.util.Arrays;
import net.minecraft.util.ResourceLocation;

public class TextureObject {

    public String displayName;
    public ResourceLocation bars = resource("bars.png");
    public ResourceLocation mines = resource("mines.png");
    public ResourceLocation playerStats = resource("playerstats.png");
    public ResourceLocation stats = resource("stats.png");
    public ResourceLocation dungeon = resource("dungeon.png");
    public ResourceLocation dialogue = resource("dialogue.png");

    public TextureObject(String displayName) {
        this.displayName = displayName;
    }

    public static TextureObject decode(JsonObject json) {
        TextureObject textureObject = new TextureObject(json.get("displayName").getAsString());
        Arrays
            .stream(textureObject.getClass().getDeclaredFields())
            .filter(field -> field.getType().equals(ResourceLocation.class))
            .forEach(field -> {
                try {
                    field.set(textureObject, new ResourceLocation(json.get(field.getName()).getAsString()));
                } catch (Exception ignored) {}
            });
        return textureObject;
    }

    private static ResourceLocation resource(String path) {
        return new ResourceLocation("skyblockhud", path);
    }
}