From 2ea463b870152586428c14fbbc5bdb60a232ca4f Mon Sep 17 00:00:00 2001 From: Elis Eriksson Date: Sun, 23 Nov 2025 15:50:13 +0100 Subject: add compatibility i guess, and commit some more changes i made at some point idk --- .../spelis/valvesprint/client/KeybindCompat.java | 29 ++++++++++++++++++++++ .../valvesprint/client/ValveSprintClient.java | 11 ++------ 2 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 src/client/java/eu/projnull/spelis/valvesprint/client/KeybindCompat.java (limited to 'src/client/java/eu/projnull') diff --git a/src/client/java/eu/projnull/spelis/valvesprint/client/KeybindCompat.java b/src/client/java/eu/projnull/spelis/valvesprint/client/KeybindCompat.java new file mode 100644 index 0000000..ed7f427 --- /dev/null +++ b/src/client/java/eu/projnull/spelis/valvesprint/client/KeybindCompat.java @@ -0,0 +1,29 @@ +package eu.projnull.spelis.valvesprint.client; + +import net.minecraft.client.option.KeyBinding; +import net.minecraft.client.util.InputUtil; +import org.lwjgl.glfw.GLFW; + +import java.lang.reflect.Constructor; + +public class KeybindCompat { + + public static KeyBinding createKeybind() { + String id = "key.valvesprint.walk"; + int glfwKey = GLFW.GLFW_KEY_LEFT_SHIFT; + try { + Constructor newest = KeyBinding.class.getConstructor(String.class, InputUtil.Type.class, int.class, KeyBinding.Category.class); + return newest.newInstance(id, InputUtil.Type.KEYSYM, glfwKey, KeyBinding.Category.MOVEMENT); + } catch (NoSuchMethodException | NoClassDefFoundError e1) { + try { + Constructor old = KeyBinding.class.getConstructor(String.class, InputUtil.Type.class, int.class, String.class); + return old.newInstance(id, InputUtil.Type.KEYSYM, glfwKey, "key.categories.movement"); + } catch (Exception e2) { + throw new RuntimeException("Cannot create keybind: unsupported MC version", e2); + } + } catch (Exception ex) { + throw new RuntimeException("Failed to create keybind", ex); + } + } + +} diff --git a/src/client/java/eu/projnull/spelis/valvesprint/client/ValveSprintClient.java b/src/client/java/eu/projnull/spelis/valvesprint/client/ValveSprintClient.java index 5b79ec1..a7cf564 100644 --- a/src/client/java/eu/projnull/spelis/valvesprint/client/ValveSprintClient.java +++ b/src/client/java/eu/projnull/spelis/valvesprint/client/ValveSprintClient.java @@ -4,23 +4,16 @@ import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; -import org.lwjgl.glfw.GLFW; public class ValveSprintClient implements ClientModInitializer { - private KeyBinding walkBind = KeyBindingHelper.registerKeyBinding(new KeyBinding( - "key.valvesprint.walk", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_LEFT_SHIFT, - "key.categories.movement" - )); + private final KeyBinding walkBind = KeyBindingHelper.registerKeyBinding(KeybindCompat.createKeybind()); @Override public void onInitializeClient() { ClientTickEvents.START_CLIENT_TICK.register(client -> { if (client.player != null) { if (client.player.input.hasForwardMovement()) { - client.player.setSprinting(!walkBind.isPressed() && !client.player.isSneaking()); + client.player.setSprinting(!walkBind.isPressed()); } } }); -- cgit v1.3-7-ge9ab