diff --git a/build.gradle b/build.gradle index da91906..5b9bca7 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,12 @@ version = project.mod_version group = project.maven_group repositories { - maven { url 'https://jitpack.io' } + maven { + url 'https://jitpack.io' + } + maven { + url 'https://maven.foxes4life.net' + } } configurations { @@ -30,6 +35,7 @@ dependencies { modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" implementation 'com.github.Vatuu:discord-rpc:1.6.2' + implementation 'net.foxes4life:konfig:1.1' extraLibs files('discord-rpc-jna-removed.jar') //configurations.compile.extendsFrom(configurations.extraLibs) diff --git a/gradle.properties b/gradle.properties index 6c8de9b..74f9485 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx2G loader_version=0.14.6 # Mod Properties - mod_version = 0.1.4-1.19 + mod_version = 0.1.5-1.19 maven_group = net.foxes4life archives_base_name = foxclient diff --git a/src/main/java/net/foxes4life/foxclient/Main.java b/src/main/java/net/foxes4life/foxclient/Main.java index 32e3132..3592194 100644 --- a/src/main/java/net/foxes4life/foxclient/Main.java +++ b/src/main/java/net/foxes4life/foxclient/Main.java @@ -2,23 +2,19 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.loader.api.FabricLoader; -import net.foxes4life.foxclient.config.Config; -import net.foxes4life.foxclient.config.ConfigData; +import net.foxes4life.konfig.Konfig; +import net.foxes4life.konfig.data.KonfigCategory; public class Main implements ModInitializer { public static final String FOXCLIENT_MOD_ID = "foxclient"; public static String VERSION = ""; public static String JAVA_VERSION = "unknown"; - public static Config config_instance; - public static ConfigData config; + public static Konfig konfig; @Override public void onInitialize() { - Config.load("config.json"); - config_instance = Config.getInstance(); - config = Config.getData(); - config_instance.toFile("config.json"); + initConfig(); if(FabricLoader.getInstance().getModContainer(Main.FOXCLIENT_MOD_ID).isPresent()) { VERSION = FabricLoader.getInstance().getModContainer(Main.FOXCLIENT_MOD_ID).get().getMetadata().getVersion().getFriendlyString(); @@ -31,4 +27,35 @@ public void onInitialize() { System.out.println("FoxClient (recode) by Rooot and Flustix"); System.out.println(Main.VERSION); } + + void initConfig () { + konfig = new Konfig("foxclient"); + + KonfigCategory client = new KonfigCategory("client"); + client.addEntry("hud-enabled", true); + + KonfigCategory menus = new KonfigCategory("menus"); + menus.addEntry("mainmenu", true); + menus.addEntry("pause", false); + + KonfigCategory misc = new KonfigCategory("misc"); + misc.addEntry("discord-rpc", true); + misc.addEntry("discord-rpc-show-ip", true); + + KonfigCategory eastereggs = new KonfigCategory("eastereggs"); + eastereggs.addEntry("owo", false); + + KonfigCategory ingameHUD = new KonfigCategory("ingame-hud"); + ingameHUD.addEntry("version", true); + ingameHUD.addEntry("coords", true); + ingameHUD.addEntry("fps", true); + ingameHUD.addEntry("ping", true); + ingameHUD.addEntry("tps", true); + + konfig.addCategory(client); + konfig.addCategory(menus); + konfig.addCategory(ingameHUD); + konfig.addCategory(misc); + konfig.addCategory(eastereggs); + } } diff --git a/src/main/java/net/foxes4life/foxclient/MainClient.java b/src/main/java/net/foxes4life/foxclient/MainClient.java index 6d7f56d..63e68d6 100644 --- a/src/main/java/net/foxes4life/foxclient/MainClient.java +++ b/src/main/java/net/foxes4life/foxclient/MainClient.java @@ -14,6 +14,8 @@ import net.minecraft.client.option.KeyBinding; import org.lwjgl.glfw.GLFW; +import java.io.IOException; + public class MainClient implements ClientModInitializer { private static final KeyBinding toggleHud = new KeyBinding("key.foxclient.toggle_hud", GLFW.GLFW_KEY_F6, "category.foxclient.main"); private static final KeyBinding clientConfig = new KeyBinding("key.foxclient.configKey", GLFW.GLFW_KEY_RIGHT_CONTROL, "category.foxclient.main"); @@ -33,8 +35,10 @@ public void onInitializeClient() { ClientTickEvents.END_CLIENT_TICK.register(client -> { while (toggleHud.wasPressed()) { - Main.config_instance.set("client", "hud-enabled", - Main.config_instance.getEntry("client", "hud-enabled").setValue(!Main.config_instance.getBoolean("client", "hud-enabled"))); + Main.konfig.set("client", "hud-enabled", !(boolean) Main.konfig.get("client", "hud-enabled")); + try { + Main.konfig.save(); + } catch (IOException ignored) {} } }); diff --git a/src/main/java/net/foxes4life/foxclient/config/Category.java b/src/main/java/net/foxes4life/foxclient/config/Category.java deleted file mode 100644 index b51d2a6..0000000 --- a/src/main/java/net/foxes4life/foxclient/config/Category.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.foxes4life.foxclient.config; - -import com.google.gson.annotations.Expose; - -import java.util.LinkedHashMap; - -public class Category { - @Expose - public final String name; - - @Expose - public LinkedHashMap> settings = new LinkedHashMap<>(); - - public Category(String name) { - this.name = name; - } - - public void addSetting(String key, CategoryEntry value) { - this.settings.put(key, value); - } - - public void set(String key, CategoryEntry value) { - if(!this.settings.containsKey(key)) return; - this.settings.put(key, value); - } - - public Object get(String key) { - if(!this.settings.containsKey(key)) return null; - return this.settings.get(key); - } -} diff --git a/src/main/java/net/foxes4life/foxclient/config/CategoryEntry.java b/src/main/java/net/foxes4life/foxclient/config/CategoryEntry.java deleted file mode 100644 index b7ef193..0000000 --- a/src/main/java/net/foxes4life/foxclient/config/CategoryEntry.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.foxes4life.foxclient.config; - -import com.google.gson.annotations.Expose; - -public class CategoryEntry { - @Expose - public final String name; - - @Expose - private T value; - - public CategoryEntry(T value, String name) { - this.value = value; - this.name = name; - } - - public CategoryEntry setValue(Object newVal) { - if(newVal == null) { - System.out.println("value is null"); - return this; - } - - //noinspection unchecked - this.value = (T) newVal; - return this; - } - - public T getValue() { - return this.value; - } -} diff --git a/src/main/java/net/foxes4life/foxclient/config/Config.java b/src/main/java/net/foxes4life/foxclient/config/Config.java deleted file mode 100644 index b9b44af..0000000 --- a/src/main/java/net/foxes4life/foxclient/config/Config.java +++ /dev/null @@ -1,149 +0,0 @@ -package net.foxes4life.foxclient.config; - -import com.google.common.reflect.TypeToken; -import com.google.gson.*; -import net.foxes4life.foxclient.Main; -import net.fabricmc.loader.api.FabricLoader; - -import java.io.*; -import java.lang.reflect.Type; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.LinkedHashMap; - -// i literally copy-pasted this from https://github.com/frankred/json-config-file because I am lazy -// (it is heavily modified tho) -public class Config { - public static File configDir = Paths.get(FabricLoader.getInstance().getConfigDir().toString(), Main.FOXCLIENT_MOD_ID).toFile(); - static Path folderPath = Paths.get(FabricLoader.getInstance().getConfigDir().toString(), Main.FOXCLIENT_MOD_ID); - private String configFile; - - private static Config instance; - private static ConfigData data; - - public static Config getInstance() { - data = fromFile(Paths.get(configDir.toString(), instance.configFile).toFile()); - if (data == null) { - data = fromDefaults(); - } - - return instance; - } - - public static ConfigData getData() { - return data; - } - private static void load(File file) { - checkForPath(); - data = fromFile(file); - //instance = fromFile(file); - - if (instance == null) { - instance = new Config(); - } - - if (data == null) { - data = fromDefaults(); - } - } - - public static void load(String file) { - load(Paths.get(configDir.toString(), file).toFile()); - instance.configFile = file; - } - - private static ConfigData fromDefaults() { - return new ConfigData(); - } - - public void toFile(String file) { - toFile(Paths.get(configDir.toString(), file).toFile()); - } - - private void toFile(File file) { - checkForPath(); - Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation() - .setPrettyPrinting().create(); - String jsonConfig = gson.toJson(data.things); - FileWriter writer; - try { - writer = new FileWriter(file); - writer.write(jsonConfig); - writer.flush(); - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - private static ConfigData fromFile(File configFile) { - try { - Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation() - .setPrettyPrinting().create(); - BufferedReader reader = new BufferedReader(new InputStreamReader( - new FileInputStream(configFile))); - @SuppressWarnings("UnstableApiUsage") - Type type = new TypeToken>() { - }.getType(); - return new ConfigData(gson.fromJson(reader, type)); - } catch (FileNotFoundException e) { - return null; - } - } - - @Override - public String toString() { - Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation() - .setPrettyPrinting().create(); - return gson.toJson(data); - } - - // config set methods - public void set(String category, String key, CategoryEntry value) { - data.things.get(category).set(key, value); - instance.toFile(instance.configFile); - } - - public boolean getBoolean(String category, String name) { - Object d = getObject(category, name); - if (d != null) { - try { - return (boolean) d; - } catch (ClassCastException ignored) { - return false; - } - } - return false; - } - - public String getString(String category, String name) { - Object d = getObject(category, name); - if (d != null) { - try { - return (String) d; - } catch (ClassCastException ignored) { - return null; - } - } - return null; - } - - public CategoryEntry getEntry(String category, String name) { - return data.things.get(category).settings.get(name); - } - - public Object getObject(String category, String name) { - return data.things.get(category).settings.get(name).getValue(); - } - - static void checkForPath(){ - if (!Files.exists(folderPath)) { - try { - Files.createDirectory(folderPath); - } catch (IOException e) { - e.printStackTrace(); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/net/foxes4life/foxclient/config/ConfigData.java b/src/main/java/net/foxes4life/foxclient/config/ConfigData.java deleted file mode 100644 index 9c87fb3..0000000 --- a/src/main/java/net/foxes4life/foxclient/config/ConfigData.java +++ /dev/null @@ -1,56 +0,0 @@ -package net.foxes4life.foxclient.config; - -import net.minecraft.util.Identifier; - -import java.util.LinkedHashMap; - -public class ConfigData { - public LinkedHashMap things = new LinkedHashMap<>(); // linked to prevent messing up the config file - - public ConfigData() { - Category client = new Category("Client"); - client.addSetting("hud-enabled", new CategoryEntry<>(true, "Show HUD")); - - Category menus = new Category("Menus"); - menus.addSetting("mainmenu", new CategoryEntry<>(true, "Title Screen")); - menus.addSetting("pause", new CategoryEntry<>(false, "Pause Screen")); - - Category misc = new Category("Miscellaneous"); - misc.addSetting("discord-rpc", new CategoryEntry<>(true, "Discord RPC")); - misc.addSetting("discord-rpc-show-ip", new CategoryEntry<>(true, "RPC: Show Server IP")); - - Category debug = new Category("Debug"); - debug.addSetting("boolean-uwu", new CategoryEntry<>(true, "Boolean Test")); - debug.addSetting("string-owo", new CategoryEntry<>("hewwo wowwd", "String Test")); - debug.addSetting("float-rawr", new CategoryEntry<>(0.1F, "Float Test")); - debug.addSetting("int-nya", new CategoryEntry<>(621, "Integer Test")); - debug.addSetting("identifier", new CategoryEntry<>(new Identifier("among", "us"), "ID Test")); - - Category eastereggs = new Category("Easter Eggs"); - eastereggs.addSetting("owo", new CategoryEntry<>(false, "owo whats this?")); - - Category ingameHUD = new Category("Overlay HUD"); - ingameHUD.addSetting("version", new CategoryEntry<>(true, "Version")); - ingameHUD.addSetting("coords", new CategoryEntry<>(true, "Coordinates")); - ingameHUD.addSetting("fps", new CategoryEntry<>(true, "FPS")); - ingameHUD.addSetting("ping", new CategoryEntry<>(true, "Ping")); - ingameHUD.addSetting("tps", new CategoryEntry<>(true, "TPS")); - - things.put("client", client); - things.put("menus", menus); - things.put("ingame-hud", ingameHUD); - things.put("misc", misc); - things.put("eastereggs", eastereggs); -// things.put("debug", debug); - } - - public ConfigData(LinkedHashMap in) { - things = new ConfigData().things; - - things.putAll(in); - } - - public ConfigData getInstance() { - return this; - } -} \ No newline at end of file diff --git a/src/main/java/net/foxes4life/foxclient/config/ConfigHelper.java b/src/main/java/net/foxes4life/foxclient/config/ConfigHelper.java deleted file mode 100644 index 8b9c16c..0000000 --- a/src/main/java/net/foxes4life/foxclient/config/ConfigHelper.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.foxes4life.foxclient.config; - -import net.foxes4life.foxclient.rpc.DiscordInstance; -import net.foxes4life.foxclient.rpc.PresenceUpdater; -import net.foxes4life.foxclient.rpc.State; - -public class ConfigHelper { - - // called whenever something needs to be done extra - public static void onUpdate(String category, String key, Object value) { -// System.out.println("update " + category+"."+key + " to " + value); - if(category.equals("misc")) { - if(key.equals("discord-rpc")) { - boolean enabled = (boolean) value; - if(!enabled) { - System.out.println("ConfigHelper: stopping discord rpc"); - DiscordInstance.get().stfu(); - } else { - System.out.println("ConfigHelper: starting discord rpc"); - DiscordInstance.get().init(); - PresenceUpdater.setState(State.IDLE); - } - } - } - } -} diff --git a/src/main/java/net/foxes4life/foxclient/gui/FoxClientHUD.java b/src/main/java/net/foxes4life/foxclient/gui/FoxClientHUD.java index bbf74b5..42c4c4d 100644 --- a/src/main/java/net/foxes4life/foxclient/gui/FoxClientHUD.java +++ b/src/main/java/net/foxes4life/foxclient/gui/FoxClientHUD.java @@ -49,21 +49,28 @@ public void render(MatrixStack matrices) { } void loadList () { - if (Main.config_instance.getBoolean("ingame-hud", "version")) + boolean version = (boolean) Main.konfig.get("ingame-hud", "version"); + boolean coords = (boolean) Main.konfig.get("ingame-hud", "coords"); + boolean fps = (boolean) Main.konfig.get("ingame-hud", "fps"); + boolean ping = (boolean) Main.konfig.get("ingame-hud", "ping"); + boolean tps = (boolean) Main.konfig.get("ingame-hud", "tps"); + + + if (version) textList.add(TextUtils.string(Main.VERSION)); - if (Main.config_instance.getBoolean("ingame-hud", "coords")) { + if (coords) { assert this.client.player != null; textList.add(TextUtils.string(String.format("[XYZ] %s %s %s", this.client.player.getBlockPos().getX(), this.client.player.getBlockPos().getY(), this.client.player.getBlockPos().getZ()))); } - if (Main.config_instance.getBoolean("ingame-hud", "fps")) + if (fps) textList.add(TextUtils.string("[FPS] " + ClientUtils.getFPS())); - if (Main.config_instance.getBoolean("ingame-hud", "ping")) + if (ping) textList.add(TextUtils.string(String.format("[Ping] " + ClientUtils.getPing() + "ms"))); - if (Main.config_instance.getBoolean("ingame-hud", "tps")) + if (tps) textList.add(TextUtils.string(String.format("[TPS] " + ServerTickUtils.calculateServerTPS()))); for (Text text : textList) { diff --git a/src/main/java/net/foxes4life/foxclient/mixin/InGameHUDMixin.java b/src/main/java/net/foxes4life/foxclient/mixin/InGameHUDMixin.java index 95577b3..8e44fa1 100644 --- a/src/main/java/net/foxes4life/foxclient/mixin/InGameHUDMixin.java +++ b/src/main/java/net/foxes4life/foxclient/mixin/InGameHUDMixin.java @@ -18,7 +18,7 @@ public class InGameHUDMixin { @Inject(at = @At("HEAD"), method = "render") public void render(MatrixStack matrices, float tickDelta, CallbackInfo ci) { - if(Main.config_instance.getBoolean("client", "hud-enabled")) { + if((boolean) Main.konfig.get("client", "hud-enabled")) { new FoxClientHUD(this.client).render(matrices); } } diff --git a/src/main/java/net/foxes4life/foxclient/mixin/MinecraftClientMixin.java b/src/main/java/net/foxes4life/foxclient/mixin/MinecraftClientMixin.java index e987bc5..a0315fc 100644 --- a/src/main/java/net/foxes4life/foxclient/mixin/MinecraftClientMixin.java +++ b/src/main/java/net/foxes4life/foxclient/mixin/MinecraftClientMixin.java @@ -52,7 +52,7 @@ private void getWindowTitle(CallbackInfoReturnable cir) { ClientPlayNetworkHandler clientPlayNetworkHandler = MinecraftClient.getInstance().getNetworkHandler(); - if(Main.config_instance.getBoolean("misc", "discord-rpc")) { + if((boolean)Main.konfig.get("misc", "discord-rpc")) { PresenceUpdater.setState(DiscordMinecraftClient.getState(clientPlayNetworkHandler)); } @@ -63,7 +63,7 @@ private void getWindowTitle(CallbackInfoReturnable cir) { } else if(MinecraftClient.getInstance().isConnectedToRealms()) { title += I18n.translate("title.multiplayer.realms"); } else if(this.server == null && (this.currentServerEntry == null || ! this.currentServerEntry.isLocal())) { - if(this.currentServerEntry != null && this.currentServerEntry.address != null || Main.config_instance.getBoolean("misc", "discord-rpc-show-ip")) { + if(this.currentServerEntry != null && this.currentServerEntry.address != null || (boolean)Main.konfig.get("misc", "discord-rpc-show-ip")) { title += I18n.translate("title.multiplayer.other2", this.currentServerEntry.address); } else { title += I18n.translate("title.multiplayer.other"); @@ -78,7 +78,7 @@ private void getWindowTitle(CallbackInfoReturnable cir) { @Inject(at = @At("HEAD"), method = "openPauseMenu", cancellable = true) public void openPauseMenu(boolean pause, CallbackInfo ci) { - if (Main.config_instance.getBoolean("menus", "pause")) { + if ((boolean)Main.konfig.get("menus", "pause")) { ci.cancel(); if (MinecraftClient.getInstance().currentScreen == null) { MinecraftClient.getInstance().setScreen(new FoxClientPauseMenu()); diff --git a/src/main/java/net/foxes4life/foxclient/mixin/TitleScreenMixin.java b/src/main/java/net/foxes4life/foxclient/mixin/TitleScreenMixin.java index 9642afe..cb7803d 100644 --- a/src/main/java/net/foxes4life/foxclient/mixin/TitleScreenMixin.java +++ b/src/main/java/net/foxes4life/foxclient/mixin/TitleScreenMixin.java @@ -14,7 +14,7 @@ public class TitleScreenMixin { @Inject(at = @At("HEAD"), method = "render", cancellable = true) public void render(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) { - if (Main.config_instance.getBoolean("menus", "mainmenu")) { + if ((boolean)Main.konfig.get("menus", "mainmenu")) { ci.cancel(); MinecraftClient.getInstance().setScreen(new FoxClientTitleScreen(false)); } diff --git a/src/main/java/net/foxes4life/foxclient/rpc/Discord.java b/src/main/java/net/foxes4life/foxclient/rpc/Discord.java index 0f94fe5..e63eafa 100644 --- a/src/main/java/net/foxes4life/foxclient/rpc/Discord.java +++ b/src/main/java/net/foxes4life/foxclient/rpc/Discord.java @@ -26,7 +26,7 @@ public void init() { } } - if(Main.config_instance.getBoolean("misc", "discord-rpc")) { + if((boolean)Main.konfig.get("misc", "discord-rpc")) { System.out.println("yes"); try { System.out.println("init dc"); @@ -72,7 +72,7 @@ public void setActivity(DiscordRichPresence.Builder presenceBuilder) { return; } - if(Main.config_instance.getBoolean("misc", "discord-rpc")) { + if((boolean)Main.konfig.get("misc", "discord-rpc")) { if (START_TIME == 0L) { START_TIME = System.currentTimeMillis(); } @@ -85,7 +85,7 @@ public void setActivity(DiscordRichPresence.Builder presenceBuilder) { } private void runCallback() { - if(Main.config_instance.getBoolean("misc", "discord-rpc")) { + if((boolean)Main.konfig.get("misc", "discord-rpc")) { DiscordRPC.discordRunCallbacks(); } } diff --git a/src/main/java/net/foxes4life/foxclient/rpc/PresenceUpdater.java b/src/main/java/net/foxes4life/foxclient/rpc/PresenceUpdater.java index 4e13805..b45159f 100644 --- a/src/main/java/net/foxes4life/foxclient/rpc/PresenceUpdater.java +++ b/src/main/java/net/foxes4life/foxclient/rpc/PresenceUpdater.java @@ -18,7 +18,7 @@ public static void setState(State state) { case SINGLEPLAYER -> stateLine = I18n.translate("foxclient.rpc.state.singleplayer"); case LAN -> stateLine = I18n.translate("foxclient.rpc.state.lan"); case MULTIPLAYER -> { - if (Main.config_instance.getBoolean("misc", "discord-rpc-show-ip")) { + if ((boolean)Main.konfig.get("misc", "discord-rpc-show-ip")) { if(MinecraftClient.getInstance().getCurrentServerEntry() != null) { stateLine = I18n.translate("foxclient.rpc.state.multiplayer", MinecraftClient.getInstance().getCurrentServerEntry().address); } else { @@ -32,7 +32,7 @@ public static void setState(State state) { default -> stateLine = "unimplemented!"; } - if(Main.config_instance.getBoolean("misc", "discord-rpc") && Discord.initialised) { + if((boolean)Main.konfig.get("misc", "discord-rpc") && Discord.initialised) { DiscordRichPresence.Builder builder = new DiscordRichPresence.Builder(stateLine) .setDetails("Playing Minecraft "+SharedConstants.getGameVersion().getName()) .setBigImage(largeImage, "FoxClient - A private Minecraft Mod") diff --git a/src/main/java/net/foxes4life/foxclient/screen/settings/client/SettingsMenuScreen.java b/src/main/java/net/foxes4life/foxclient/screen/settings/client/SettingsMenuScreen.java index e9ee668..17f8e85 100644 --- a/src/main/java/net/foxes4life/foxclient/screen/settings/client/SettingsMenuScreen.java +++ b/src/main/java/net/foxes4life/foxclient/screen/settings/client/SettingsMenuScreen.java @@ -3,11 +3,11 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.foxes4life.foxclient.Main; -import net.foxes4life.foxclient.config.Category; -import net.foxes4life.foxclient.config.ConfigHelper; import net.foxes4life.foxclient.gui.settings.SettingsCategorySidebarButton; import net.foxes4life.foxclient.gui.settings.SettingsToggleButton; +import net.foxes4life.foxclient.util.ConfigUtils; import net.foxes4life.foxclient.util.TextUtils; +import net.foxes4life.konfig.data.KonfigCategory; import net.minecraft.client.gui.Drawable; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.Selectable; @@ -18,6 +18,8 @@ import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import java.io.IOException; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.concurrent.atomic.AtomicInteger; @@ -26,7 +28,7 @@ public class SettingsMenuScreen extends Screen { private static final Identifier X_BUTTON = new Identifier("foxclient", "textures/ui/buttons/x.png"); private static String currentCategoryId; - private static Category currentCategory; + private static KonfigCategory currentCategory; private static final int sidebarWidth = 64+16; private int amountOfDrawableChilds = 0; // set amount of buttons created in init() here (excluding the ones in the loop) @@ -48,7 +50,7 @@ protected void init() { assert this.client != null; this.client.keyboard.setRepeatEvents(true); - LinkedHashMap categories = Main.config.things; + HashMap categories = Main.konfig.getData(); AtomicInteger cat = new AtomicInteger(); @@ -58,7 +60,7 @@ protected void init() { cat.get() *22+6, sidebarWidth, 22, - Text.of(category.name), + ConfigUtils.translatableCategory(category), false, name, (button) -> { @@ -96,7 +98,7 @@ protected void init() { } } - private void addCategoryButtons(String name, Category category) { + private void addCategoryButtons(String name, KonfigCategory category) { if(currentCategory != null) { for (Object o : this.children().subList(amountOfDrawableChilds, this.children().size()).toArray()) { this.remove((Element) o); @@ -109,26 +111,30 @@ private void addCategoryButtons(String name, Category category) { AtomicInteger settingsThing = new AtomicInteger(0); int bHeight = 22; - currentCategory.settings.forEach((key, value) -> { + currentCategory.catData.forEach((key, value) -> { settingsThing.getAndIncrement(); - if (Boolean.class.equals(value.getValue().getClass())) { + if (Boolean.class.equals(value.value.getClass())) { // System.out.println("boolean"); this.addDrawableChild( new SettingsToggleButton(sidebarWidth+2, settingsThing.get()*bHeight+32, width - sidebarWidth - 4, bHeight, - Text.of(value.name), (Boolean) value.getValue(), (b) -> { + ConfigUtils.translatableEntry(category, value), (Boolean) value.value, (b) -> { // System.out.println("clicked toggle!"); - Main.config_instance.set(name, key, value.setValue(!(boolean)value.getValue())); - ConfigHelper.onUpdate(name, key, value.getValue()); + Main.konfig.set(name, key, !(boolean)value.value); + try { + Main.konfig.save(); + } catch (IOException e) { + e.printStackTrace(); + } })); - } else if (String.class.equals(value.getValue().getClass())) { + } else if (String.class.equals(value.value.getClass())) { // System.out.println("string"); this.addDrawableChild(new ButtonWidget(0,0,0,0, Text.of(""), (b) -> {})); } else { - System.out.println("UNKNOWN: " + value.getValue().getClass()); + System.out.println("UNKNOWN: " + value.value.getClass()); // add dummy to avoid crashes this.addDrawableChild(new ButtonWidget(0,0,0,0, Text.of("a"), (b) -> {})); } diff --git a/src/main/java/net/foxes4life/foxclient/util/ConfigUtils.java b/src/main/java/net/foxes4life/foxclient/util/ConfigUtils.java new file mode 100644 index 0000000..19e78ad --- /dev/null +++ b/src/main/java/net/foxes4life/foxclient/util/ConfigUtils.java @@ -0,0 +1,16 @@ +package net.foxes4life.foxclient.util; + +import net.foxes4life.konfig.data.KonfigCategory; +import net.foxes4life.konfig.data.KonfigEntry; +import net.minecraft.text.MutableText; +import net.minecraft.text.TranslatableTextContent; + +public class ConfigUtils { + public static MutableText translatableEntry (KonfigCategory c, KonfigEntry e) { + return TextUtils.translatable("foxclient.config." + c.catName + "." + e.entryName); + } + + public static MutableText translatableCategory (KonfigCategory c) { + return TextUtils.translatable("foxclient.config." + c.catName); + } +} diff --git a/src/main/java/net/foxes4life/foxclient/util/UwUfyUtils.java b/src/main/java/net/foxes4life/foxclient/util/UwUfyUtils.java index 3f6e372..ccba136 100644 --- a/src/main/java/net/foxes4life/foxclient/util/UwUfyUtils.java +++ b/src/main/java/net/foxes4life/foxclient/util/UwUfyUtils.java @@ -4,7 +4,7 @@ public class UwUfyUtils { public static String uwufy(String in) { - if(!Main.config_instance.getBoolean("eastereggs", "owo")) + if(!(boolean)Main.konfig.get("eastereggs", "owo")) return in; in = in diff --git a/src/main/resources/assets/minecraft/lang/en_us.json b/src/main/resources/assets/minecraft/lang/en_us.json index f856c60..2984f00 100644 --- a/src/main/resources/assets/minecraft/lang/en_us.json +++ b/src/main/resources/assets/minecraft/lang/en_us.json @@ -38,5 +38,27 @@ "foxclient.rpc.state.lan": "Playing on a LAN game", "foxclient.rpc.state.multiplayer": "Playing on %s", "foxclient.rpc.state.multiplayer.hide_ip": "Playing Multiplayer", - "foxclient.rpc.state.realms": "Playing on a Realm" + "foxclient.rpc.state.realms": "Playing on a Realm", + + "foxclient.config.ingame-hud": "In-Game HUD", + "foxclient.config.client": "Client", + "foxclient.config.eastereggs": "EasterEggs", + "foxclient.config.menus": "Custom Menus", + "foxclient.config.misc": "Miscellaneous", + + "foxclient.config.ingame-hud.ping": "Ping", + "foxclient.config.ingame-hud.tps": "TPS", + "foxclient.config.ingame-hud.fps": "FPS", + "foxclient.config.ingame-hud.version": "Version", + "foxclient.config.ingame-hud.coords": "XYZ", + + "foxclient.config.client.hud-enabled" : "Enable In-Game HUD", + + "foxclient.config.eastereggs.owo": "OwO", + + "foxclient.config.menus.mainmenu": "Main Menu", + "foxclient.config.menus.pause": "Pause Menu", + + "foxclient.config.misc.discord-rpc": "DiscordRPC - Enabled", + "foxclient.config.misc.discord-rpc-show-ip": "DiscordRPC - Show IP" }