mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-22 08:27:37 +01:00
Send full position update packet in 1.20.5->1.21 placement rotation fix (#4290)
This commit is contained in:
parent
9d4af84872
commit
b57265e64f
@ -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.ComponentRewriter1_21;
|
||||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.EntityPacketRewriter1_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.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.ComponentRewriter;
|
||||||
import com.viaversion.viaversion.rewriter.ParticleRewriter;
|
import com.viaversion.viaversion.rewriter.ParticleRewriter;
|
||||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
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) {
|
public void init(final UserConnection connection) {
|
||||||
addEntityTracker(connection, new EntityTrackerBase(connection, EntityTypes1_20_5.PLAYER));
|
addEntityTracker(connection, new EntityTrackerBase(connection, EntityTypes1_20_5.PLAYER));
|
||||||
connection.put(new EfficiencyAttributeStorage());
|
connection.put(new EfficiencyAttributeStorage());
|
||||||
connection.put(new OnGroundTracker());
|
connection.put(new PlayerPositionStorage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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.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.data.AttributeModifierMappings1_21;
|
||||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.EfficiencyAttributeStorage;
|
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.BlockRewriter;
|
||||||
import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
|
import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -143,13 +143,16 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<Cl
|
|||||||
if (!Via.getConfig().fix1_21PlacementRotation()) {
|
if (!Via.getConfig().fix1_21PlacementRotation()) {
|
||||||
return;
|
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
|
// 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, yaw);
|
||||||
playerRotation.write(Types.FLOAT, pitch);
|
playerRotation.write(Types.FLOAT, pitch);
|
||||||
playerRotation.write(Types.BOOLEAN, tracker.onGround());
|
playerRotation.write(Types.BOOLEAN, storage.onGround());
|
||||||
|
|
||||||
playerRotation.sendToServer(Protocol1_20_5To1_21.class);
|
playerRotation.sendToServer(Protocol1_20_5To1_21.class);
|
||||||
wrapper.sendToServer(Protocol1_20_5To1_21.class);
|
wrapper.sendToServer(Protocol1_20_5To1_21.class);
|
||||||
|
@ -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.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.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.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.EntityRewriter;
|
||||||
import com.viaversion.viaversion.rewriter.RegistryDataRewriter;
|
import com.viaversion.viaversion.rewriter.RegistryDataRewriter;
|
||||||
|
|
||||||
@ -123,48 +123,51 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPa
|
|||||||
|
|
||||||
// Resend attribute modifiers from items
|
// Resend attribute modifiers from items
|
||||||
wrapper.user().get(EfficiencyAttributeStorage.class).onRespawn(wrapper.user());
|
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 -> {
|
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS, wrapper -> {
|
||||||
if (!Via.getConfig().fix1_21PlacementRotation()) {
|
if (Via.getConfig().fix1_21PlacementRotation()) {
|
||||||
return;
|
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 -> {
|
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_ROT, wrapper -> {
|
||||||
if (!Via.getConfig().fix1_21PlacementRotation()) {
|
if (Via.getConfig().fix1_21PlacementRotation()) {
|
||||||
return;
|
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 -> {
|
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS_ROT, wrapper -> {
|
||||||
if (!Via.getConfig().fix1_21PlacementRotation()) {
|
if (Via.getConfig().fix1_21PlacementRotation()) {
|
||||||
return;
|
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 -> {
|
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_STATUS_ONLY, wrapper -> {
|
||||||
if (!Via.getConfig().fix1_21PlacementRotation()) {
|
if (Via.getConfig().fix1_21PlacementRotation()) {
|
||||||
return;
|
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
|
@Override
|
||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
filter().handler((event, data) -> {
|
filter().handler((event, data) -> {
|
||||||
|
@ -19,10 +19,31 @@ package com.viaversion.viaversion.protocols.v1_20_5to1_21.storage;
|
|||||||
|
|
||||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
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;
|
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() {
|
public boolean onGround() {
|
||||||
return onGround;
|
return onGround;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user