Only apply chunk loading fix for 1.21.2 clients (#14)

This commit is contained in:
RK_01 2024-10-30 21:43:27 +01:00 committed by Nassim Jahnke
parent 0acec719b1
commit e539375143
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
3 changed files with 21 additions and 3 deletions

View File

@ -27,6 +27,7 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider; import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.rewriter.ComponentRewriter; import com.viaversion.viaversion.api.rewriter.ComponentRewriter;
import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.misc.ParticleType;
@ -234,8 +235,14 @@ public final class Protocol1_21To1_21_2 extends AbstractProtocol<ClientboundPack
addEntityTracker(connection, new EntityTracker1_21_2(connection)); addEntityTracker(connection, new EntityTracker1_21_2(connection));
connection.put(new BundleStateTracker()); connection.put(new BundleStateTracker());
connection.put(new PlayerPositionStorage()); connection.put(new PlayerPositionStorage());
connection.put(new ChunkLoadTracker());
connection.put(new GroundFlagTracker()); connection.put(new GroundFlagTracker());
// <= 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)) {
connection.put(new ChunkLoadTracker());
}
} }
@Override @Override

View File

@ -376,6 +376,10 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
} }
final ChunkLoadTracker chunkLoadTracker = wrapper.user().get(ChunkLoadTracker.class); final ChunkLoadTracker chunkLoadTracker = wrapper.user().get(ChunkLoadTracker.class);
if (chunkLoadTracker == null) {
return;
}
if (chunkLoadTracker.isChunkLoaded(chunk.getX(), chunk.getZ())) { if (chunkLoadTracker.isChunkLoaded(chunk.getX(), chunk.getZ())) {
// Unload the old chunk, so the new one can be loaded without graphical glitches // Unload the old chunk, so the new one can be loaded without graphical glitches
// Bundling it prevents the client from falling through the world during the chunk swap // Bundling it prevents the client from falling through the world during the chunk swap
@ -401,7 +405,11 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
}); });
protocol.registerClientbound(ClientboundPackets1_21.FORGET_LEVEL_CHUNK, wrapper -> { protocol.registerClientbound(ClientboundPackets1_21.FORGET_LEVEL_CHUNK, wrapper -> {
final ChunkPosition chunkPosition = wrapper.passthrough(Types.CHUNK_POSITION); final ChunkPosition chunkPosition = wrapper.passthrough(Types.CHUNK_POSITION);
wrapper.user().get(ChunkLoadTracker.class).removeChunk(chunkPosition.chunkX(), chunkPosition.chunkZ());
final ChunkLoadTracker chunkLoadTracker = wrapper.user().get(ChunkLoadTracker.class);
if (chunkLoadTracker != null) {
chunkLoadTracker.removeChunk(chunkPosition.chunkX(), chunkPosition.chunkZ());
}
}); });
} }

View File

@ -159,7 +159,10 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
final EntityTracker entityTracker = tracker(wrapper.user()); final EntityTracker entityTracker = tracker(wrapper.user());
if (entityTracker.currentWorld() != null && !entityTracker.currentWorld().equals(world)) { if (entityTracker.currentWorld() != null && !entityTracker.currentWorld().equals(world)) {
wrapper.user().get(ChunkLoadTracker.class).clear(); final ChunkLoadTracker chunkLoadTracker = wrapper.user().get(ChunkLoadTracker.class);
if (chunkLoadTracker != null) {
chunkLoadTracker.clear();
}
} }
trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world); trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world);