summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
author alemidev <me@alemi.dev>2023-01-30 23:35:32 +0100
committer alemidev <me@alemi.dev>2023-01-30 23:35:32 +0100
commit5e0ec6d4aa35a5563f1f4f3e925fe84e4460bf6e (patch)
tree5a6e24d1a8da113a6049b677e6789a4b69eec651 /src/main/java
parent867a5f5f622c6a4c969ef43f16e99949169ec6f4 (diff)
feat: added QuickModule with a toggle keybind
awful name but eeehh
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/co/fantabos/bscv/module/QuickModule.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main/java/co/fantabos/bscv/module/QuickModule.java b/src/main/java/co/fantabos/bscv/module/QuickModule.java
new file mode 100644
index 0000000..4942476
--- /dev/null
+++ b/src/main/java/co/fantabos/bscv/module/QuickModule.java
@@ -0,0 +1,61 @@
+package co.fantabos.bscv.module;
+
+import com.mojang.brigadier.CommandDispatcher;
+
+import net.minecraft.client.settings.KeyBinding;
+import net.minecraft.command.CommandSource;
+import net.minecraftforge.client.event.InputEvent;
+import net.minecraftforge.common.ForgeConfigSpec;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.eventbus.api.SubscribeEvent;
+import net.minecraftforge.fml.client.registry.ClientRegistry;
+import co.fantabos.bscv.BoSCoVicino;
+
+// TODO rename
+public class QuickModule extends Module {
+
+ private class ToggleHook {
+ private final KeyBinding key;
+ private final Module mod;
+ protected ToggleHook(KeyBinding key, Module mod) {
+ this.key = key;
+ this.mod = mod;
+ }
+
+ @SubscribeEvent
+ public void onKeyPress(InputEvent.KeyInputEvent event) {
+ if (this.key.isDown()) {
+ this.mod.toggle();
+ }
+ }
+
+ @SubscribeEvent
+ public void onKeyPress(InputEvent.MouseInputEvent event) {
+ if (this.key.isDown()) {
+ this.mod.toggle();
+
+ }
+ }
+ }
+
+ public final KeyBinding keybind;
+
+ public QuickModule(String name, Group group, int default_key, ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
+ super(name, group, builder, dispatcher);
+
+ this.keybind = new KeyBinding(key_name(name), default_key, key_category());
+ ClientRegistry.registerKeyBinding(this.keybind);
+
+ // register a separate subclass on the hook, so that it's always listening
+ MinecraftForge.EVENT_BUS.register(new ToggleHook(this.keybind, this));
+ }
+
+ private static String key_name(String name) {
+ return String.format("key.%s.%s", BoSCoVicino.MOD_ID, name);
+ }
+
+ private static String key_category() {
+ return String.format("key.category.%s", BoSCoVicino.MOD_ID);
+ }
+
+}