30 lines
1.3 KiB
Java
30 lines
1.3 KiB
Java
package dev.nightly.sablegravity.mixin;
|
|
|
|
import dev.nightly.sablegravity.SableGravityState;
|
|
import dev.nightly.sablegravity.physics.SableLocalPlayerPhysics;
|
|
import dev.ryanhcode.sable.sublevel.SubLevel;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
|
|
/** Gives Shift its crouch pose and dimensions while creative flight uses it for local descent. */
|
|
@Mixin(targets = "net.minecraft.client.player.LocalPlayer", priority = 4000)
|
|
public abstract class LocalPlayerFlightCrouchMixin {
|
|
@Inject(method = "isCrouching", at = @At("HEAD"), cancellable = true)
|
|
private void sablegravity$crouchWhileFlying(CallbackInfoReturnable<Boolean> cir) {
|
|
Player player = (Player) (Object) this;
|
|
if (!player.getAbilities().flying
|
|
|| !player.isShiftKeyDown()
|
|
|| !((SableGravityState) player).sablegravity$isEnabled()) {
|
|
return;
|
|
}
|
|
|
|
SubLevel frame = SableLocalPlayerPhysics.getAttachedFrameIfPresent(player);
|
|
if (frame != null && !frame.isRemoved() && frame.getLevel() == player.level()) {
|
|
cir.setReturnValue(true);
|
|
}
|
|
}
|
|
}
|