Move flight check fixes to onTick()

This commit is contained in:
Sollace 2024-05-25 18:52:19 +01:00
parent a6a19a4d4b
commit 6057d8ea3b
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB

View file

@ -17,36 +17,37 @@ import net.minecraft.server.world.EntityTrackingListener;
@Mixin(ServerPlayNetworkHandler.class) @Mixin(ServerPlayNetworkHandler.class)
abstract class MixinServerPlayNetworkHandler implements EntityTrackingListener, ServerPlayPacketListener { abstract class MixinServerPlayNetworkHandler implements EntityTrackingListener, ServerPlayPacketListener {
@Shadow public ServerPlayerEntity player;
@Shadow private boolean floating; @Shadow private boolean floating;
@Shadow private int floatingTicks; @Shadow private int floatingTicks;
private boolean flyingSurvival;
private boolean prevMotionChecks; private boolean prevMotionChecks;
@Inject(method = "onPlayerMove(Lnet/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket;)V", at = @At("HEAD")) @Inject(method = "onPlayerMove(Lnet/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket;)V", at = @At("HEAD"))
private void beforePlayerMove(PlayerMoveC2SPacket packet, CallbackInfo info) { private void beforePlayerMove(PlayerMoveC2SPacket packet, CallbackInfo info) {
ServerPlayerEntity player = ((ServerPlayNetworkHandler)(Object)this).player;
NetworkThreadUtils.forceMainThread(packet, this, player.getServerWorld()); NetworkThreadUtils.forceMainThread(packet, this, player.getServerWorld());
flyingSurvival = Pony.of(player).getPhysics().isFlyingSurvival; prevMotionChecks = player.isInTeleportationState();
if (Pony.of(player).getPhysics().isFlyingSurvival) {
if (flyingSurvival) { ((ServerPlayerEntityDuck)player).setPreventMotionChecks(true);
setPreventMotionChecks(true);
} }
} }
@Inject(method = "onPlayerMove(Lnet/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket;)V", at = @At("RETURN")) @Inject(method = "onPlayerMove(Lnet/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket;)V", at = @At("RETURN"))
private void afterPlayerMove(PlayerMoveC2SPacket packet, CallbackInfo info) { private void afterPlayerMove(PlayerMoveC2SPacket packet, CallbackInfo info) {
if (flyingSurvival) { ((ServerPlayerEntityDuck)player).setPreventMotionChecks(prevMotionChecks);
setPreventMotionChecks(prevMotionChecks); if (Pony.of(player).getPhysics().isFlyingSurvival) {
floating = false;
floatingTicks = 0;
player.fallDistance = 0;
} }
} }
private void setPreventMotionChecks(boolean motionChecks) { @Inject(method = "tick()V", at = @At("HEAD"))
ServerPlayerEntity player = ((ServerPlayNetworkHandler)(Object)this).player; private void beforePlayerTick() {
prevMotionChecks = player.isInTeleportationState(); if (Pony.of(player).getPhysics().isFlyingSurvival) {
((ServerPlayerEntityDuck)player).setPreventMotionChecks(motionChecks);
player.fallDistance = 0;
floating = false; floating = false;
floatingTicks = 0; floatingTicks = 0;
player.fallDistance = 0;
}
} }
} }