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

Make "Auto Jump Replacement" more compatible #530

Merged
merged 3 commits into from
Jul 28, 2024
Merged
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 @@ -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);
}
}