diff --git a/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java b/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java index 5a010ed..756fa0c 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java +++ b/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java @@ -2,6 +2,7 @@ import com.tanishisherewith.dynamichud.config.GlobalConfig; import com.tanishisherewith.dynamichud.screens.AbstractMoveableScreen; +import com.tanishisherewith.dynamichud.utils.BooleanPool; import com.tanishisherewith.dynamichud.widget.Widget; import com.tanishisherewith.dynamichud.widget.WidgetManager; import com.tanishisherewith.dynamichud.widget.WidgetRenderer; @@ -152,18 +153,20 @@ public void onInitializeClient() { if (e instanceof IOException) { logger.warn("An error has occurred while loading widgets of mod {}", modId, e); } else { - logger.warn("Mod {} has incorrect implementation of DynamicHUD", modId, e); + logger.warn("Mod {} has improper implementation of DynamicHUD", modId, e); } } }); - printInfo("Integration of all mods found was successful"); + printInfo("(DynamicHUD) Integration of mods found was successful"); //Global config saving (YACL) ServerLifecycleEvents.SERVER_STOPPING.register(server -> GlobalConfig.HANDLER.save()); ServerLifecycleEvents.END_DATA_PACK_RELOAD.register((server, resourceManager, s) -> GlobalConfig.HANDLER.save()); ServerPlayConnectionEvents.DISCONNECT.register((handler, packetSender) -> GlobalConfig.HANDLER.save()); - ClientLifecycleEvents.CLIENT_STOPPING.register((minecraftClient) -> GlobalConfig.HANDLER.save()); + ClientLifecycleEvents.CLIENT_STOPPING.register((minecraftClient) -> { + GlobalConfig.HANDLER.save(); + }); //In game screen render. diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/BooleanPool.java b/src/main/java/com/tanishisherewith/dynamichud/utils/BooleanPool.java new file mode 100644 index 0000000..9c518b5 --- /dev/null +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/BooleanPool.java @@ -0,0 +1,19 @@ +package com.tanishisherewith.dynamichud.utils; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class BooleanPool { + private static final Map pool = new ConcurrentHashMap<>(); + + public static void put(String key, boolean value) { + pool.put(key, value); + } + public static void remove(String key) { + pool.remove(key); + } + + public static boolean get(String key) { + return pool.getOrDefault(key, false); + } +} \ No newline at end of file diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/BooleanOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/BooleanOption.java index 5b32b6b..d5ec0e4 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/BooleanOption.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/BooleanOption.java @@ -1,5 +1,6 @@ package com.tanishisherewith.dynamichud.utils.contextmenu.options; +import com.tanishisherewith.dynamichud.utils.BooleanPool; import com.tanishisherewith.dynamichud.utils.contextmenu.Option; import net.minecraft.client.gui.DrawContext; import net.minecraft.text.Text; @@ -16,6 +17,11 @@ public BooleanOption(String name, Supplier getter, Consumer se this.name = name; } + public BooleanOption(String name, boolean defaultValue) { + this(name, () -> BooleanPool.get(name), value -> BooleanPool.put(name, value)); + BooleanPool.put(name, defaultValue); + } + @Override public void render(DrawContext drawContext, int x, int y) { super.render(drawContext, x, y); diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java index 883ef92..c797189 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java @@ -1,5 +1,6 @@ package com.tanishisherewith.dynamichud.utils.contextmenu.options; +import com.tanishisherewith.dynamichud.utils.BooleanPool; import com.tanishisherewith.dynamichud.utils.contextmenu.Option; import net.minecraft.client.gui.DrawContext; import net.minecraft.text.Text; @@ -25,8 +26,15 @@ public RunnableOption(String name, Supplier getter, Consumer s this.name = "Run: " + name; // prepend the "run" symbol to the name this.task = task; } + + public RunnableOption(String name, boolean defaultValue,Runnable task) { + this(name, () -> BooleanPool.get(name), value -> BooleanPool.put(name, value),task); + BooleanPool.put(name, defaultValue); + } + Color DARK_RED = new Color(116, 0, 0); Color DARK_GREEN = new Color(24, 132, 0, 226); + @Override public void render(DrawContext drawContext, int x, int y) { super.render(drawContext, x, y); diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/SubMenuOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/SubMenuOption.java index 5d23702..07a7b0b 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/SubMenuOption.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/SubMenuOption.java @@ -1,5 +1,6 @@ package com.tanishisherewith.dynamichud.utils.contextmenu.options; +import com.tanishisherewith.dynamichud.utils.BooleanPool; import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu; import com.tanishisherewith.dynamichud.utils.contextmenu.Option; import net.minecraft.client.gui.DrawContext; @@ -32,6 +33,9 @@ public SubMenuOption(String name, ContextMenu parentMenu, Supplier gett this.subMenu.heightOffset = 0; this.subMenu.shouldDisplay = get(); } + public SubMenuOption(String name, ContextMenu parentMenu) { + this(name, parentMenu, () -> BooleanPool.get(name), value -> BooleanPool.put(name, value)); + } @Override public void render(DrawContext drawContext, int x, int y,int mouseX,int mouseY) {