From 4eae9e9827332b9e332c4ad909bbcebfae8da0fb Mon Sep 17 00:00:00 2001 From: I-No-oNe <145749961+I-No-oNe@users.noreply.github.com> Date: Sat, 22 Aug 2026 23:24:34 +0300 Subject: [PATCH] refactor(input): use platform input API --- .../clickcrystals/ClickCrystals.java | 8 +- .../clickcrystals/gui/GuiScreen.java | 14 +-- .../module/KeybindSettingElement.java | 9 +- .../gui/elements/common/Typeable.java | 8 +- .../common/interactive/TextFieldElement.java | 48 +++++----- .../clickcrystals/gui/screens/HomeScreen.java | 4 +- .../modulescreen/ScriptsBrowsingScreen.java | 4 +- .../gui/screens/profiles/ProfilesScreen.java | 4 +- .../scripts/ClickScriptAutocomplete.java | 10 +-- .../gui/screens/scripts/ClickScriptIDE.java | 8 +- .../modules/keybinds/Keybind.java | 87 +++++++++---------- .../modules/modules/misc/GuiCursor.java | 8 +- .../modules/modules/misc/MsgResend.java | 6 +- .../modules/modules/misc/Zoom.java | 4 +- 14 files changed, 105 insertions(+), 117 deletions(-) diff --git a/src/main/java/io/github/itzispyder/clickcrystals/ClickCrystals.java b/src/main/java/io/github/itzispyder/clickcrystals/ClickCrystals.java index 198d7a85e..923b4fbe6 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/ClickCrystals.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/ClickCrystals.java @@ -61,7 +61,7 @@ import net.minecraft.client.gui.screens.TitleScreen; import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen; import net.minecraft.client.gui.screens.worldselection.SelectWorldScreen; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; /** * ClickCrystals main @@ -98,7 +98,7 @@ public final class ClickCrystals implements ModInitializer, Global { @SuppressWarnings("unused") public static final Keybind openModuleKeybind = Keybind.create() .id("open-clickcrystals-module-screen") - .defaultKey(GLFW.GLFW_KEY_APOSTROPHE) + .defaultKey(InputConstants.KEY_APOSTROPHE) .condition((bind, screen) -> screen == null || screen instanceof TitleScreen || screen instanceof JoinMultiplayerScreen || screen instanceof SelectWorldScreen) .onPress(bind -> UserInputListener.openPreviousScreen()) .onChange(config::saveKeybind) @@ -107,7 +107,7 @@ public final class ClickCrystals implements ModInitializer, Global { @SuppressWarnings("unused") public static final Keybind openHudEditorKeybind = Keybind.create() .id("open-hud-editor-screen") - .defaultKey(GLFW.GLFW_KEY_SEMICOLON) + .defaultKey(InputConstants.KEY_SEMICOLON) .condition((bind, screen) -> screen == null) .onPress(bind -> { if (Module.isEnabled(InGameHuds.class)) { @@ -122,7 +122,7 @@ public final class ClickCrystals implements ModInitializer, Global { @SuppressWarnings("unused") public static final Keybind commandPrefix = Keybind.create() .id("command-prefix") - .defaultKey(GLFW.GLFW_KEY_COMMA) + .defaultKey(InputConstants.KEY_COMMA) .condition((bind, screen) -> screen == null) .onPress(bind -> mc.gui.setScreen(new ChatScreen("", false))) .onChange(config::saveKeybind) diff --git a/src/main/java/io/github/itzispyder/clickcrystals/gui/GuiScreen.java b/src/main/java/io/github/itzispyder/clickcrystals/gui/GuiScreen.java index 52c7bfa55..2ede08e80 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/gui/GuiScreen.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/gui/GuiScreen.java @@ -17,7 +17,7 @@ import net.minecraft.client.input.MouseButtonEvent; import net.minecraft.client.renderer.RenderPipelines; import net.minecraft.network.chat.Component; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; import java.util.ArrayList; import java.util.ConcurrentModificationException; @@ -238,13 +238,13 @@ public boolean keyPressed(KeyEvent input) { int scanCode = input.scancode(); int modifiers = input.modifiers(); - if (keyCode == GLFW.GLFW_KEY_LEFT_SHIFT || keyCode == GLFW.GLFW_KEY_RIGHT_SHIFT) { + if (keyCode == InputConstants.KEY_LSHIFT || keyCode == InputConstants.KEY_RSHIFT) { this.shiftKeyPressed = true; } - else if (keyCode == GLFW.GLFW_KEY_LEFT_ALT || keyCode == GLFW.GLFW_KEY_RIGHT_ALT) { + else if (keyCode == InputConstants.KEY_LALT || keyCode == InputConstants.KEY_RALT) { this.altKeyPressed = true; } - else if (keyCode == GLFW.GLFW_KEY_LEFT_CONTROL || keyCode == GLFW.GLFW_KEY_RIGHT_CONTROL) { + else if (keyCode == InputConstants.KEY_LCONTROL || keyCode == InputConstants.KEY_RCONTROL) { this.ctrlKeyPressed = true; } @@ -265,13 +265,13 @@ public boolean keyReleased(KeyEvent input) { int scanCode = input.scancode(); int modifiers = input.modifiers(); - if (keyCode == GLFW.GLFW_KEY_LEFT_SHIFT || keyCode == GLFW.GLFW_KEY_RIGHT_SHIFT) { + if (keyCode == InputConstants.KEY_LSHIFT || keyCode == InputConstants.KEY_RSHIFT) { this.shiftKeyPressed = false; } - else if (keyCode == GLFW.GLFW_KEY_LEFT_ALT || keyCode == GLFW.GLFW_KEY_RIGHT_ALT) { + else if (keyCode == InputConstants.KEY_LALT || keyCode == InputConstants.KEY_RALT) { this.altKeyPressed = false; } - else if (keyCode == GLFW.GLFW_KEY_LEFT_CONTROL || keyCode == GLFW.GLFW_KEY_RIGHT_CONTROL) { + else if (keyCode == InputConstants.KEY_LCONTROL || keyCode == InputConstants.KEY_RCONTROL) { this.ctrlKeyPressed = false; } diff --git a/src/main/java/io/github/itzispyder/clickcrystals/gui/elements/browsingmode/module/KeybindSettingElement.java b/src/main/java/io/github/itzispyder/clickcrystals/gui/elements/browsingmode/module/KeybindSettingElement.java index 4f4f0a6b3..ea3855797 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/gui/elements/browsingmode/module/KeybindSettingElement.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/gui/elements/browsingmode/module/KeybindSettingElement.java @@ -7,7 +7,7 @@ import io.github.itzispyder.clickcrystals.modules.settings.KeybindSetting; import io.github.itzispyder.clickcrystals.util.minecraft.render.RenderUtils; import net.minecraft.client.gui.GuiGraphicsExtractor; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; import java.util.function.Function; @@ -15,13 +15,11 @@ public class KeybindSettingElement extends SettingElement implem private final KeybindSetting setting; private String display; - private int currentScanCode; public KeybindSettingElement(KeybindSetting setting, int x, int y) { super(setting, x, y); this.setting = setting; this.display = null; - this.currentScanCode = 42; } @Override @@ -54,8 +52,7 @@ public void mouseClicked(double mouseX, double mouseY, int button) { @Override public boolean onKey(int key, int scanCode) { if (mc.gui.screen() instanceof GuiScreen screen) { - setting.setKey(key == GLFW.GLFW_KEY_ESCAPE ? Keybind.NONE : key); - currentScanCode = scanCode; + setting.setKey(key == InputConstants.KEY_ESCAPE ? Keybind.NONE : key); screen.selected = null; } return true; @@ -72,7 +69,7 @@ public String getDisplay() { public void updateDisplay() { int key = setting.getKey(); - String name = GLFW.glfwGetKeyName(key, currentScanCode); + String name = InputConstants.Type.KEYSYM.getOrCreate(key).getDisplayName().getString(); if (name == null || Keybind.EXTRAS.containsKey(key)) { name = Keybind.EXTRAS.get(key); diff --git a/src/main/java/io/github/itzispyder/clickcrystals/gui/elements/common/Typeable.java b/src/main/java/io/github/itzispyder/clickcrystals/gui/elements/common/Typeable.java index 7a343f196..89190d894 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/gui/elements/common/Typeable.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/gui/elements/common/Typeable.java @@ -2,7 +2,7 @@ import io.github.itzispyder.clickcrystals.Global; import io.github.itzispyder.clickcrystals.gui.GuiScreen; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; import java.util.function.Function; @@ -12,17 +12,17 @@ default boolean onKey(int key, int scan) { if (!(mc.gui.screen() instanceof GuiScreen screen)) return false; - if (key == GLFW.GLFW_KEY_ESCAPE) { + if (key == InputConstants.KEY_ESCAPE) { screen.selected = null; return true; } - else if (key == GLFW.GLFW_KEY_BACKSPACE) { + else if (key == InputConstants.KEY_BACKSPACE) { onInput(input -> input.isEmpty() ? input : input.substring(0, input.length() - 1)); return true; } - else if (key == GLFW.GLFW_KEY_V && screen.ctrlKeyPressed) { + else if (key == InputConstants.KEY_V && screen.ctrlKeyPressed) { onInput(input -> input.concat(mc.keyboardHandler.getClipboard())); return true; } diff --git a/src/main/java/io/github/itzispyder/clickcrystals/gui/elements/common/interactive/TextFieldElement.java b/src/main/java/io/github/itzispyder/clickcrystals/gui/elements/common/interactive/TextFieldElement.java index 1e9289f65..84b230c4c 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/gui/elements/common/interactive/TextFieldElement.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/gui/elements/common/interactive/TextFieldElement.java @@ -12,7 +12,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; import net.minecraft.util.FormattedCharSequence; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; import java.awt.*; import java.util.ArrayDeque; @@ -233,12 +233,12 @@ public boolean onKey(int key, int scan) { if (keyInterceptor != null && keyInterceptor.apply(key)) return true; boolean handled = handleKeyInner(key, screen); // Only typing (character entry, backspace, delete) should surface autocomplete; copy/paste/navigation dismiss it. - if (handled) fireChanged(key == GLFW.GLFW_KEY_BACKSPACE || key == GLFW.GLFW_KEY_DELETE); + if (handled) fireChanged(key == InputConstants.KEY_BACKSPACE || key == InputConstants.KEY_DELETE); return handled; } private boolean handleKeyInner(int key, GuiScreen screen) { - if (key == GLFW.GLFW_KEY_ESCAPE) { + if (key == InputConstants.KEY_ESCAPE) { if (hasRange() || selectedAll) { selectedAll = false; selectionEnd = selectionStart; @@ -251,17 +251,17 @@ private boolean handleKeyInner(int key, GuiScreen screen) { // Ctrl combos if (screen.ctrlKeyPressed) { switch (key) { - case GLFW.GLFW_KEY_A -> { + case InputConstants.KEY_A -> { selectedAll = true; preferredCol = -1; return true; } - case GLFW.GLFW_KEY_C -> { + case InputConstants.KEY_C -> { if (selectedAll) mc.keyboardHandler.setClipboard(content); else if (hasRange()) mc.keyboardHandler.setClipboard(content.substring(selMin(), selMax())); return true; } - case GLFW.GLFW_KEY_X -> { + case InputConstants.KEY_X -> { if (selectedAll) { mc.keyboardHandler.setClipboard(content); clear(); @@ -272,14 +272,14 @@ private boolean handleKeyInner(int key, GuiScreen screen) { preferredCol = -1; return true; } - case GLFW.GLFW_KEY_V -> { + case InputConstants.KEY_V -> { if (hasRange() || selectedAll) deleteRange(); onInput(input -> insertInput(mc.keyboardHandler.getClipboard())); shiftRight(); preferredCol = -1; return true; } - case GLFW.GLFW_KEY_Z -> { + case InputConstants.KEY_Z -> { if (!undoStack.isEmpty()) { redoStack.push(Pair.of(content, selectionStart)); Pair state = undoStack.pop(); @@ -291,7 +291,7 @@ private boolean handleKeyInner(int key, GuiScreen screen) { preferredCol = -1; return true; } - case GLFW.GLFW_KEY_Y -> { + case InputConstants.KEY_Y -> { if (!redoStack.isEmpty()) { undoStack.push(Pair.of(content, selectionStart)); Pair state = redoStack.pop(); @@ -303,7 +303,7 @@ private boolean handleKeyInner(int key, GuiScreen screen) { preferredCol = -1; return true; } - case GLFW.GLFW_KEY_D -> { + case InputConstants.KEY_D -> { int ls = lineStart(selectionStart); int le = lineEnd(selectionStart); String line = content.substring(ls, le); @@ -316,24 +316,24 @@ private boolean handleKeyInner(int key, GuiScreen screen) { preferredCol = -1; return true; } - case GLFW.GLFW_KEY_SLASH -> { + case InputConstants.KEY_SLASH -> { return toggleComment(); } - case GLFW.GLFW_KEY_LEFT -> { + case InputConstants.KEY_LEFT -> { selectionStart = selectionEnd = prevWordBoundary(selectionStart); selectedAll = false; updateSelection(); preferredCol = -1; return true; } - case GLFW.GLFW_KEY_RIGHT -> { + case InputConstants.KEY_RIGHT -> { selectionStart = selectionEnd = nextWordBoundary(selectionStart); selectedAll = false; updateSelection(); preferredCol = -1; return true; } - case GLFW.GLFW_KEY_BACKSPACE -> { + case InputConstants.KEY_BACKSPACE -> { if (hasRange() || selectedAll) { deleteRange(); preferredCol = -1; @@ -355,7 +355,7 @@ private boolean handleKeyInner(int key, GuiScreen screen) { // Basic keys switch (key) { - case GLFW.GLFW_KEY_BACKSPACE -> { + case InputConstants.KEY_BACKSPACE -> { if (hasRange() || selectedAll) { deleteRange(); preferredCol = -1; @@ -381,7 +381,7 @@ private boolean handleKeyInner(int key, GuiScreen screen) { preferredCol = -1; return true; } - case GLFW.GLFW_KEY_DELETE -> { + case InputConstants.KEY_DELETE -> { if (hasRange() || selectedAll) { deleteRange(); preferredCol = -1; @@ -391,7 +391,7 @@ private boolean handleKeyInner(int key, GuiScreen screen) { preferredCol = -1; return true; } - case GLFW.GLFW_KEY_ENTER -> { + case InputConstants.KEY_RETURN -> { if (hasRange() || selectedAll) deleteRange(); int ls = lineStart(selectionStart); String before = content.substring(ls, selectionStart); @@ -420,14 +420,14 @@ private boolean handleKeyInner(int key, GuiScreen screen) { preferredCol = -1; return true; } - case GLFW.GLFW_KEY_TAB -> { + case InputConstants.KEY_TAB -> { if (hasRange() || selectedAll) deleteRange(); onInput(input -> insertInput(" ")); for (int i = 0; i < 4; i++) shiftRight(); preferredCol = -1; return true; } - case GLFW.GLFW_KEY_LEFT -> { + case InputConstants.KEY_LEFT -> { if (hasRange() || selectedAll) { selectionStart = selectionEnd = selMin(); selectedAll = false; @@ -436,7 +436,7 @@ private boolean handleKeyInner(int key, GuiScreen screen) { preferredCol = -1; return true; } - case GLFW.GLFW_KEY_RIGHT -> { + case InputConstants.KEY_RIGHT -> { if (hasRange() || selectedAll) { selectionStart = selectionEnd = selMax(); selectedAll = false; @@ -445,25 +445,25 @@ private boolean handleKeyInner(int key, GuiScreen screen) { preferredCol = -1; return true; } - case GLFW.GLFW_KEY_HOME -> { + case InputConstants.KEY_HOME -> { selectionStart = selectionEnd = lineStart(selectionStart); selectedAll = false; updateSelection(); preferredCol = -1; return true; } - case GLFW.GLFW_KEY_END -> { + case InputConstants.KEY_END -> { selectionStart = selectionEnd = lineEnd(selectionStart); selectedAll = false; updateSelection(); preferredCol = -1; return true; } - case GLFW.GLFW_KEY_UP -> { + case InputConstants.KEY_UP -> { navigateVertical(-1); return true; } - case GLFW.GLFW_KEY_DOWN -> { + case InputConstants.KEY_DOWN -> { navigateVertical(1); return true; } diff --git a/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/HomeScreen.java b/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/HomeScreen.java index ef63b261c..5d84bbc22 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/HomeScreen.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/HomeScreen.java @@ -16,7 +16,7 @@ import net.minecraft.client.gui.GuiGraphicsExtractor; import net.minecraft.client.input.KeyEvent; import net.minecraft.client.input.MouseButtonEvent; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; import java.util.ArrayList; import java.util.List; @@ -113,7 +113,7 @@ public void resize(int width, int height) { @Override public boolean keyPressed(KeyEvent e) { super.keyPressed(e); - if (e.input() == GLFW.GLFW_KEY_ENTER && this.selected == searchBar && !searchBar.getQuery().isEmpty()) { + if (e.input() == InputConstants.KEY_RETURN && this.selected == searchBar && !searchBar.getQuery().isEmpty()) { mc.gui.setScreen(new SearchScreen() {{ this.searchbar.setQuery(HomeScreen.this.searchBar.getQuery()); this.filterByQuery(this.searchbar); diff --git a/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/modulescreen/ScriptsBrowsingScreen.java b/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/modulescreen/ScriptsBrowsingScreen.java index da3dd8323..62594e085 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/modulescreen/ScriptsBrowsingScreen.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/modulescreen/ScriptsBrowsingScreen.java @@ -20,7 +20,7 @@ import io.github.itzispyder.clickcrystals.util.minecraft.PlayerUtils; import io.github.itzispyder.clickcrystals.util.minecraft.render.RenderUtils; import net.minecraft.client.gui.GuiGraphicsExtractor; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; import java.io.File; import java.util.Comparator; @@ -297,7 +297,7 @@ private static class ScriptCreateNew extends ModuleElement { @Override public boolean onKey(int key, int scancode) { - if (key != GLFW.GLFW_KEY_ENTER) + if (key != InputConstants.KEY_RETURN) return super.onKey(key, scancode); if (!(mc.gui.screen() instanceof GuiScreen screen)) return true; diff --git a/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/profiles/ProfilesScreen.java b/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/profiles/ProfilesScreen.java index 517cae932..aae2dc0e7 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/profiles/ProfilesScreen.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/profiles/ProfilesScreen.java @@ -11,7 +11,7 @@ import io.github.itzispyder.clickcrystals.util.StringUtils; import io.github.itzispyder.clickcrystals.util.minecraft.render.RenderUtils; import net.minecraft.client.gui.GuiGraphicsExtractor; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; public class ProfilesScreen extends DefaultBase { @@ -121,7 +121,7 @@ private static class ProfileCreateNew extends ModuleElement { @Override public boolean onKey(int key, int scancode) { - if (key != GLFW.GLFW_KEY_ENTER) + if (key != InputConstants.KEY_RETURN) return super.onKey(key, scancode); if (!(mc.gui.screen() instanceof GuiScreen screen)) return true; diff --git a/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/scripts/ClickScriptAutocomplete.java b/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/scripts/ClickScriptAutocomplete.java index f0a0139fb..eed10d851 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/scripts/ClickScriptAutocomplete.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/scripts/ClickScriptAutocomplete.java @@ -19,7 +19,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; import net.minecraft.world.level.GameType; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; import java.util.*; @@ -297,15 +297,15 @@ private static List firstArgPool(String cmd, int idx) { public boolean onKey(int key) { if (!visible) return false; return switch (key) { - case GLFW.GLFW_KEY_UP -> { + case InputConstants.KEY_UP -> { selectedIndex = (selectedIndex - 1 + suggestions.size()) % suggestions.size(); yield true; } - case GLFW.GLFW_KEY_DOWN -> { + case InputConstants.KEY_DOWN -> { selectedIndex = (selectedIndex + 1) % suggestions.size(); yield true; } - case GLFW.GLFW_KEY_ESCAPE -> { + case InputConstants.KEY_ESCAPE -> { visible = false; yield true; } @@ -314,7 +314,7 @@ public boolean onKey(int key) { } public boolean isInsertKey(int key) { - return visible && (key == GLFW.GLFW_KEY_TAB || key == GLFW.GLFW_KEY_ENTER); + return visible && (key == InputConstants.KEY_TAB || key == InputConstants.KEY_RETURN); } public String getSelected() { diff --git a/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/scripts/ClickScriptIDE.java b/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/scripts/ClickScriptIDE.java index e6349e147..3ecef5a9e 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/scripts/ClickScriptIDE.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/gui/screens/scripts/ClickScriptIDE.java @@ -31,7 +31,7 @@ import io.github.itzispyder.clickcrystals.util.misc.Voidable; import net.minecraft.client.gui.GuiGraphicsExtractor; import net.minecraft.network.chat.Component; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; import java.io.*; import java.util.Arrays; @@ -122,7 +122,7 @@ public ClickScriptIDE(File file) { this.removeChild(buttonSearch); textField.setKeyInterceptor(key -> { - if (key == GLFW.GLFW_KEY_ESCAPE && showKeybinds) { + if (key == InputConstants.KEY_ESCAPE && showKeybinds) { showKeybinds = false; return true; } @@ -135,7 +135,7 @@ public ClickScriptIDE(File file) { return true; } } - if (key == GLFW.GLFW_KEY_S && ctrlKeyPressed) { + if (key == InputConstants.KEY_S && ctrlKeyPressed) { saveContents(); return true; } @@ -414,4 +414,4 @@ public void deleteScript() { public void resize(int width, int height) { mc.gui.setScreen(new ClickScriptIDE(currentFile)); } -} \ No newline at end of file +} diff --git a/src/main/java/io/github/itzispyder/clickcrystals/modules/keybinds/Keybind.java b/src/main/java/io/github/itzispyder/clickcrystals/modules/keybinds/Keybind.java index f0c54c0e7..8638a4c0e 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/modules/keybinds/Keybind.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/modules/keybinds/Keybind.java @@ -3,7 +3,7 @@ import io.github.itzispyder.clickcrystals.Global; import io.github.itzispyder.clickcrystals.util.StringUtils; import io.github.itzispyder.clickcrystals.util.misc.ManualMap; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; import java.awt.event.KeyEvent; import java.util.Map; @@ -13,42 +13,42 @@ public class Keybind implements Global { public static final int DEFAULT_SCANCODE = 42; public static final int NONE = -1; public static final Map EXTRAS = ManualMap.fromItems( - GLFW.GLFW_KEY_LEFT_SHIFT, "LS", - GLFW.GLFW_KEY_RIGHT_SHIFT, "RS", - GLFW.GLFW_KEY_LEFT_ALT, "LA", - GLFW.GLFW_KEY_RIGHT_ALT, "RA", - GLFW.GLFW_KEY_LEFT_CONTROL, "LC", - GLFW.GLFW_KEY_RIGHT_CONTROL, "RC", - GLFW.GLFW_KEY_PAGE_DOWN, "P⇧", - GLFW.GLFW_KEY_PAGE_UP, "P⇩", - GLFW.GLFW_KEY_UP, "⇧", - GLFW.GLFW_KEY_DOWN, "⇩", - GLFW.GLFW_KEY_LEFT, "⇦", - GLFW.GLFW_KEY_RIGHT, "⇨" + InputConstants.KEY_LSHIFT, "LS", + InputConstants.KEY_RSHIFT, "RS", + InputConstants.KEY_LALT, "LA", + InputConstants.KEY_RALT, "RA", + InputConstants.KEY_LCONTROL, "LC", + InputConstants.KEY_RCONTROL, "RC", + InputConstants.KEY_PAGEDOWN, "P⇧", + InputConstants.KEY_PAGEUP, "P⇩", + InputConstants.KEY_UP, "⇧", + InputConstants.KEY_DOWN, "⇩", + InputConstants.KEY_LEFT, "⇦", + InputConstants.KEY_RIGHT, "⇨" ); public static final Map EXTENDED_NAMES = ManualMap.fromItems( - GLFW.GLFW_KEY_LEFT_SHIFT, "left_shift", - GLFW.GLFW_KEY_RIGHT_SHIFT, "right_shift", - GLFW.GLFW_KEY_LEFT_ALT, "left_alt", - GLFW.GLFW_KEY_RIGHT_ALT, "right_alt", - GLFW.GLFW_KEY_LEFT_CONTROL, "left_control", - GLFW.GLFW_KEY_RIGHT_CONTROL, "right_control", - GLFW.GLFW_KEY_PAGE_DOWN, "page_down", - GLFW.GLFW_KEY_PAGE_UP, "page_up", - GLFW.GLFW_KEY_UP, "up_arrow", - GLFW.GLFW_KEY_DOWN, "down_arrow", - GLFW.GLFW_KEY_LEFT, "left_arrow", - GLFW.GLFW_KEY_RIGHT, "right_arrow", - GLFW.GLFW_KEY_ESCAPE, "escape", - GLFW.GLFW_KEY_BACKSPACE, "backspace", - GLFW.GLFW_KEY_INSERT, "insert", - GLFW.GLFW_KEY_DELETE, "delete", - GLFW.GLFW_KEY_HOME, "home", - GLFW.GLFW_KEY_END, "end", - GLFW.GLFW_KEY_TAB, "tab", - GLFW.GLFW_KEY_CAPS_LOCK, "capslock", - GLFW.GLFW_KEY_SPACE, "space", - GLFW.GLFW_KEY_ENTER, "enter" + InputConstants.KEY_LSHIFT, "left_shift", + InputConstants.KEY_RSHIFT, "right_shift", + InputConstants.KEY_LALT, "left_alt", + InputConstants.KEY_RALT, "right_alt", + InputConstants.KEY_LCONTROL, "left_control", + InputConstants.KEY_RCONTROL, "right_control", + InputConstants.KEY_PAGEDOWN, "page_down", + InputConstants.KEY_PAGEUP, "page_up", + InputConstants.KEY_UP, "up_arrow", + InputConstants.KEY_DOWN, "down_arrow", + InputConstants.KEY_LEFT, "left_arrow", + InputConstants.KEY_RIGHT, "right_arrow", + InputConstants.KEY_ESCAPE, "escape", + InputConstants.KEY_BACKSPACE, "backspace", + InputConstants.KEY_INSERT, "insert", + InputConstants.KEY_DELETE, "delete", + InputConstants.KEY_HOME, "home", + InputConstants.KEY_END, "end", + InputConstants.KEY_TAB, "tab", + InputConstants.KEY_CAPSLOCK, "capslock", + InputConstants.KEY_SPACE, "space", + InputConstants.KEY_RETURN, "enter" ); private final String name, id; private int key, defaultKey; @@ -73,7 +73,7 @@ public void onPress() { } public boolean canPress(int keyCode, int scanCode) { - boolean notNull = GLFW.glfwGetKeyName(key, scanCode) != null; + boolean notNull = InputConstants.Type.KEYSYM.getOrCreate(key) != InputConstants.UNKNOWN; boolean isExtra = EXTRAS.containsKey(key); boolean isKey = keyCode == key; return (notNull || isExtra) && isKey; @@ -92,24 +92,15 @@ public int getKey() { } public String getKeyName() { - // glfwGetKeyName renames printable keys after the system layout, key code stays put - if (key >= GLFW.GLFW_KEY_APOSTROPHE && key <= GLFW.GLFW_KEY_GRAVE_ACCENT) { + if (key >= InputConstants.KEY_APOSTROPHE && key <= InputConstants.KEY_GRAVE) { return String.valueOf((char)key).toLowerCase(); } - String name = GLFW.glfwGetKeyName(key, 32); - if (name == null) { - name = EXTRAS.getOrDefault(key, "NONE"); - } - return name; + return EXTRAS.getOrDefault(key, InputConstants.Type.KEYSYM.getOrCreate(key).getDisplayName().getString()); } public static String getExtendedKeyName(int key, int scancode) { - String name = GLFW.glfwGetKeyName(key, scancode); - if (name == null) { - name = EXTENDED_NAMES.get(key); - } - return name; + return EXTENDED_NAMES.getOrDefault(key, InputConstants.Type.KEYSYM.getOrCreate(key).getDisplayName().getString()); } public static int fromExtendedKeyName(String name) { diff --git a/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/misc/GuiCursor.java b/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/misc/GuiCursor.java index 2ab5124f3..09daa1b8e 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/misc/GuiCursor.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/misc/GuiCursor.java @@ -21,7 +21,7 @@ import net.minecraft.world.inventory.ContainerInput; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; import java.awt.*; import java.util.ArrayList; @@ -86,9 +86,9 @@ public static void setCursor(int x, int y) { Window win = mc.getWindow(); double ratW = (double) win.getGuiScaledWidth() / win.getScreenWidth(); double ratH = (double) win.getGuiScaledHeight() / win.getScreenHeight(); - GLFW.glfwSetCursorPos(win.handle(), x / ratW, y / ratH); + InputConstants.grabOrReleaseMouse(win, InputConstants.CURSOR_NORMAL, x / ratW, y / ratH); // Update internal mouse state directly for Wayland compatibility, - // where glfwSetCursorPos silently fails in normal cursor mode + // where cursor positioning silently fails in normal cursor mode ((AccessorMouseHandler) mc.mouseHandler).clickCrystals$setCursorPos(x / ratW, y / ratH); } @@ -163,7 +163,7 @@ private void onTick(ClientTickStartEvent e) { @EventHandler private void onKey(KeyPressEvent e) { - if (e.getKeycode() == GLFW.GLFW_KEY_LEFT_SHIFT) + if (e.getKeycode() == InputConstants.KEY_LSHIFT) shiftKeyDown = e.getAction().isDown(); } diff --git a/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/misc/MsgResend.java b/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/misc/MsgResend.java index 0fd08fca0..e0a45b949 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/misc/MsgResend.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/misc/MsgResend.java @@ -11,7 +11,7 @@ import io.github.itzispyder.clickcrystals.modules.settings.SettingSection; import io.github.itzispyder.clickcrystals.util.minecraft.ChatUtils; import io.github.itzispyder.clickcrystals.util.misc.Voidable; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; public class MsgResend extends ListenerModule { @@ -25,7 +25,7 @@ public class MsgResend extends ListenerModule { public final ModuleSetting resendKeybind = scGeneral.add(KeybindSetting.create() .name("message-resend-keybind") .description("Key to resend last message/command.") - .def(GLFW.GLFW_KEY_UP) + .def(InputConstants.KEY_UP) .onPress(bind -> this.resendMessage()) .condition((bind, screen) -> screen == null) .build() @@ -63,4 +63,4 @@ public void resendMessage() { else lastMessage.accept(ChatUtils::sendChatMessage); } -} \ No newline at end of file +} diff --git a/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/misc/Zoom.java b/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/misc/Zoom.java index 168e63619..528df0d9b 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/misc/Zoom.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/misc/Zoom.java @@ -12,7 +12,7 @@ import io.github.itzispyder.clickcrystals.modules.settings.DoubleSetting; import io.github.itzispyder.clickcrystals.modules.settings.KeybindSetting; import io.github.itzispyder.clickcrystals.modules.settings.SettingSection; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; public class Zoom extends Module implements Listener { @@ -28,7 +28,7 @@ public class Zoom extends Module implements Listener { public final ModuleSetting keybind = scGeneral.add(KeybindSetting.create() .name("zoom-key") .description("Keybind to activate zoom.") - .def(GLFW.GLFW_KEY_B) + .def(InputConstants.KEY_B) .build() ); public final ModuleSetting scrollToChange = scGeneral.add(BooleanSetting.create()