Send full position update packet in 1.20.5->1.21 placement rotation fix (#4290)

This commit is contained in:
EnZaXD 2024-11-29 16:02:47 +01:00 committed by GitHub
parent 9d4af84872
commit b57265e64f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 61 additions and 34 deletions

View File

@ -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<ClientboundPack
public void init(final UserConnection connection) {
addEntityTracker(connection, new EntityTrackerBase(connection, EntityTypes1_20_5.PLAYER));
connection.put(new EfficiencyAttributeStorage());
connection.put(new OnGroundTracker());
connection.put(new PlayerPositionStorage());
}
@Override

View File

@ -40,7 +40,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPac
import com.viaversion.viaversion.protocols.v1_20_5to1_21.Protocol1_20_5To1_21;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.AttributeModifierMappings1_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.BlockRewriter;
import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
import java.util.Arrays;
@ -143,13 +143,16 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<Cl
if (!Via.getConfig().fix1_21PlacementRotation()) {
return;
}
final OnGroundTracker tracker = wrapper.user().get(OnGroundTracker.class);
final PlayerPositionStorage storage = wrapper.user().get(PlayerPositionStorage.class);
// Not correct but *enough* for vanilla/normal servers to have block placement synchronized
final PacketWrapper playerRotation = wrapper.create(ServerboundPackets1_20_5.MOVE_PLAYER_ROT);
final PacketWrapper playerRotation = wrapper.create(ServerboundPackets1_20_5.MOVE_PLAYER_POS_ROT);
playerRotation.write(Types.DOUBLE, storage.x());
playerRotation.write(Types.DOUBLE, storage.y());
playerRotation.write(Types.DOUBLE, storage.z());
playerRotation.write(Types.FLOAT, yaw);
playerRotation.write(Types.FLOAT, pitch);
playerRotation.write(Types.BOOLEAN, tracker.onGround());
playerRotation.write(Types.BOOLEAN, storage.onGround());
playerRotation.sendToServer(Protocol1_20_5To1_21.class);
wrapper.sendToServer(Protocol1_20_5To1_21.class);

View File

@ -38,7 +38,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPac
import com.viaversion.viaversion.protocols.v1_20_5to1_21.Protocol1_20_5To1_21;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.Paintings1_20_5;
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.EntityRewriter;
import com.viaversion.viaversion.rewriter.RegistryDataRewriter;
@ -123,48 +123,51 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPa
// Resend attribute modifiers from items
wrapper.user().get(EfficiencyAttributeStorage.class).onRespawn(wrapper.user());
wrapper.user().put(new PlayerPositionStorage());
});
// Tracks on ground state for block interactions
// Tracking player position and on ground for block interactions, rotations is kept from the interaction packet
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS, wrapper -> {
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) -> {

View File

@ -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;
}