From 416badb6b077321b73d4827b11077617d077adb8 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sun, 30 Jun 2024 23:27:51 +0100 Subject: Count non-air blocks and use the real count not 4096. --- src/Protocol/ChunkDataSerializer.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Protocol/ChunkDataSerializer.cpp b/src/Protocol/ChunkDataSerializer.cpp index 6b5553ee7..6f95fb472 100644 --- a/src/Protocol/ChunkDataSerializer.cpp +++ b/src/Protocol/ChunkDataSerializer.cpp @@ -502,7 +502,21 @@ inline void cChunkDataSerializer::Serialize477(const int a_ChunkX, const int a_C // Write each chunk section... ChunkDef_ForEachSection(a_BlockData, a_LightData, { - m_Packet.WriteBEInt16(ChunkBlockData::SectionBlockCount); // a temp fix to make sure sections don't disappear + // Count non-air blocks. + int BlockCount = 0; + if (Blocks != nullptr) + { + for (size_t i = 0; i != ChunkBlockData::SectionBlockCount; i++) + { + const BLOCKTYPE BlockType = (*Blocks)[i]; + if (BlockType != E_BLOCK_AIR) + { + BlockCount++; + } + } + } + + m_Packet.WriteBEInt16(BlockCount); m_Packet.WriteBEUInt8(BitsPerEntry); m_Packet.WriteVarInt32(static_cast(ChunkSectionDataArraySize)); WriteBlockSectionSeamless<&Palette477>(Blocks, Metas, BitsPerEntry); -- cgit v1.2.3