From a8e9dd7c4a23ee921b96ca7cbeeb4a389f3ba51b Mon Sep 17 00:00:00 2001 From: crazycat256 <63475640+crazycat256@users.noreply.github.com> Date: Sat, 3 Feb 2024 02:39:08 +0100 Subject: [PATCH] GuiMove improvements (#4282) --- .../meteorclient/mixin/ScreenMixin.java | 16 ++++++++++ .../systems/modules/movement/GUIMove.java | 31 ++++++++++++++----- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ScreenMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ScreenMixin.java index ee67c6bdb5..3fb6f8ecc2 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ScreenMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ScreenMixin.java @@ -9,8 +9,10 @@ import meteordevelopment.meteorclient.commands.Commands; import meteordevelopment.meteorclient.systems.config.Config; import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.movement.GUIMove; import meteordevelopment.meteorclient.systems.modules.render.NoRender; import meteordevelopment.meteorclient.utils.Utils; +import net.minecraft.client.gui.screen.ChatScreen; import net.minecraft.client.gui.screen.Screen; import net.minecraft.text.Style; import org.spongepowered.asm.mixin.Mixin; @@ -19,6 +21,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.List; + +import static net.minecraft.client.util.InputUtil.*; + @Mixin(value = Screen.class, priority = 500) // needs to be before baritone public abstract class ScreenMixin { @Inject(method = "renderBackground", at = @At("HEAD"), cancellable = true) @@ -38,4 +44,14 @@ private void onRunCommand(Style style, CallbackInfoReturnable cir) { } } } + + @Inject(method = "keyPressed", at = @At("HEAD"), cancellable = true) + private void onKeyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable info) { + if ((Object) (this) instanceof ChatScreen) return; + GUIMove guiMove = Modules.get().get(GUIMove.class); + List arrows = List.of(GLFW_KEY_RIGHT, GLFW_KEY_LEFT, GLFW_KEY_DOWN, GLFW_KEY_UP); + if ((guiMove.disableArrows() && arrows.contains(keyCode)) || (guiMove.disableSpace() && keyCode == GLFW_KEY_SPACE)) { + info.cancel(); + } + } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/GUIMove.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/GUIMove.java index 0c3bc94cca..f9ed75835a 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/GUIMove.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/GUIMove.java @@ -7,6 +7,7 @@ import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.events.meteor.KeyEvent; +import meteordevelopment.meteorclient.events.render.Render3DEvent; import meteordevelopment.meteorclient.events.world.TickEvent; import meteordevelopment.meteorclient.gui.WidgetScreen; import meteordevelopment.meteorclient.mixin.CreativeInventoryScreenAccessor; @@ -86,7 +87,7 @@ public enum Screens { .min(0) .build() ); - + public GUIMove() { super(Categories.Movement, "gui-move", "Allows you to perform various actions while in GUIs."); } @@ -103,6 +104,13 @@ public void onDeactivate() { if (sprint.get()) set(mc.options.sprintKey, false); } + public boolean disableSpace() { + return isActive() && jump.get() && mc.options.jumpKey.isDefault(); + } + public boolean disableArrows() { + return isActive() && arrowsRotate.get(); + } + @EventHandler private void onTick(TickEvent.Pre event) { if (skip()) return; @@ -118,16 +126,25 @@ private void onTick(TickEvent.Pre event) { if (sneak.get()) set(mc.options.sneakKey, Input.isPressed(mc.options.sneakKey)); if (sprint.get()) set(mc.options.sprintKey, Input.isPressed(mc.options.sprintKey)); + } + + @EventHandler + private void onRender3D(Render3DEvent event) { + if (skip()) return; + if (screens.get() == Screens.GUI && !(mc.currentScreen instanceof WidgetScreen)) return; + if (screens.get() == Screens.Inventory && mc.currentScreen instanceof WidgetScreen) return; + + float rotationDelta = Math.min((float) (rotateSpeed.get() * event.frameTime * 20f), 100); + if (arrowsRotate.get()) { float yaw = mc.player.getYaw(); float pitch = mc.player.getPitch(); - for (int i = 0; i < (rotateSpeed.get() * 2); i++) { - if (Input.isKeyPressed(GLFW_KEY_LEFT)) yaw -= 0.5; - if (Input.isKeyPressed(GLFW_KEY_RIGHT)) yaw += 0.5; - if (Input.isKeyPressed(GLFW_KEY_UP)) pitch -= 0.5; - if (Input.isKeyPressed(GLFW_KEY_DOWN)) pitch += 0.5; - } + if (Input.isKeyPressed(GLFW_KEY_LEFT)) yaw -= rotationDelta; + if (Input.isKeyPressed(GLFW_KEY_RIGHT)) yaw += rotationDelta; + if (Input.isKeyPressed(GLFW_KEY_UP)) pitch -= rotationDelta; + if (Input.isKeyPressed(GLFW_KEY_DOWN)) pitch += rotationDelta; + pitch = MathHelper.clamp(pitch, -90, 90);