Skip to content

Commit

Permalink
Merge #916 (Omnidirectional Sprint)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 authored Dec 30, 2023
2 parents 128f455 + ccabdac commit 84a2d99
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/main/java/net/wurstclient/hacks/AutoSprintHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
@SearchTags({"auto sprint"})
public final class AutoSprintHack extends Hack implements UpdateListener
{
private final CheckboxSetting allDirections =
new CheckboxSetting("Omnidirectional Sprint",
"Sprint in all directions, not just forward.", false);

private final CheckboxSetting hungry = new CheckboxSetting("Hungry Sprint",
"Sprint even on low hunger.", false);

public AutoSprintHack()
{
super("AutoSprint");
setCategory(Category.MOVEMENT);
addSetting(allDirections);
addSetting(hungry);
}

Expand All @@ -43,15 +48,24 @@ public void onDisable()
public void onUpdate()
{
ClientPlayerEntity player = MC.player;

if(player.horizontalCollision || player.isSneaking())
return;

if(player.isInsideWaterOrBubbleColumn() || player.isSubmergedInWater())
return;

if(player.forwardSpeed > 0)
player.setSprinting(true);
if(!allDirections.isChecked() && player.forwardSpeed <= 0)
return;

if(player.input.getMovementInput().length() <= 1e-5F)
return;

player.setSprinting(true);
}

public boolean shouldOmniSprint()
{
return isEnabled() && allDirections.isChecked();
}

public boolean shouldSprintHungry()
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/net/wurstclient/mixin/ClientPlayerEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.authlib.GameProfile;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.input.Input;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
Expand Down Expand Up @@ -65,6 +68,23 @@ private void onTick(CallbackInfo ci)
EventManager.fire(UpdateEvent.INSTANCE);
}

/**
* This mixin makes AutoSprint's "Omnidirectional Sprint" setting work.
*/
@WrapOperation(
at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/input/Input;hasForwardMovement()Z",
ordinal = 0),
method = "tickMovement()V")
private boolean wrapHasForwardMovement(Input input,
Operation<Boolean> original)
{
if(WurstClient.INSTANCE.getHax().autoSprintHack.shouldOmniSprint())
return input.getMovementInput().length() > 1e-5F;

return original.call(input);
}

/**
* This mixin runs just before the tickMovement() method calls
* isUsingItem(), so that the onIsUsingItem() mixin knows which
Expand Down

0 comments on commit 84a2d99

Please sign in to comment.