Skip to content

Commit

Permalink
Added ability to rebind shift in inventory (QUICK_MOVE)
Browse files Browse the repository at this point in the history
  • Loading branch information
Minenash committed Jul 2, 2022
1 parent f8d1b84 commit 97cab1c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/rebind_all_the_keys.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
],
"injectors": {
"defaultRequire": 1
}
},
"mixins": [
"HandledScreenMixin"
]
}

0 comments on commit 97cab1c

Please sign in to comment.