Fix teleport confirm<->move packet order in 1.21.3

This commit is contained in:
FlorianMichael 2024-12-04 15:55:08 +01:00
parent 0a079a1a90
commit ab86e95d5e
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126

View File

@ -55,10 +55,7 @@ import net.minecraft.world.GameMode;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.raphimc.viabedrock.api.BedrockProtocolVersion; import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@ -91,10 +88,30 @@ public abstract class MixinClientPlayNetworkHandler extends ClientCommonNetworkH
@Shadow @Shadow
private ClientWorld world; private ClientWorld world;
@Unique
private Packet<?> viaFabricPlus$teleportConfirmPacket;
protected MixinClientPlayNetworkHandler(MinecraftClient client, ClientConnection connection, ClientConnectionState connectionState) { protected MixinClientPlayNetworkHandler(MinecraftClient client, ClientConnection connection, ClientConnectionState connectionState) {
super(client, connection, 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)) @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) { private boolean dontHandleEntityPositionChange(TrackedPosition instance, Vec3d pos) {
return ProtocolTranslator.getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_21_2); return ProtocolTranslator.getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_21_2);