From 067395ab2a6966f02a2b1538104d866e2880042d Mon Sep 17 00:00:00 2001 From: BruceChen Date: Sat, 21 Mar 2026 12:11:18 +0800 Subject: [PATCH] fix: correct biome data array length calculation for 1.21.5+ terrain parsing The biome PalettedContainer data array length was calculated as ceil(64 * bitsPerEntry / 64) which is incorrect for non-power-of-2 bit widths. The correct calculation uses SimpleBitStorage's formula: valuesPerLong = 64 / bitsPerEntry, then ceil(64 / valuesPerLong). For example, with bitsPerEntry=3: old formula gave 3 longs but the actual data contains 4 longs (valuesPerLong=21, ceil(64/21)=4). This bug was masked in 1.21.5 by excess padding bytes in chunk buffers (due to PalettedContainer.Data.getSerializedSize over-counting). MC 1.21.6 fixed the size calculation server-side, removing the padding and exposing this pre-existing MCC bug. Made-with: Cursor --- MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs b/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs index 75bf7b34..09f99cf5 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs @@ -213,7 +213,9 @@ namespace MinecraftClient.Protocol.Handlers { // 1.21.5: No VarInt length prefix; calculate from bits per entry // Biome container has 64 entries (4x4x4) - int dataArrayLength = (64 * bitsPerEntryBiome + 63) / 64; + // Uses SimpleBitStorage: valuesPerLong = 64/bitsPerEntry, longs = ceil(64/valuesPerLong) + int valuesPerLong = 64 / bitsPerEntryBiome; + int dataArrayLength = (64 + valuesPerLong - 1) / valuesPerLong; dataTypes.DropData(dataArrayLength * 8, cache); } else