From 6332e9c7bcd0e7843236d94210e4a076d2cffac7 Mon Sep 17 00:00:00 2001 From: isXander Date: Mon, 13 Feb 2023 22:05:00 +0000 Subject: [PATCH] swap hands and shift click binds --- .../isxander/controlify/bindings/ControllerBindings.java | 6 ++++-- .../mixins/feature/virtualmouse/InputConstantsMixin.java | 7 +++++-- .../controlify/virtualmouse/VirtualMouseHandler.java | 8 ++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/dev/isxander/controlify/bindings/ControllerBindings.java b/src/main/java/dev/isxander/controlify/bindings/ControllerBindings.java index 090a012..5b5de48 100644 --- a/src/main/java/dev/isxander/controlify/bindings/ControllerBindings.java +++ b/src/main/java/dev/isxander/controlify/bindings/ControllerBindings.java @@ -23,10 +23,11 @@ public class ControllerBindings { PAUSE, INVENTORY, CHANGE_PERSPECTIVE, + SWAP_HANDS, OPEN_CHAT, GUI_PRESS, GUI_BACK, GUI_NEXT_TAB, GUI_PREV_TAB, - VMOUSE_LCLICK, VMOUSE_RCLICK, VMOUSE_MCLICK, VMOUSE_SCROLL_UP, VMOUSE_SCROLL_DOWN, VMOUSE_ESCAPE, VMOUSE_SHIFT, VMOUSE_TOGGLE, + VMOUSE_LCLICK, VMOUSE_RCLICK, VMOUSE_SHIFT_CLICK, VMOUSE_SCROLL_UP, VMOUSE_SCROLL_DOWN, VMOUSE_ESCAPE, VMOUSE_SHIFT, VMOUSE_TOGGLE, PICK_BLOCK, TOGGLE_HUD_VISIBILITY, SHOW_PLAYER_LIST; @@ -54,6 +55,7 @@ public class ControllerBindings { register(PAUSE = new ControllerBinding(controller, Bind.START, new ResourceLocation("controlify", "pause"))); register(INVENTORY = new ControllerBinding(controller, Bind.Y_BUTTON, new ResourceLocation("controlify", "inventory"), options.keyInventory, () -> false)); register(CHANGE_PERSPECTIVE = new ControllerBinding(controller, Bind.BACK, new ResourceLocation("controlify", "change_perspective"), options.keyTogglePerspective, () -> false)); + register(SWAP_HANDS = new ControllerBinding(controller, Bind.X_BUTTON, new ResourceLocation("controlify", "swap_hands"), options.keySwapOffhand, () -> false)); register(OPEN_CHAT = new ControllerBinding(controller, Bind.DPAD_UP, new ResourceLocation("controlify", "open_chat"), options.keyChat, () -> false)); register(GUI_PRESS = new ControllerBinding(controller, Bind.A_BUTTON, new ResourceLocation("controlify", "gui_press"))); register(GUI_BACK = new ControllerBinding(controller, Bind.B_BUTTON, new ResourceLocation("controlify", "gui_back"))); @@ -64,7 +66,7 @@ public class ControllerBindings { register(SHOW_PLAYER_LIST = new ControllerBinding(controller, Bind.DPAD_RIGHT, new ResourceLocation("controlify", "show_player_list"), options.keyPlayerList, () -> false)); register(VMOUSE_LCLICK = new ControllerBinding(controller, Bind.A_BUTTON, new ResourceLocation("controlify", "vmouse_lclick"))); register(VMOUSE_RCLICK = new ControllerBinding(controller, Bind.X_BUTTON, new ResourceLocation("controlify", "vmouse_rclick"))); - register(VMOUSE_MCLICK = new ControllerBinding(controller, Bind.Y_BUTTON, new ResourceLocation("controlify", "vmouse_mclick"))); + register(VMOUSE_SHIFT_CLICK = new ControllerBinding(controller, Bind.Y_BUTTON, new ResourceLocation("controlify", "vmouse_shift_click"))); register(VMOUSE_SCROLL_UP = new ControllerBinding(controller, Bind.RIGHT_STICK_FORWARD, new ResourceLocation("controlify", "vmouse_scroll_up"))); register(VMOUSE_SCROLL_DOWN = new ControllerBinding(controller, Bind.RIGHT_STICK_BACKWARD, new ResourceLocation("controlify", "vmouse_scroll_down"))); register(VMOUSE_ESCAPE = new ControllerBinding(controller, Bind.B_BUTTON, new ResourceLocation("controlify", "vmouse_escape"))); diff --git a/src/main/java/dev/isxander/controlify/mixins/feature/virtualmouse/InputConstantsMixin.java b/src/main/java/dev/isxander/controlify/mixins/feature/virtualmouse/InputConstantsMixin.java index ac01da4..07f8f21 100644 --- a/src/main/java/dev/isxander/controlify/mixins/feature/virtualmouse/InputConstantsMixin.java +++ b/src/main/java/dev/isxander/controlify/mixins/feature/virtualmouse/InputConstantsMixin.java @@ -3,6 +3,7 @@ package dev.isxander.controlify.mixins.feature.virtualmouse; import com.llamalad7.mixinextras.injector.ModifyReturnValue; import com.mojang.blaze3d.platform.InputConstants; import dev.isxander.controlify.Controlify; +import net.minecraft.client.Minecraft; import org.lwjgl.glfw.GLFW; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -12,8 +13,10 @@ public class InputConstantsMixin { // must modify isKeyDown here because Screen.hasShiftDown has some instances that ask for this directly. @ModifyReturnValue(method = "isKeyDown", at = @At("RETURN")) private static boolean modifyIsKeyDown(boolean keyDown, long window, int key) { - if (key == GLFW.GLFW_KEY_LEFT_SHIFT) { - return keyDown || Controlify.instance().currentController().bindings().VMOUSE_SHIFT.held(); + if (key == GLFW.GLFW_KEY_LEFT_SHIFT && window == Minecraft.getInstance().getWindow().getWindow()) { + return keyDown + || Controlify.instance().currentController().bindings().VMOUSE_SHIFT_CLICK.held() + || Controlify.instance().currentController().bindings().VMOUSE_SHIFT.held(); } return keyDown; diff --git a/src/main/java/dev/isxander/controlify/virtualmouse/VirtualMouseHandler.java b/src/main/java/dev/isxander/controlify/virtualmouse/VirtualMouseHandler.java index df8d9b2..1221ebe 100644 --- a/src/main/java/dev/isxander/controlify/virtualmouse/VirtualMouseHandler.java +++ b/src/main/java/dev/isxander/controlify/virtualmouse/VirtualMouseHandler.java @@ -106,10 +106,10 @@ public class VirtualMouseHandler { mouseHandler.invokeOnPress(minecraft.getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_RIGHT, GLFW.GLFW_RELEASE, 0); } - if (controller.bindings().VMOUSE_MCLICK.justPressed()) { - mouseHandler.invokeOnPress(minecraft.getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_MIDDLE, GLFW.GLFW_PRESS, 0); - } else if (controller.bindings().VMOUSE_MCLICK.justReleased()) { - mouseHandler.invokeOnPress(minecraft.getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_MIDDLE, GLFW.GLFW_RELEASE, 0); + if (controller.bindings().VMOUSE_SHIFT_CLICK.justPressed()) { + mouseHandler.invokeOnPress(minecraft.getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_LEFT, GLFW.GLFW_PRESS, 0); + } else if (controller.bindings().VMOUSE_SHIFT_CLICK.justReleased()) { + mouseHandler.invokeOnPress(minecraft.getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_LEFT, GLFW.GLFW_RELEASE, 0); } if (controller.bindings().VMOUSE_ESCAPE.justPressed()) {