diff options
author | Albi <12825442+Flanisch@users.noreply.github.com> | 2022-08-12 20:34:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-12 20:34:37 +0200 |
commit | bbd40c34e104dcead78290af1394e6f5867df565 (patch) | |
tree | 43c8d507722b7ba189cf4acfb924ca584b287c6f /src/main/java/gregtech/loaders/misc | |
parent | d815f1f0e7b267c1c7ef97fdf2c790b6c9f6a378 (diff) | |
download | GT5-Unofficial-bbd40c34e104dcead78290af1394e6f5867df565.tar.gz GT5-Unofficial-bbd40c34e104dcead78290af1394e6f5867df565.tar.bz2 GT5-Unofficial-bbd40c34e104dcead78290af1394e6f5867df565.zip |
Added means of customizing GUI colors for resource packs (#1203)
* Added means of customizing GUI colors through lang file
* Color values are now stored in json file instead of the lang file
* Made json only load upon resource reload and ensured server compatibility
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Diffstat (limited to 'src/main/java/gregtech/loaders/misc')
-rw-r--r-- | src/main/java/gregtech/loaders/misc/GT_JsonLoader.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/main/java/gregtech/loaders/misc/GT_JsonLoader.java b/src/main/java/gregtech/loaders/misc/GT_JsonLoader.java new file mode 100644 index 0000000000..d46c7eae0b --- /dev/null +++ b/src/main/java/gregtech/loaders/misc/GT_JsonLoader.java @@ -0,0 +1,64 @@ +package gregtech.loaders.misc; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.IReloadableResourceManager; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.client.resources.IResourceManagerReloadListener; +import net.minecraft.util.ResourceLocation; + +import org.json.JSONObject; + +import gregtech.api.util.GT_Log; + +@SideOnly(Side.CLIENT) +public class GT_JsonLoader implements IResourceManagerReloadListener { + private JSONObject json; + private ResourceLocation jsonLocation; + private IResourceManager resourceManager; + + public String getString(String key) { + String s = ""; + try { + s = this.json.getString(key); + } + catch (Exception e) { + GT_Log.err.println("GT_JsonLoader" + e); + } + return s; + } + + public void loadJson() { + this.json = new JSONObject("{}"); + try { + BufferedInputStream bis = new BufferedInputStream(this.resourceManager.getResource(this.jsonLocation).getInputStream()); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + for (int result = bis.read(); result != -1; result = bis.read()) { + bos.write((byte)result); + } + + this.json = new JSONObject(bos.toString("UTF-8")); + } + catch (Exception e) { + GT_Log.err.println("GT_JsonLoader: " + e); + } + } + + public void onResourceManagerReload(IResourceManager rm) { + loadJson(); + } + + public GT_JsonLoader (String resourcePath) { + GT_Log.err.println("GT_JsonLoader: Init"); + this.jsonLocation = new ResourceLocation("gregtech", resourcePath); + this.resourceManager = Minecraft.getMinecraft().getResourceManager(); + ((IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(this); + loadJson(); + } +}
\ No newline at end of file |