From ab86e95d5eb161a9309c5e5490e026b67e5c9752 Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Wed, 4 Dec 2024 15:55:08 +0100 Subject: [PATCH] Fix teleport confirm<->move packet order in 1.21.3 --- .../MixinClientPlayNetworkHandler.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinClientPlayNetworkHandler.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinClientPlayNetworkHandler.java index 766a52c2..d4057c47 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinClientPlayNetworkHandler.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinClientPlayNetworkHandler.java @@ -55,10 +55,7 @@ import net.minecraft.world.GameMode; import net.minecraft.world.World; import net.raphimc.viabedrock.api.BedrockProtocolVersion; import org.slf4j.Logger; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -91,10 +88,30 @@ public abstract class MixinClientPlayNetworkHandler extends ClientCommonNetworkH @Shadow private ClientWorld world; + @Unique + private Packet viaFabricPlus$teleportConfirmPacket; + protected MixinClientPlayNetworkHandler(MinecraftClient client, ClientConnection connection, ClientConnectionState connectionState) { super(client, connection, connectionState); } + @WrapWithCondition(method = "onPlayerPositionLook", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;send(Lnet/minecraft/network/packet/Packet;)V", ordinal = 0)) + private boolean changePacketOrder(ClientConnection instance, Packet packet) { + final boolean cancel = ProtocolTranslator.getTargetVersion().equalTo(ProtocolVersion.v1_21_2); + if (cancel) { + this.viaFabricPlus$teleportConfirmPacket = packet; + } + return !cancel; + } + + @Inject(method = "onPlayerPositionLook", at = @At("RETURN")) + public void changePacketOrder(PlayerPositionLookS2CPacket packet, CallbackInfo ci) { + if (viaFabricPlus$teleportConfirmPacket != null) { + this.connection.send(viaFabricPlus$teleportConfirmPacket); + viaFabricPlus$teleportConfirmPacket = null; + } + } + @WrapWithCondition(method = "onEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/TrackedPosition;setPos(Lnet/minecraft/util/math/Vec3d;)V", ordinal = 0)) private boolean dontHandleEntityPositionChange(TrackedPosition instance, Vec3d pos) { return ProtocolTranslator.getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_21_2);