diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-06-12 18:22:03 +0700 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-06-12 18:22:03 +0700 |
commit | 30ffb79a12903b15cda80f14520631d8ba4f0de7 (patch) | |
tree | fa0a4372c804fc88efa692807a5c806b72a00e20 /src/main/java/cc/polyfrost/oneconfig | |
parent | 004191f93e015c0f83dc5da65ea847641033cbdb (diff) | |
download | OneConfig-30ffb79a12903b15cda80f14520631d8ba4f0de7.tar.gz OneConfig-30ffb79a12903b15cda80f14520631d8ba4f0de7.tar.bz2 OneConfig-30ffb79a12903b15cda80f14520631d8ba4f0de7.zip |
migrate keybinds to oneconfig events
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig')
7 files changed, 29 insertions, 11 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/KeyInputEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/KeyInputEvent.java new file mode 100644 index 0000000..15056d6 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/events/event/KeyInputEvent.java @@ -0,0 +1,4 @@ +package cc.polyfrost.oneconfig.events.event; + +public class KeyInputEvent { +} diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/MouseInputEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/MouseInputEvent.java new file mode 100644 index 0000000..e2373ef --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/events/event/MouseInputEvent.java @@ -0,0 +1,4 @@ +package cc.polyfrost.oneconfig.events.event; + +public class MouseInputEvent { +} diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java index 1aa5d66..aa215a4 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java @@ -23,7 +23,7 @@ public class ConfigKeyBind extends BasicOption { super(field, parent, name, category, subcategory, size); button = new BasicButton(256, 32, "", SVGs.KEYSTROKE, null, BasicButton.ALIGNMENT_JUSTIFIED, ColorPalette.SECONDARY); button.setToggleable(true); - KeyBindHandler.addKeyBind(getKeyBind()); + KeyBindHandler.INSTANCE.addKeyBind(getKeyBind()); } public static ConfigKeyBind create(Field field, Object parent) { diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java index c3e2750..efc4324 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java @@ -13,7 +13,6 @@ import cc.polyfrost.oneconfig.internal.hud.HudCore; import cc.polyfrost.oneconfig.utils.commands.CommandManager; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.DummyModContainer; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.ModContainer; @@ -75,7 +74,7 @@ public class OneConfig { CommandManager.INSTANCE.registerCommand(OneConfigCommand.class); EventManager.INSTANCE.register(new HudCore()); EventManager.INSTANCE.register(HypixelUtils.INSTANCE); - MinecraftForge.EVENT_BUS.register(new KeyBindHandler()); + EventManager.INSTANCE.register(KeyBindHandler.INSTANCE); reloadModsList(); initialized = true; } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java index 5a9dd0b..a1084a1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java @@ -18,7 +18,7 @@ public class ConfigCore { ArrayList<Mod> data = new ArrayList<>(oneConfigMods); oneConfigMods.clear(); HudCore.huds.clear(); - KeyBindHandler.clearKeyBinds(); + KeyBindHandler.INSTANCE.clearKeyBinds(); for (Mod modData : data) { modData.config.init(modData); } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/KeyBindHandler.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/KeyBindHandler.java index da82951..6829ae4 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/KeyBindHandler.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/KeyBindHandler.java @@ -1,27 +1,28 @@ package cc.polyfrost.oneconfig.internal.config.core; import cc.polyfrost.oneconfig.config.core.OneKeyBind; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.InputEvent; +import cc.polyfrost.oneconfig.events.event.KeyInputEvent; +import cc.polyfrost.oneconfig.libs.eventbus.Subscribe; import java.util.ArrayList; public class KeyBindHandler { - private static final ArrayList<OneKeyBind> keyBinds = new ArrayList<>(); + public static final KeyBindHandler INSTANCE = new KeyBindHandler(); + private final ArrayList<OneKeyBind> keyBinds = new ArrayList<>(); - @SubscribeEvent - public void onKeyPressed(InputEvent.KeyInputEvent event) { + @Subscribe + private void onKeyPressed(KeyInputEvent event) { for (OneKeyBind keyBind : keyBinds) { if (keyBind.isActive()) keyBind.run(); } } - public static void addKeyBind(OneKeyBind keyBind) { + public void addKeyBind(OneKeyBind keyBind) { if (keyBind == null) return; keyBinds.add(keyBind); } - public static void clearKeyBinds() { + public void clearKeyBinds() { keyBinds.clear(); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java index 8a28bed..6308fdb 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java @@ -74,4 +74,14 @@ public class MinecraftMixin { private void onDeltaTickTimerUpdate(CallbackInfo ci) { EventManager.INSTANCE.post(new TimerUpdateEvent(timer, true)); } + + @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;fireKeyInput()V")) + private void onKeyEvent(CallbackInfo ci) { + EventManager.INSTANCE.post(new KeyInputEvent()); + } + + @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;fireMouseInput()V")) + private void onMouseEvent(CallbackInfo ci) { + EventManager.INSTANCE.post(new MouseInputEvent()); + } } |