Skip to content

Commit

Permalink
Merge pull request #530 from jchung01/main
Browse files Browse the repository at this point in the history
Make "Auto Jump Replacement" more compatible
  • Loading branch information
ACGaming authored Jul 28, 2024
2 parents e2e3584 + 895b8d8 commit 5886bff
Showing 1 changed file with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,57 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;

import mod.acgaming.universaltweaks.UniversalTweaks;
import mod.acgaming.universaltweaks.config.UTConfigGeneral;
import mod.acgaming.universaltweaks.config.UTConfigTweaks;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
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 (UTConfigGeneral.DEBUG.utDebugToggle) UniversalTweaks.LOGGER.debug("UTAutoJump ::: Auto jump check");
if (Minecraft.getMinecraft().gameSettings.autoJump && !Minecraft.getMinecraft().player.isSneaking()) Minecraft.getMinecraft().player.stepHeight = 1.2f;
else Minecraft.getMinecraft().player.stepHeight = 0.6f;
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)
{
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;
}
else if (player.stepHeight < 1.0f)
{
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;
}
cir.setReturnValue(false);
}
}

0 comments on commit 5886bff

Please sign in to comment.