Fix empty chunk serializer for protocol 47 (#5514)

(Minecraft 1.8)

Co-authored-by: Sergey Lisov <sleirsgoevy@gmial.com>
This commit is contained in:
sleirsgoevy 2023-10-18 23:32:02 +03:00 committed by GitHub
parent ebeb164d2b
commit ca705be264
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -76,6 +76,7 @@ rs2k
SamJBarney
Schwertspize
Seadragon91 (Lukas Pioch)
sleirsgoevy (Sergey Lisov)
Sofapriester
Spekdrum (Pablo Beltran)
SphinxC0re

View File

@ -196,12 +196,16 @@ inline void cChunkDataSerializer::Serialize47(const int a_ChunkX, const int a_Ch
m_Packet.WriteBEInt32(a_ChunkX);
m_Packet.WriteBEInt32(a_ChunkZ);
m_Packet.WriteBool(true); // "Ground-up continuous", or rather, "biome data present" flag
m_Packet.WriteBEUInt16(Bitmask.first);
// Minecraft 1.8 does not like completely empty packets
// Send one completely empty chunk section if this is the case
m_Packet.WriteBEUInt16(Bitmask.first ? Bitmask.first : 1);
// Write the chunk size:
// Account for the single empty section if sending an empty chunk
const int BiomeDataSize = cChunkDef::Width * cChunkDef::Width;
const size_t ChunkSize = (
Bitmask.second * (ChunkBlockData::SectionBlockCount * 2 + ChunkLightData::SectionLightCount * 2) + // Blocks and lighting
(Bitmask.second ? Bitmask.second : 1) * (ChunkBlockData::SectionBlockCount * 2 + ChunkLightData::SectionLightCount * 2) + // Blocks and lighting
BiomeDataSize // Biome data
);
m_Packet.WriteVarInt32(static_cast<UInt32>(ChunkSize));
@ -250,6 +254,19 @@ inline void cChunkDataSerializer::Serialize47(const int a_ChunkX, const int a_Ch
}
});
// Serialize a single empty section if sending an empty chunk
if (!Bitmask.first)
{
// Block data (all air)
for (size_t i = 0; i < ChunkBlockData::SectionBlockCount * 2; i++)
{
m_Packet.WriteBEUInt8(0);
}
// Light data (XXX: sky light is not sent if in the nether)
m_Packet.WriteBuf(ChunkLightData::SectionLightCount, ChunkLightData::DefaultSkyLightValue);
m_Packet.WriteBuf(ChunkLightData::SectionLightCount, ChunkLightData::DefaultSkyLightValue);
}
// Write the biome data:
m_Packet.WriteBuf(a_BiomeMap, BiomeDataSize);
}