Skip to content

Commit

Permalink
GuiMove improvements (#4282)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycat256 authored Feb 3, 2024
1 parent 4b2d1f3 commit a8e9dd7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -38,4 +44,14 @@ private void onRunCommand(Style style, CallbackInfoReturnable<Boolean> cir) {
}
}
}

@Inject(method = "keyPressed", at = @At("HEAD"), cancellable = true)
private void onKeyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> info) {
if ((Object) (this) instanceof ChatScreen) return;
GUIMove guiMove = Modules.get().get(GUIMove.class);
List<Integer> 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
}
Expand All @@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit a8e9dd7

Please sign in to comment.