Skip to content

Commit

Permalink
Further overengineer auto-jump replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
jchung01 committed Jul 28, 2024
1 parent 63d9453 commit 9a8b560
Showing 1 changed file with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,50 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

// Courtesy of Aroma1997
// Courtesy of jchung01
@Mixin(EntityPlayerSP.class)
public class UTAutoJumpMixin
{
@Unique
private float ut$stepHeightOverride;
@Unique
private boolean ut$stepAssisted;

@Inject(method = "isAutoJumpEnabled", at = @At("RETURN"), cancellable = true)
public void utAutoJump(CallbackInfoReturnable<Boolean> cir)
{
if (!UTConfigTweaks.ENTITIES.utAutoJumpToggle || !Minecraft.getMinecraft().isSingleplayer()) return;
if (Minecraft.getMinecraft().gameSettings.autoJump && Minecraft.getMinecraft().player.stepHeight < 1.0f)
EntityPlayerSP player = Minecraft.getMinecraft().player;
// Magic numbers to identify as this tweak's step heights.
final float assistedStepHeight = Float.intBitsToFloat(0b00111111101000000000001000000000); // About 1.25
final float baseStepHeight = Float.intBitsToFloat(0b00111111000110011001101001000011); // About 0.6
if (Minecraft.getMinecraft().gameSettings.autoJump)
{
ut$stepAssisted = true;
if (!Minecraft.getMinecraft().player.isSneaking()) Minecraft.getMinecraft().player.stepHeight = 1.25f;
if (!player.isSneaking() && player.onGround)
{
// Capture changed step height.
if (player.stepHeight >= 1.0f && player.stepHeight != assistedStepHeight && ut$stepHeightOverride == 0.0f)
{
if (ut$stepAssisted) player.stepHeight -= 0.65f;
ut$stepHeightOverride = player.stepHeight;
}
// Something other than sneaking reduced the step height, clear the saved step height.
else if (player.stepHeight < 1.0f && player.stepHeight != baseStepHeight)
{
ut$stepHeightOverride = 0.0f;
}
player.stepHeight = ut$stepHeightOverride > 0.0f ? ut$stepHeightOverride : assistedStepHeight;
ut$stepAssisted = true;
}
else if (player.isSneaking())
{
player.stepHeight = baseStepHeight;
}
}
else if (ut$stepAssisted)
{
player.stepHeight = ut$stepHeightOverride > 0.0f ? ut$stepHeightOverride : baseStepHeight;
ut$stepAssisted = false;
Minecraft.getMinecraft().player.stepHeight = Math.max(Minecraft.getMinecraft().player.stepHeight - 0.65f, 0.6f);
}
cir.setReturnValue(false);
}
Expand Down

0 comments on commit 9a8b560

Please sign in to comment.