Skip to content

Commit

Permalink
Add BooleanPool and update some things.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh authored Jul 24, 2024
1 parent 6ccb876 commit 6af1bcd
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Boolean> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,6 +17,11 @@ public BooleanOption(String name, Supplier<Boolean> getter, Consumer<Boolean> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,8 +26,15 @@ public RunnableOption(String name, Supplier<Boolean> getter, Consumer<Boolean> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -32,6 +33,9 @@ public SubMenuOption(String name, ContextMenu parentMenu, Supplier<Boolean> 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) {
Expand Down

0 comments on commit 6af1bcd

Please sign in to comment.