Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: sprint event #5236

Merged
merged 7 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@

package net.ccbluex.liquidbounce.injection.mixins.minecraft.client;

import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.ModuleCriticals;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleSprint;
import net.minecraft.client.input.Input;
import net.minecraft.util.PlayerInput;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Input.class)
public abstract class MixinInput {
Expand All @@ -41,16 +39,14 @@ public abstract class MixinInput {
@Shadow
public PlayerInput playerInput;

@Inject(method = "hasForwardMovement", cancellable = true, at = @At("RETURN"))
private void hookOmnidirectionalSprintA(final CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
if (ModuleCriticals.WhenSprinting.INSTANCE.getRunning() && ModuleCriticals.WhenSprinting.INSTANCE.getStopSprinting() == ModuleCriticals.WhenSprinting.StopSprintingMode.LEGIT) {
callbackInfoReturnable.setReturnValue(false);
return;
@ModifyReturnValue(method = "hasForwardMovement", at = @At("RETURN"))
private boolean hookOmnidirectionalSprint(boolean original) {
// Allow omnidirectional sprinting
if (ModuleSprint.INSTANCE.getShouldSprintOmnidirectional()) {
return Math.abs(movementForward) > 1.0E-5F || Math.abs(movementSideways) > 1.0E-5F;
}

final boolean hasMovement = Math.abs(movementForward) > 1.0E-5F || Math.abs(movementSideways) > 1.0E-5F;

callbackInfoReturnable.setReturnValue(!ModuleSprint.INSTANCE.shouldPreventSprint() && (ModuleSprint.INSTANCE.shouldSprintOmnidirectionally() ? hasMovement : callbackInfoReturnable.getReturnValue()));
return original;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.ccbluex.liquidbounce.event.EventManager;
import net.ccbluex.liquidbounce.event.events.MovementInputEvent;
import net.ccbluex.liquidbounce.features.module.modules.combat.ModuleSuperKnockback;
import net.ccbluex.liquidbounce.event.events.SprintEvent;
import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleInventoryMove;
import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleSprint;
import net.ccbluex.liquidbounce.utils.aiming.RotationManager;
import net.ccbluex.liquidbounce.utils.input.InputTracker;
import net.ccbluex.liquidbounce.utils.movement.DirectionalInput;
Expand Down Expand Up @@ -61,9 +60,10 @@ private boolean hookInventoryMove(KeyBinding instance, Operation<Boolean> origin
}

/**
* At settings.backKey.isPressed()
* Later in the code, the sprint key is checked for being pressed. We need to update the state of the key
* as well.
*/
@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;isPressed()Z", ordinal = 1))
@Inject(method = "tick", at = @At("HEAD"))
private void hookInventoryMoveSprint(CallbackInfo ci) {
if (ModuleInventoryMove.INSTANCE.shouldHandleInputs(this.settings.sprintKey)) {
this.settings.sprintKey.setPressed(InputTracker.INSTANCE.isPressedOnAny(this.settings.sprintKey));
Expand All @@ -76,28 +76,20 @@ private PlayerInput modifyInput(PlayerInput original) {
EventManager.INSTANCE.callEvent(event);
var directionalInput = changeDirection(event.getDirectionalInput());

var sprintEvent = new SprintEvent(directionalInput, original.sprint(), SprintEvent.Source.INPUT);
EventManager.INSTANCE.callEvent(sprintEvent);

return new PlayerInput(
directionalInput.getForwards(),
directionalInput.getBackwards(),
directionalInput.getLeft(),
directionalInput.getRight(),
event.getJump(),
event.getSneak(),
playerInput.sprint()
sprintEvent.getSprint()
);
}

@Inject(method = "tick", at = @At("RETURN"))
private void injectStopMove(CallbackInfo ci) {
if (ModuleSuperKnockback.INSTANCE.shouldStopMoving()) {
this.movementForward = 0f;

if (ModuleSprint.INSTANCE.shouldSprintOmnidirectionally()) {
this.movementSideways = 0f;
}
}
}

@Unique
private DirectionalInput changeDirection(DirectionalInput input) {
var player = MinecraftClient.getInstance().player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
import net.ccbluex.liquidbounce.event.EventManager;
import net.ccbluex.liquidbounce.event.EventState;
import net.ccbluex.liquidbounce.event.events.*;
import net.ccbluex.liquidbounce.features.module.modules.combat.ModuleSuperKnockback;
import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.ModuleCriticals;
import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura;
import net.ccbluex.liquidbounce.features.module.modules.exploit.ModuleAntiHunger;
import net.ccbluex.liquidbounce.features.module.modules.exploit.ModulePortalMenu;
import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleEntityControl;
import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleNoPush;
Expand All @@ -42,6 +38,7 @@
import net.ccbluex.liquidbounce.integration.interop.protocol.rest.v1.game.PlayerData;
import net.ccbluex.liquidbounce.utils.aiming.Rotation;
import net.ccbluex.liquidbounce.utils.aiming.RotationManager;
import net.ccbluex.liquidbounce.utils.movement.DirectionalInput;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.input.Input;
Expand Down Expand Up @@ -303,53 +300,54 @@ private boolean hookFreeCamPreventRotations(boolean bl4) {

@ModifyConstant(method = "canSprint", constant = @Constant(floatValue = 6.0F), slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/HungerManager;getFoodLevel()I", ordinal = 0)))
private float hookSprintIgnoreHunger(float constant) {
return ModuleSprint.INSTANCE.shouldIgnoreHunger() ? -1F : constant;
return ModuleSprint.INSTANCE.getShouldIgnoreHunger() ? -1F : constant;
}

@ModifyExpressionValue(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;isPressed()Z"))
private boolean hookAutoSprint(boolean original) {
return !ModuleSuperKnockback.INSTANCE.shouldBlockSprinting() && !ModuleKillAura.INSTANCE.shouldBlockSprinting()
&& (ModuleSprint.INSTANCE.getRunning() || original);
private boolean hookSprintStart(boolean original) {
var event = new SprintEvent(new DirectionalInput(input), original, SprintEvent.Source.MOVEMENT_TICK);
EventManager.INSTANCE.callEvent(event);
return event.getSprint();
}

@ModifyExpressionValue(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isWalking()Z"))
private boolean hookOmnidirectionalSprintB(boolean original) {
return liquid_bounce$isOmniWalking();
@ModifyExpressionValue(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;canSprint()Z"))
private boolean hookSprintStop(boolean original) {
var event = new SprintEvent(new DirectionalInput(input), original, SprintEvent.Source.MOVEMENT_TICK);
EventManager.INSTANCE.callEvent(event);
return event.getSprint();
}

@ModifyExpressionValue(method = "canStartSprinting", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isBlind()Z"))
private boolean hookSprintIgnoreBlindness(boolean original) {
return !ModuleSprint.INSTANCE.shouldIgnoreBlindness() && original;
}

@ModifyExpressionValue(method = "canStartSprinting", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isWalking()Z"))
private boolean hookOmnidirectionalSprintC(boolean original) {
return liquid_bounce$isOmniWalking();
return !ModuleSprint.INSTANCE.getShouldIgnoreBlindness() && original;
}

@ModifyExpressionValue(method = "tickMovement", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerEntity;horizontalCollision:Z"))
private boolean hookSprintIgnoreCollision(boolean original) {
return !ModuleSprint.INSTANCE.shouldIgnoreCollision() && original;
return !ModuleSprint.INSTANCE.getShouldIgnoreCollision() && original;
}

@Unique
private boolean liquid_bounce$isOmniWalking() {
boolean hasMovement = Math.abs(input.movementForward) > 1.0E-5F || Math.abs(input.movementSideways) > 1.0E-5F;
boolean isWalking = (double) Math.abs(input.movementForward) >= 0.8 || (double) Math.abs(input.movementSideways) >= 0.8;
boolean modifiedIsWalking = this.isSubmergedInWater() ? hasMovement : isWalking;
return ModuleSprint.INSTANCE.shouldSprintOmnidirectionally() ? modifiedIsWalking : this.isWalking();
@ModifyReturnValue(method = "isWalking", at = @At("RETURN"))
private boolean hookIsWalking(boolean original) {
if (!ModuleSprint.INSTANCE.getShouldSprintOmnidirectional()) {
return original;
}

var hasMovement = Math.abs(input.movementForward) > 1.0E-5F ||
Math.abs(input.movementSideways) > 1.0E-5F;
var isWalking = (double) Math.abs(input.movementForward) >= 0.8 ||
(double) Math.abs(input.movementSideways) >= 0.8;
return this.isSubmergedInWater() ? hasMovement : isWalking;
}

@ModifyExpressionValue(method = "sendSprintingPacket", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSprinting()Z")
)
private boolean hookNoHungerSprint(boolean original) {
if (ModuleCriticals.WhenSprinting.INSTANCE.getRunning() && ModuleCriticals.WhenSprinting.INSTANCE.getStopSprinting() == ModuleCriticals.WhenSprinting.StopSprintingMode.ON_NETWORK) {
return false;
}

return !(ModuleAntiHunger.INSTANCE.getRunning() && ModuleAntiHunger.INSTANCE.getNoSprint()) && original;
private boolean hookNetworkSprint(boolean original) {
var event = new SprintEvent(new DirectionalInput(input), original, SprintEvent.Source.NETWORK);
EventManager.INSTANCE.callEvent(event);
return event.getSprint();
}

@WrapWithCondition(method = "closeScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;setScreen(Lnet/minecraft/client/gui/screen/Screen;)V"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ val ALL_EVENT_CLASSES: Array<KClass<out Event>> = arrayOf(
KeyboardCharEvent::class,
InputHandleEvent::class,
MovementInputEvent::class,
SprintEvent::class,
KeyEvent::class,
MouseRotationEvent::class,
KeybindChangeEvent::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,20 @@ class KeyEvent(val key: InputUtil.Key, val action: Int) : Event()
object InputHandleEvent : Event()

@Nameable("movementInput")
class MovementInputEvent(var directionalInput: DirectionalInput, var jump: Boolean, var sneak: Boolean) : Event()
class MovementInputEvent(
var directionalInput: DirectionalInput,
var jump: Boolean,
var sneak: Boolean
) : Event()

@Nameable("sprint")
class SprintEvent(val directionalInput: DirectionalInput, var sprint: Boolean, val source: Source) : Event() {
enum class Source {
INPUT,
MOVEMENT_TICK,
NETWORK
}
}

@Nameable("mouseRotation")
class MouseRotationEvent(var cursorDeltaX: Double, var cursorDeltaY: Double) : CancellableEvent()
Expand Down
Loading
Loading