mojira.dev
MC-311646

Cannot sneak under blocks while gliding

When flying near a ceiling ~(1.5 blocks), the player is forced to crouch between 1.5 and 2 blocks from the ceiling (In the attached image, I am NOT pressing the crouch button)

When flying closer than 1.5 blocks, you cannot crouch at all near a ceiling when flying

I suspect this is because of the code checking if you can fit in a space with the sneaking pose but not the standing pose, to force a crouch

and similarly to disallow a crouch if you cannot fit in the space with the sneaking pose. This is in the aiStep method in the LocalPlayer class

this.crouching = !abilities.flying
    && !this.isSwimming()
    && !this.isPassenger()
    && this.canPlayerFitWithinBlocksAndEntitiesWhen(Pose.CROUCHING)
    && (this.isShiftKeyDown() || !this.isSleeping() && !this.canPlayerFitWithinBlocksAndEntitiesWhen(Pose.STANDING));

I was able to make a quick mixin that changes this behavior in LocalPlayer and I can confirm this fix seems to work:

@Mixin(LocalPlayer.class)
public abstract class LocalPlayerMixin {

    @Redirect(method = "aiStep", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;crouching:Z", opcode = Opcodes.PUTFIELD))
    private void injected(LocalPlayer localPlayer, boolean crouching, @Local(name = "abilities") Abilities abilities)
    {
        localPlayer.crouching = !abilities.flying
                && !localPlayer.isSwimming()
                && !localPlayer.isPassenger()
                && (localPlayer.canPlayerFitWithinBlocksAndEntitiesWhen(Pose.CROUCHING) || (localPlayer.isFallFlying()) && localPlayer.canPlayerFitWithinBlocksAndEntitiesWhen(Pose.FALL_FLYING))
                && (localPlayer.isShiftKeyDown() || !localPlayer.isSleeping() && (!localPlayer.canPlayerFitWithinBlocksAndEntitiesWhen(Pose.STANDING) && !localPlayer.isFallFlying()));
    }
}

Environment

26.2 and 26.3 snapshots

Linked issues

Attachments

Comments 1

Thank you for helping us improve Minecraft! We saved your files:

[media]

dbrighthd

(Unassigned)

Confirmed

Gameplay

Low

Player

26.2, 26.3 Pre-Release 2

Retrieved