Don't swap teleport accept and move packets for 1.21.4 clients

They changed it again. Probably missing the same swap in 1.21.4<->1.21.2 now
This commit is contained in:
Nassim Jahnke 2024-11-26 17:34:57 +01:00
parent cfa20ba418
commit d3f92ce9b8
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
2 changed files with 16 additions and 6 deletions

View File

@ -172,7 +172,8 @@ public final class Protocol1_21To1_21_2 extends AbstractProtocol<ClientboundPack
registerClientbound(ClientboundPackets1_21.BUNDLE_DELIMITER, wrapper -> wrapper.user().get(BundleStateTracker.class).toggleBundling());
registerServerbound(ServerboundPackets1_21_2.PONG, wrapper -> {
final int id = wrapper.passthrough(Types.INT); // id
if (wrapper.user().get(PlayerPositionStorage.class).checkPong(id)) {
final PlayerPositionStorage playerPositionStorage = wrapper.user().get(PlayerPositionStorage.class);
if (playerPositionStorage != null && playerPositionStorage.checkPong(id)) {
wrapper.cancel();
}
});
@ -234,13 +235,17 @@ public final class Protocol1_21To1_21_2 extends AbstractProtocol<ClientboundPack
public void init(final UserConnection connection) {
addEntityTracker(connection, new EntityTracker1_21_2(connection));
connection.put(new BundleStateTracker());
connection.put(new PlayerPositionStorage());
connection.put(new GroundFlagTracker());
final ProtocolVersion protocolVersion = connection.getProtocolInfo().protocolVersion();
if (protocolVersion.olderThan(ProtocolVersion.v1_21_4)) { // Only needed for 1.21.2/1.21.3
connection.put(new PlayerPositionStorage());
}
// <= 1.21.1 clients allowed loaded chunks to get replaced with new data without unloading them first.
// 1.21.2 introduced a graphical bug where it doesn't properly render the new data unless the chunk is unloaded beforehand.
// 1.21.4 fixed this bug, so the workaround is no longer needed.
if (connection.getProtocolInfo().protocolVersion().equals(ProtocolVersion.v1_21_2)) {
if (protocolVersion.equals(ProtocolVersion.v1_21_2)) {
connection.put(new ChunkLoadTracker());
}
}

View File

@ -200,6 +200,11 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
final int teleportId = wrapper.read(Types.VAR_INT);
wrapper.set(Types.VAR_INT, 0, teleportId);
final PlayerPositionStorage positionStorage = wrapper.user().get(PlayerPositionStorage.class);
if (positionStorage == null) {
return;
}
// Accept teleportation and player position were swapped.
// Send a ping first to then capture and send the player position the accept teleportation
final boolean isBundling = wrapper.user().get(BundleStateTracker.class).isBundling();
@ -209,7 +214,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
}
final int pingId = ThreadLocalRandom.current().nextInt();
wrapper.user().get(PlayerPositionStorage.class).addPendingPong(pingId);
positionStorage.addPendingPong(pingId);
final PacketWrapper ping = wrapper.create(ClientboundPackets1_21_2.PING);
ping.write(Types.INT, pingId); // id
ping.send(Protocol1_21To1_21_2.class);
@ -330,7 +335,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
handleOnGround(wrapper);
final PlayerPositionStorage playerPositionStorage = wrapper.user().get(PlayerPositionStorage.class);
if (playerPositionStorage.checkCaptureNextPlayerPositionPacket()) {
if (playerPositionStorage != null && playerPositionStorage.checkCaptureNextPlayerPositionPacket()) {
// Capture this packet and send it after accept teleportation
final boolean onGround = wrapper.get(Types.BOOLEAN, 0);
playerPositionStorage.setPlayerPosition(new PlayerPositionStorage.PlayerPosition(x, y, z, yaw, pitch, onGround));
@ -355,7 +360,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
});
protocol.registerServerbound(ServerboundPackets1_21_2.ACCEPT_TELEPORTATION, wrapper -> {
final PlayerPositionStorage playerPositionStorage = wrapper.user().get(PlayerPositionStorage.class);
if (playerPositionStorage.checkHasPlayerPosition()) {
if (playerPositionStorage != null && playerPositionStorage.checkHasPlayerPosition()) {
// Send move player after accept teleportation
wrapper.sendToServer(Protocol1_21To1_21_2.class);
wrapper.cancel();