diff --git a/src/main/java/dev/c0de/minecraft/client/KeybindManager.java b/src/main/java/dev/c0de/minecraft/client/KeybindManager.java deleted file mode 100644 index 7deb7ba..0000000 --- a/src/main/java/dev/c0de/minecraft/client/KeybindManager.java +++ /dev/null @@ -1,53 +0,0 @@ -package dev.c0de.minecraft.client; - -import net.minecraft.client.MinecraftClient; - -import java.util.HashMap; -import java.util.List; -import java.util.Optional; -import java.util.TreeMap; - -public class KeybindManager { - private final HashMap states = new HashMap<>(); - private final List modules; - - public KeybindManager(List modules) { - this.modules = modules; - } - - public void tick(MinecraftClient client) { - // Execute the onTick function of each module - modules.forEach(module -> module.onTick(this, client)); - - // Toggle the module state with keybind - modules.stream().filter(module -> module.getKey() != null).forEach(module -> { - if (module.getKey().wasPressed()) { - final String name = module.getClass().getName(); - final boolean newState = states.get(name); - - c0deFoxModClient.LOGGER.info(name); - - states.put(name, !states.getOrDefault(name, false)); - - module.setState(newState); - module.onToggle(this, client); - } - }); - } - - public boolean getState(Class cls) { - return states.getOrDefault(cls.getName(), false); - } - - public TreeMap getSortedStates() { - final TreeMap keyStates = new TreeMap<>(); - - states.forEach((key, value) -> { - final Optional foundModule = modules.stream().filter(module -> module.getClass().getName().equals(key)).findFirst(); - - foundModule.ifPresent(module -> keyStates.put(module.getKey().getTranslationKey(), value)); - }); - - return keyStates; - } -} diff --git a/src/main/java/dev/c0de/minecraft/client/Module.java b/src/main/java/dev/c0de/minecraft/client/Module.java index eef4f9e..a82b312 100644 --- a/src/main/java/dev/c0de/minecraft/client/Module.java +++ b/src/main/java/dev/c0de/minecraft/client/Module.java @@ -8,12 +8,10 @@ public abstract class Module { protected KeyBinding key; protected boolean state; - public void onTick(KeybindManager manager, MinecraftClient client) { - + public void onTick(MinecraftClient client) { } - public void onToggle(KeybindManager manager, MinecraftClient client) { - + public void onToggle(MinecraftClient client) { } public void setState(boolean state) { @@ -21,10 +19,10 @@ public abstract class Module { } public KeyBinding getKey() { - return key; + return this.key; } public boolean isState() { - return state; + return this.state; } } \ No newline at end of file diff --git a/src/main/java/dev/c0de/minecraft/client/c0deFoxModClient.java b/src/main/java/dev/c0de/minecraft/client/c0deFoxModClient.java index bd2ad89..46905ce 100644 --- a/src/main/java/dev/c0de/minecraft/client/c0deFoxModClient.java +++ b/src/main/java/dev/c0de/minecraft/client/c0deFoxModClient.java @@ -7,6 +7,7 @@ import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.minecraft.client.MinecraftClient; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,23 +20,14 @@ public class c0deFoxModClient implements ClientModInitializer { public static final Logger LOGGER = LoggerFactory.getLogger("c0defox"); private static c0deFoxModClient self; - private static KeybindManager keybindManager; - // Load in modules as independent parts of the mod - private static List modules; + protected Fullbright fullbright; @Override public void onInitializeClient() { ClientTickEvents.END_CLIENT_TICK.register(this::tick); - self = this; - - // Add new modules here - modules = List.of( - new Fullbright() - ); - - keybindManager = new KeybindManager(modules); + fullbright = new Fullbright(); LOGGER.info("Ready"); } @@ -44,13 +36,9 @@ public class c0deFoxModClient implements ClientModInitializer { return self; } - public static KeybindManager getKeybindManager() { - return keybindManager; - } - // Called on every game tick public void tick(MinecraftClient client) { - keybindManager.tick(client); + fullbright.onTick(client); } } diff --git a/src/main/java/dev/c0de/minecraft/client/modules/Fullbright.java b/src/main/java/dev/c0de/minecraft/client/modules/Fullbright.java index 8b31aeb..692dbfc 100644 --- a/src/main/java/dev/c0de/minecraft/client/modules/Fullbright.java +++ b/src/main/java/dev/c0de/minecraft/client/modules/Fullbright.java @@ -3,7 +3,6 @@ package dev.c0de.minecraft.client.modules; import dev.c0de.minecraft.c0deFoxMod; import dev.c0de.minecraft.client.Module; import dev.c0de.minecraft.client.c0deFoxModClient; -import dev.c0de.minecraft.client.KeybindManager; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.MinecraftClient; @@ -21,12 +20,12 @@ public class Fullbright extends Module { "key.c0defox.fullbright", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_B, - "category.c0defox.default" + "key.categories.c0defox" )); } @Override - public void onTick(KeybindManager manager, MinecraftClient client) { + public void onTick(MinecraftClient client) { update(client, DEFAULT); if (this.isState()) { c0deFoxModClient.LOGGER.warn("Active State"); diff --git a/src/main/resources/assets/c0defox/lang/en_us.json b/src/main/resources/assets/c0defox/lang/en_us.json index 6648298..ab2de31 100644 --- a/src/main/resources/assets/c0defox/lang/en_us.json +++ b/src/main/resources/assets/c0defox/lang/en_us.json @@ -1,4 +1,4 @@ { - "category.c0defox.default": "c0de's mods", + "key.categories.c0defox": "c0de's mods", "key.c0defox.fullbright": "Fullbright" } \ No newline at end of file