diff options
author | ThatGravyBoat <thatgravyboat@gmail.com> | 2021-07-17 01:26:21 -0230 |
---|---|---|
committer | ThatGravyBoat <thatgravyboat@gmail.com> | 2021-07-17 01:26:21 -0230 |
commit | e364de18cbcbc9f334d890703812876789374bab (patch) | |
tree | d9360da1aaba43d88a2637ac73d9a15bd374886a /src/main/java/com/thatgravyboat/skyblockhud/handlers | |
parent | 3f3a68b898930c9c33ff852e6d0d8270835c4b98 (diff) | |
download | SkyblockHud-Death-Defied-e364de18cbcbc9f334d890703812876789374bab.tar.gz SkyblockHud-Death-Defied-e364de18cbcbc9f334d890703812876789374bab.tar.bz2 SkyblockHud-Death-Defied-e364de18cbcbc9f334d890703812876789374bab.zip |
Added the ability to turn off the map for certain locations and added the ability for texture pack devs to add textures for npc dialogue
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/handlers')
-rw-r--r-- | src/main/java/com/thatgravyboat/skyblockhud/handlers/NpcDialogue.java | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/NpcDialogue.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/NpcDialogue.java index ab4afbc..1db9d1a 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/handlers/NpcDialogue.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/NpcDialogue.java @@ -1,28 +1,39 @@ package com.thatgravyboat.skyblockhud.handlers; -import static com.thatgravyboat.skyblockhud.GuiTextures.dialogue; - +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 com.thatgravyboat.skyblockhud.Utils; -import java.util.ArrayDeque; -import java.util.List; -import java.util.Locale; -import java.util.Queue; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.client.resources.IResourceManagerReloadListener; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; -public class NpcDialogue { +import static com.thatgravyboat.skyblockhud.GuiTextures.dialogue; + +public class NpcDialogue implements IResourceManagerReloadListener { public static final Pattern NPC_DIALOGUE_REGEX = Pattern.compile("\\[NPC] (.*): (.*)"); + private static final Gson gson = new GsonBuilder().create(); + private static final Map<String, ResourceLocation> NPCS = new HashMap<>(); + private static boolean showDialogue = false; private static int ticks = 0; @@ -77,6 +88,13 @@ public class NpcDialogue { Gui.drawModalRectWithCustomSizedTexture(x, y, 0, 0, 182, 68, 256, 256); + String npcID = currentNpc.toLowerCase(Locale.ENGLISH).replace(" ", "_"); + + if (NPCS.containsKey(npcID)){ + mc.renderEngine.bindTexture(NPCS.get(npcID)); + Gui.drawModalRectWithCustomSizedTexture(x + 4, y + 4, 0, 0, 32, 60, 128, 128); + } + FontRenderer font = mc.fontRendererObj; font.drawString(currentNpc, x + 40, y + 10, 0xffffff); @@ -88,4 +106,22 @@ public class NpcDialogue { } } } + + @Override + public void onResourceManagerReload(IResourceManager resourceManager) { + NPCS.clear(); + try { + ResourceLocation trackers = new ResourceLocation("skyblockhud:data/npc_textures.json"); + InputStream is = resourceManager.getResource(trackers).getInputStream(); + + try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { + for (JsonElement npc : gson.fromJson(reader, JsonObject.class).getAsJsonArray("npcs")) { + JsonObject npcObject = npc.getAsJsonObject(); + String npcName = npcObject.get("name").getAsString(); + ResourceLocation rl = new ResourceLocation(npcObject.get("texture").getAsString()); + NPCS.put(npcName.toLowerCase(Locale.ENGLISH).replace(" ", "_"), rl); + } + } + } catch (Exception ignored) {} + } } |