From 4d62899a10da957e1c0b0bdcbaccd9f01694064a Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Tue, 13 Oct 2026 00:52:35 +0200 Subject: [PATCH] Harness: force-load the spawn area so both servers serve full chunks Co-Authored-By: Claude Opus 5.5 --- .../parity/VanillaProtocolClient.java | 34 +++++++++++++++---- tools/test_dedicated_server_parity.py | 9 +++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaProtocolClient.java b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaProtocolClient.java index a26fb1687..b5b04a1f4 100644 --- a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaProtocolClient.java +++ b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaProtocolClient.java @@ -294,7 +294,7 @@ public final class VanillaProtocolClient { } return b.append('}').toString(); } - return s.replaceAll("@[0-9a-f]{4,}", "@"); + return s.replaceAll("\\$\\$Lambda/0x[0-9a-f]+@", "\\$\\$Lambda@").replaceAll("@[0-9a-f]{4,}", "@"); } private void record(String section, String line) { @@ -519,11 +519,31 @@ public final class VanillaProtocolClient { * loaded with their saved light, which test_light_parity covers. */ private static String chunkHash(ClientboundLevelChunkWithLightPacket p) { - RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(Unpooled.buffer(), ParityData.access); - ClientboundLevelChunkPacketData.STREAM_CODEC.encode(buf, p.chunkData()); - byte[] bytes = new byte[buf.readableBytes()]; - buf.readBytes(bytes); - return sha(bytes); + var data = p.chunkData(); + var heightmaps = new TreeMap(); + data.getHeightmaps().forEach((k, v) -> heightmaps.put(k.getSerializedName(), java.util.Arrays.toString(v))); + FriendlyByteBuf buf = data.getReadBuffer(); + byte[] sections = new byte[buf.readableBytes()]; + buf.getBytes(buf.readerIndex(), sections); + // What the sections hold, apart from how their palettes encode it. + FriendlyByteBuf copy = new FriendlyByteBuf(Unpooled.wrappedBuffer(sections)); + var factory = PalettedContainerFactory.create(ParityData.access); + StringBuilder content = new StringBuilder(); + while (copy.isReadable()) { + LevelChunkSection section = new LevelChunkSection(factory); + section.read(copy); + for (int y = 0; y < 16; y++) for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++) { + content.append(net.minecraft.world.level.block.Block.getId(section.getBlockState(x, y, z))).append(','); + } + for (int y = 0; y < 4; y++) for (int z = 0; z < 4; z++) for (int x = 0; x < 4; x++) { + content.append(section.getNoiseBiome(x, y, z).getRegisteredName()).append(','); + } + } + StringBuilder entities = new StringBuilder(); + data.forEachBlockEntityTag(p.x(), p.z(), (pos, type, tag) -> entities.append(pos.toShortString()).append(' ') + .append(net.minecraft.core.registries.BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(type)).append(' ').append(tag).append(';')); + return "c" + sha(content.toString().getBytes()).substring(0, 8) + "s" + sha(sections).substring(0, 8) + "h" + sha(heightmaps.toString().getBytes()).substring(0, 8) + "e" + + sha(entities.toString().getBytes()).substring(0, 8); } /** The light layers a chunk has, sky then block (with data or empty). */ @@ -623,6 +643,8 @@ public final class VanillaProtocolClient { return text(r.packet).replaceAll("playerId=-?\\d+", "playerId=_").replaceAll("levels=\\[(ResourceKey\\[[^\\]]*\\](, )?)*\\]", "levels=" + levels); } if (t.equals("minecraft:set_time") || t.equals("minecraft:keep_alive") || t.equals("minecraft:ping")) return ""; + // The tree is compared below, as sets: the children's order is vanilla's registration order. + if (t.equals("minecraft:commands")) return ""; if (t.equals("minecraft:set_entity_data")) { return text(((net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket) r.packet).packedItems()); } diff --git a/tools/test_dedicated_server_parity.py b/tools/test_dedicated_server_parity.py index 904dbbd3c..35d9a9399 100644 --- a/tools/test_dedicated_server_parity.py +++ b/tools/test_dedicated_server_parity.py @@ -254,6 +254,15 @@ def main(): server.wait_for(r'Done \(') server.console('gamerule respawn_radius 0') server.wait_for(r'respawn_radius', timeout=30) + # Vanilla keeps no spawn chunks: force-load the area the client is + # sent and its neighbours (the console stands at the world spawn) so + # both servers load full chunks instead of finishing proto-chunks. + server.console('forceload add ~-80 ~-80 ~80 ~80') + server.wait_for(r'chunks in the Overworld are now force loaded|forceloaded|force loaded', timeout=60) + time.sleep(20) + server.console('forceload remove all') + server.console('save-all flush') + server.wait_for(r'Saved the game', timeout=120) finally: server.stop() world = generate / 'world'