From 42ab94491cd87a2e95079b7206e72a3a72c4a9cf Mon Sep 17 00:00:00 2001 From: MachieCodes <80427814+machiecodes@users.noreply.github.com> Date: Wed, 1 Jan 2025 15:22:59 -0600 Subject: [PATCH] Refactor Sprint (#5078) Co-authored-by: Wide_Cat --- .../mixin/ClientPlayerEntityMixin.java | 4 +- .../meteorclient/mixin/LivingEntityMixin.java | 20 ++++-- .../systems/modules/movement/Sprint.java | 72 +++++++++++-------- 3 files changed, 58 insertions(+), 38 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayerEntityMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayerEntityMixin.java index 5fe903751d..afa19d988c 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayerEntityMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayerEntityMixin.java @@ -113,7 +113,9 @@ private boolean modifyMovement(boolean original) { @WrapWithCondition(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;setSprinting(Z)V", ordinal = 3)) private boolean wrapSetSprinting(ClientPlayerEntity instance, boolean b) { - return !Modules.get().get(Sprint.class).rageSprint(); + Sprint s = Modules.get().get(Sprint.class); + + return !s.rageSprint() || s.unsprintInWater() && isTouchingWater(); } // Rotations diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityMixin.java index f40ab07655..830a4bb30d 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityMixin.java @@ -69,15 +69,19 @@ private void spawnItemParticles(ItemStack stack, int count, CallbackInfo info) { @Inject(method = "onEquipStack", at = @At("HEAD"), cancellable = true) private void onEquipStack(EquipmentSlot slot, ItemStack oldStack, ItemStack newStack, CallbackInfo info) { - if ((Object) this == mc.player && Modules.get().get(OffhandCrash.class).isAntiCrash()) { + if ((Object) this != mc.player) return; + + if (Modules.get().get(OffhandCrash.class).isAntiCrash()) { info.cancel(); } } @ModifyArg(method = "swingHand(Lnet/minecraft/util/Hand;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;swingHand(Lnet/minecraft/util/Hand;Z)V")) private Hand setHand(Hand hand) { + if ((Object) this != mc.player) return hand; + HandView handView = Modules.get().get(HandView.class); - if ((Object) this == mc.player && handView.isActive()) { + if (handView.isActive()) { if (handView.swingMode.get() == HandView.SwingMode.None) return hand; return handView.swingMode.get() == HandView.SwingMode.Offhand ? Hand.OFF_HAND : Hand.MAIN_HAND; } @@ -87,12 +91,15 @@ private Hand setHand(Hand hand) { @ModifyConstant(method = "getHandSwingDuration", constant = @Constant(intValue = 6)) private int getHandSwingDuration(int constant) { if ((Object) this != mc.player) return constant; + return Modules.get().get(HandView.class).isActive() && mc.options.getPerspective().isFirstPerson() ? Modules.get().get(HandView.class).swingSpeed.get() : constant; } @ModifyReturnValue(method = "isGliding", at = @At("RETURN")) private boolean isGlidingHook(boolean original) { - if ((Object) this == mc.player && Modules.get().get(ElytraFly.class).canPacketEfly()) { + if ((Object) this != mc.player) return original; + + if (Modules.get().get(ElytraFly.class).canPacketEfly()) { return true; } @@ -122,9 +129,7 @@ private boolean hasStatusEffect(boolean original, RegistryEntry ef @ModifyExpressionValue(method = "jump", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F")) private float modifyGetYaw(float original) { if ((Object) this != mc.player) return original; - - Sprint s = Modules.get().get(Sprint.class); - if (!s.rageSprint() || !s.jumpFix.get()) return original; + if (!Modules.get().get(Sprint.class).rageSprint()) return original; float forward = Math.signum(mc.player.input.movementForward); float strafe = 90 * Math.signum(mc.player.input.movementSideways); @@ -138,7 +143,8 @@ private float modifyGetYaw(float original) { @ModifyExpressionValue(method = "jump", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;isSprinting()Z")) private boolean modifyIsSprinting(boolean original) { - if ((Object) this != mc.player || !Modules.get().get(Sprint.class).rageSprint()) return original; + if ((Object) this != mc.player) return original; + if (!Modules.get().get(Sprint.class).rageSprint()) return original; // only add the extra velocity if you're actually moving, otherwise you'll jump in place and move forward return original && (Math.abs(mc.player.input.movementForward) > 1.0E-5F || Math.abs(mc.player.input.movementSideways) > 1.0E-5F); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Sprint.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Sprint.java index 8e2e2d46eb..6935d708d9 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Sprint.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Sprint.java @@ -30,38 +30,39 @@ public enum Mode { } public final Setting mode = sgGeneral.add(new EnumSetting.Builder() - .name("speed-mode") + .name("sprint-mode") .description("What mode of sprinting.") .defaultValue(Mode.Strict) .build() ); - public final Setting jumpFix = sgGeneral.add(new BoolSetting.Builder() - .name("jump-fix") - .description("Whether to correct jumping directions.") - .defaultValue(true) - .visible(() -> mode.get() == Mode.Rage) - .build() - ); - private final Setting keepSprint = sgGeneral.add(new BoolSetting.Builder() .name("keep-sprint") - .description("Whether to keep sprinting after attacking an entity.") + .description("Whether to keep sprinting after attacking.") .defaultValue(false) .build() ); private final Setting unsprintOnHit = sgGeneral.add(new BoolSetting.Builder() .name("unsprint-on-hit") - .description("Whether to stop sprinting when attacking, to ensure you get crits and sweep attacks.") + .description("Whether to stop sprinting before attacking, to ensure you get crits and sweep attacks.") .defaultValue(false) .build() ); - private final Setting unsprintInWater = sgGeneral.add(new BoolSetting.Builder() + public final Setting unsprintInWater = sgGeneral.add(new BoolSetting.Builder() .name("unsprint-in-water") .description("Whether to stop sprinting when in water.") .defaultValue(true) + .visible(() -> mode.get() == Mode.Rage) + .build() + ); + + private final Setting permaSprint = sgGeneral.add(new BoolSetting.Builder() + .name("sprint-while-stationary") + .description("Sprint even when not moving.") + .defaultValue(false) + .visible(() -> mode.get() == Mode.Rage) .build() ); @@ -69,19 +70,18 @@ public Sprint() { super(Categories.Movement, "sprint", "Automatically sprints."); } - @Override - public void onDeactivate() { - mc.player.setSprinting(false); - } - - @EventHandler + @EventHandler(priority = EventPriority.HIGH) private void onTickMovement(TickEvent.Post event) { - if (shouldSprint()) mc.player.setSprinting(true); + if (unsprintInWater.get() && mc.player.isTouchingWater()) return; + + mc.player.setSprinting(shouldSprint()); } @EventHandler(priority = EventPriority.HIGH) private void onPacketSend(PacketEvent.Send event) { - if (!unsprintOnHit.get() || !(event.packet instanceof IPlayerInteractEntityC2SPacket packet) || packet.meteor$getType() != PlayerInteractEntityC2SPacket.InteractType.ATTACK) return; + if (!unsprintOnHit.get()) return; + if (!(event.packet instanceof IPlayerInteractEntityC2SPacket packet) + || packet.meteor$getType() != PlayerInteractEntityC2SPacket.InteractType.ATTACK) return; mc.getNetworkHandler().sendPacket(new ClientCommandC2SPacket(mc.player, ClientCommandC2SPacket.Mode.STOP_SPRINTING)); mc.player.setSprinting(false); @@ -90,29 +90,41 @@ private void onPacketSend(PacketEvent.Send event) { @EventHandler private void onPacketSent(PacketEvent.Sent event) { if (!unsprintOnHit.get() || !keepSprint.get()) return; - if (!(event.packet instanceof IPlayerInteractEntityC2SPacket packet) || packet.meteor$getType() != PlayerInteractEntityC2SPacket.InteractType.ATTACK) return; + if (!(event.packet instanceof IPlayerInteractEntityC2SPacket packet) + || packet.meteor$getType() != PlayerInteractEntityC2SPacket.InteractType.ATTACK) return; - if (shouldSprint() && !mc.player.isSprinting()) { - mc.getNetworkHandler().sendPacket(new ClientCommandC2SPacket(mc.player, ClientCommandC2SPacket.Mode.START_SPRINTING)); - mc.player.setSprinting(true); - } + if (!shouldSprint() || mc.player.isSprinting()) return; + + mc.getNetworkHandler().sendPacket(new ClientCommandC2SPacket(mc.player, ClientCommandC2SPacket.Mode.START_SPRINTING)); + mc.player.setSprinting(true); } public boolean shouldSprint() { - if (unsprintInWater.get() && (mc.player.isTouchingWater() || mc.player.isSubmergedInWater())) return false; + if (mc.currentScreen != null && !Modules.get().get(GUIMove.class).sprint.get()) return false; + + float movement = mode.get() == Mode.Rage + ? (Math.abs(mc.player.input.movementForward) + Math.abs(mc.player.input.movementSideways)) + : mc.player.input.movementForward; + + if (movement <= (mc.player.isSubmergedInWater() ? 1.0E-5F : 0.8)) { + if (mode.get() == Mode.Strict || !permaSprint.get()) return false; + } - boolean strictSprint = mc.player.forwardSpeed > 1.0E-5F + boolean strictSprint = !(mc.player.isTouchingWater() && !mc.player.isSubmergedInWater()) && ((ClientPlayerEntityAccessor) mc.player).invokeCanSprint() - && (!mc.player.horizontalCollision || mc.player.collidedSoftly) - && !(mc.player.isTouchingWater() && !mc.player.isSubmergedInWater()); + && (!mc.player.horizontalCollision || mc.player.collidedSoftly); - return isActive() && (mode.get() == Mode.Rage || strictSprint) && (mc.currentScreen == null || Modules.get().get(GUIMove.class).sprint.get()); + return isActive() && (mode.get() == Mode.Rage || strictSprint); } public boolean rageSprint() { return isActive() && mode.get() == Mode.Rage; } + public boolean unsprintInWater() { + return isActive() && unsprintInWater.get(); + } + public boolean stopSprinting() { return !isActive() || !keepSprint.get(); }