aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/thatgravyboat/skyblockhud/textures
diff options
context:
space:
mode:
authorThatGravyBoat <thatgravyboat@gmail.com>2021-07-18 05:27:24 -0230
committerThatGravyBoat <thatgravyboat@gmail.com>2021-07-18 05:27:24 -0230
commit5559861e52a788f08bc48946a9aad6dd52b373bf (patch)
treef4caac982db914fca97527f8783d26d6703bec64 /src/main/java/com/thatgravyboat/skyblockhud/textures
parentbaf3b8aa15cbd2dc0fcb4a80707557c44ee30c16 (diff)
downloadSkyblockHud-Death-Defied-5559861e52a788f08bc48946a9aad6dd52b373bf.tar.gz
SkyblockHud-Death-Defied-5559861e52a788f08bc48946a9aad6dd52b373bf.tar.bz2
SkyblockHud-Death-Defied-5559861e52a788f08bc48946a9aad6dd52b373bf.zip
Added texture styles
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/textures')
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud/textures/TextureObject.java37
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud/textures/Textures.java49
2 files changed, 86 insertions, 0 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/textures/TextureObject.java b/src/main/java/com/thatgravyboat/skyblockhud/textures/TextureObject.java
new file mode 100644
index 0000000..10495f5
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud/textures/TextureObject.java
@@ -0,0 +1,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);
+ }
+}
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/textures/Textures.java b/src/main/java/com/thatgravyboat/skyblockhud/textures/Textures.java
new file mode 100644
index 0000000..61b19b7
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud/textures/Textures.java
@@ -0,0 +1,49 @@
+package com.thatgravyboat.skyblockhud.textures;
+
+import com.google.common.collect.Lists;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.thatgravyboat.skyblockhud.SkyblockHud;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import net.minecraft.client.resources.IResourceManager;
+import net.minecraft.client.resources.IResourceManagerReloadListener;
+import net.minecraft.util.ResourceLocation;
+
+public class Textures implements IResourceManagerReloadListener {
+ private static final TextureObject DEFAULT_TEXTURE = new TextureObject("Default");
+
+ private static final Gson gson = new GsonBuilder().create();
+ public static final List<TextureObject> styles = Lists.newArrayList(DEFAULT_TEXTURE);
+ public static TextureObject texture = DEFAULT_TEXTURE;
+
+ public static void setTexture(int selected){
+ if (selected >= styles.size() || selected < 0) {
+ texture = DEFAULT_TEXTURE;
+ SkyblockHud.config.misc.style = 0;
+ } else {
+ texture = styles.get(selected);
+ }
+ }
+
+ @Override
+ public void onResourceManagerReload(IResourceManager resourceManager) {
+ styles.clear();
+ styles.add(DEFAULT_TEXTURE);
+ try {
+ ResourceLocation stylesData = new ResourceLocation("skyblockhud:data/styles.json");
+ InputStream is = resourceManager.getResource(stylesData).getInputStream();
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
+ for (JsonElement json : gson.fromJson(reader, JsonObject.class).getAsJsonArray("styles")) {
+ styles.add(TextureObject.decode((JsonObject) json));
+ }
+ }
+ } catch (Exception ignored) {}
+ }
+
+}