From b57265e64f94997f487f7f3142761cab91755773 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Fri, 29 Nov 2024 16:02:47 +0100 Subject: [PATCH] Send full position update packet in 1.20.5->1.21 placement rotation fix (#4290) --- .../v1_20_5to1_21/Protocol1_20_5To1_21.java | 4 +- .../rewriter/BlockItemPacketRewriter1_21.java | 11 ++-- .../rewriter/EntityPacketRewriter1_21.java | 57 ++++++++++--------- ...racker.java => PlayerPositionStorage.java} | 23 +++++++- 4 files changed, 61 insertions(+), 34 deletions(-) rename common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/storage/{OnGroundTracker.java => PlayerPositionStorage.java} (72%) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java index b49ba0422..e3aa714c7 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java @@ -46,7 +46,7 @@ import com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacke import com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.ComponentRewriter1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.EntityPacketRewriter1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.EfficiencyAttributeStorage; -import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.OnGroundTracker; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.PlayerPositionStorage; import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.rewriter.ParticleRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter; @@ -234,7 +234,7 @@ public final class Protocol1_20_5To1_21 extends AbstractProtocol { - if (!Via.getConfig().fix1_21PlacementRotation()) { - return; + if (Via.getConfig().fix1_21PlacementRotation()) { + storePosition(wrapper); + storeOnGround(wrapper); } - wrapper.passthrough(Types.DOUBLE); // X - wrapper.passthrough(Types.DOUBLE); // Y - wrapper.passthrough(Types.DOUBLE); // Z - - wrapper.user().get(OnGroundTracker.class).setOnGround(wrapper.passthrough(Types.BOOLEAN)); }); protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_ROT, wrapper -> { - if (!Via.getConfig().fix1_21PlacementRotation()) { - return; + if (Via.getConfig().fix1_21PlacementRotation()) { + wrapper.passthrough(Types.FLOAT); // Yaw + wrapper.passthrough(Types.FLOAT); // Pitch + storeOnGround(wrapper); } - wrapper.passthrough(Types.FLOAT); // Yaw - wrapper.passthrough(Types.FLOAT); // Pitch - - wrapper.user().get(OnGroundTracker.class).setOnGround(wrapper.passthrough(Types.BOOLEAN)); }); protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS_ROT, wrapper -> { - if (!Via.getConfig().fix1_21PlacementRotation()) { - return; + if (Via.getConfig().fix1_21PlacementRotation()) { + storePosition(wrapper); + wrapper.passthrough(Types.FLOAT); // Yaw + wrapper.passthrough(Types.FLOAT); // Pitch + storeOnGround(wrapper); } - wrapper.passthrough(Types.DOUBLE); // X - wrapper.passthrough(Types.DOUBLE); // Y - wrapper.passthrough(Types.DOUBLE); // Z - wrapper.passthrough(Types.FLOAT); // Yaw - wrapper.passthrough(Types.FLOAT); // Pitch - - wrapper.user().get(OnGroundTracker.class).setOnGround(wrapper.passthrough(Types.BOOLEAN)); }); protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_STATUS_ONLY, wrapper -> { - if (!Via.getConfig().fix1_21PlacementRotation()) { - return; + if (Via.getConfig().fix1_21PlacementRotation()) { + storeOnGround(wrapper); } - wrapper.user().get(OnGroundTracker.class).setOnGround(wrapper.passthrough(Types.BOOLEAN)); }); } + private void storePosition(final PacketWrapper wrapper) { + final double x = wrapper.passthrough(Types.DOUBLE); + final double y = wrapper.passthrough(Types.DOUBLE); + final double z = wrapper.passthrough(Types.DOUBLE); + wrapper.user().get(PlayerPositionStorage.class).setPosition(x, y, z); + } + + private void storeOnGround(final PacketWrapper wrapper) { + final boolean onGround = wrapper.passthrough(Types.BOOLEAN); + wrapper.user().get(PlayerPositionStorage.class).setOnGround(onGround); + } + @Override protected void registerRewrites() { filter().handler((event, data) -> { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/storage/OnGroundTracker.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/storage/PlayerPositionStorage.java similarity index 72% rename from common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/storage/OnGroundTracker.java rename to common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/storage/PlayerPositionStorage.java index f7a8c3453..beaf4beec 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/storage/OnGroundTracker.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/storage/PlayerPositionStorage.java @@ -19,10 +19,31 @@ package com.viaversion.viaversion.protocols.v1_20_5to1_21.storage; import com.viaversion.viaversion.api.connection.StorableObject; -public final class OnGroundTracker implements StorableObject { +public final class PlayerPositionStorage implements StorableObject { + private double x; + private double y; + private double z; private boolean onGround; + public double x() { + return x; + } + + public double y() { + return y; + } + + public double z() { + return z; + } + + public void setPosition(final double x, final double y, final double z) { + this.x = x; + this.y = y; + this.z = z; + } + public boolean onGround() { return onGround; }