diff --git a/src/main/java/com/minenash/rebind_all_the_keys/RebindAllTheKeys.java b/src/main/java/com/minenash/rebind_all_the_keys/RebindAllTheKeys.java index e7ed2d4..271a016 100644 --- a/src/main/java/com/minenash/rebind_all_the_keys/RebindAllTheKeys.java +++ b/src/main/java/com/minenash/rebind_all_the_keys/RebindAllTheKeys.java @@ -6,6 +6,7 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.option.KeyBinding; import net.minecraft.client.option.SimpleOption; import net.minecraft.client.util.InputUtil; @@ -51,6 +52,7 @@ public class RebindAllTheKeys implements ClientModInitializer { public static final KeyBinding HOTBAR_NEXT_OVERRIDE = keybind("hotbar_next_override", GLFW.GLFW_KEY_UNKNOWN, KeyBinding.INVENTORY_CATEGORY); public static final KeyBinding HOTBAR_PREVIOUS_OVERRIDE = keybind("hotbar_previous_override", GLFW.GLFW_KEY_UNKNOWN, KeyBinding.INVENTORY_CATEGORY); + public static final KeyBinding QUICK_MOVE = keybind("quick_move", GLFW.GLFW_KEY_LEFT_SHIFT, KeyBinding.INVENTORY_CATEGORY); public static Text gamemodeSwitcherSelectText = null; @@ -131,4 +133,8 @@ public static String getDebugKeybindString(KeyBinding key) { public static int getKeyCode(KeyBinding key) { return Math.abs(KeyBindingHelper.getBoundKeyOf(key).getCode()); } + + public static boolean isKeybindPressed(KeyBinding key) { + return InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), getKeyCode(key)); + } } diff --git a/src/main/java/com/minenash/rebind_all_the_keys/mixin/HandledScreenMixin.java b/src/main/java/com/minenash/rebind_all_the_keys/mixin/HandledScreenMixin.java new file mode 100644 index 0000000..f064f77 --- /dev/null +++ b/src/main/java/com/minenash/rebind_all_the_keys/mixin/HandledScreenMixin.java @@ -0,0 +1,27 @@ +package com.minenash.rebind_all_the_keys.mixin; + +import com.minenash.rebind_all_the_keys.RebindAllTheKeys; +import net.minecraft.client.gui.screen.ingame.HandledScreen; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(HandledScreen.class) +public class HandledScreenMixin { + + @Redirect(method = "mouseReleased", at = @At(value = "INVOKE",target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;hasShiftDown()Z")) + public boolean rebindShift() { + return RebindAllTheKeys.QUICK_MOVE.isDefault() ? HandledScreen.hasShiftDown() : RebindAllTheKeys.isKeybindPressed(RebindAllTheKeys.QUICK_MOVE); + } + + @Redirect(method = "mouseReleased", at = @At(value = "INVOKE",target = "Lnet/minecraft/client/util/InputUtil;isKeyPressed(JI)Z")) + public boolean rebindShift2(long _handle, int _code) { + return RebindAllTheKeys.QUICK_MOVE.isDefault() ? HandledScreen.hasShiftDown() : RebindAllTheKeys.isKeybindPressed(RebindAllTheKeys.QUICK_MOVE); + } + + @Redirect(method = "mouseClicked", at = @At(value = "INVOKE",target = "Lnet/minecraft/client/util/InputUtil;isKeyPressed(JI)Z")) + public boolean rebindShift3(long _handle, int _code) { + return RebindAllTheKeys.QUICK_MOVE.isDefault() ? HandledScreen.hasShiftDown() : RebindAllTheKeys.isKeybindPressed(RebindAllTheKeys.QUICK_MOVE); + } + +} diff --git a/src/main/resources/assets/rebind_all_the_keys/lang/en_us.json b/src/main/resources/assets/rebind_all_the_keys/lang/en_us.json index b9e8793..3937232 100644 --- a/src/main/resources/assets/rebind_all_the_keys/lang/en_us.json +++ b/src/main/resources/assets/rebind_all_the_keys/lang/en_us.json @@ -25,6 +25,7 @@ "rebind_all_the_keys.keybind.refresh_server_list" : "Refresh Server List", "rebind_all_the_keys.keybind.hotbar_next_override" : "Hotbar Next (Override)", "rebind_all_the_keys.keybind.hotbar_previous_override" : "Hotbar Previous (Override)", + "rebind_all_the_keys.keybind.quick_move" : "Quick Move", "rebind_all_the_keys.controls.cmdToCtrl": "Cmd → Ctrl", "rebind_all_the_keys.controls.doubleTapSprint": "Double Tap Sprint" diff --git a/src/main/resources/rebind_all_the_keys.mixins.json b/src/main/resources/rebind_all_the_keys.mixins.json index 2ff207d..241af9f 100644 --- a/src/main/resources/rebind_all_the_keys.mixins.json +++ b/src/main/resources/rebind_all_the_keys.mixins.json @@ -22,5 +22,8 @@ ], "injectors": { "defaultRequire": 1 - } + }, + "mixins": [ + "HandledScreenMixin" + ] }