summaryrefslogtreecommitdiffstats
path: root/src/Protocol/ChunkDataSerializer.cpp
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-09-04 19:03:21 +0200
committerHowaner <franzi.moos@googlemail.com>2014-09-04 19:03:21 +0200
commitda28c70def4be849925709b2c4d4857b6db1abb8 (patch)
treee334f02678b7efe7c0bdaaa5672b0ce8528dc340 /src/Protocol/ChunkDataSerializer.cpp
parentAdded more 1.8 protocol things. (diff)
downloadcuberite-da28c70def4be849925709b2c4d4857b6db1abb8.tar
cuberite-da28c70def4be849925709b2c4d4857b6db1abb8.tar.gz
cuberite-da28c70def4be849925709b2c4d4857b6db1abb8.tar.bz2
cuberite-da28c70def4be849925709b2c4d4857b6db1abb8.tar.lz
cuberite-da28c70def4be849925709b2c4d4857b6db1abb8.tar.xz
cuberite-da28c70def4be849925709b2c4d4857b6db1abb8.tar.zst
cuberite-da28c70def4be849925709b2c4d4857b6db1abb8.zip
Diffstat (limited to '')
-rw-r--r--src/Protocol/ChunkDataSerializer.cpp32
1 files changed, 7 insertions, 25 deletions
diff --git a/src/Protocol/ChunkDataSerializer.cpp b/src/Protocol/ChunkDataSerializer.cpp
index 9eadc4f0b..29e32ce32 100644
--- a/src/Protocol/ChunkDataSerializer.cpp
+++ b/src/Protocol/ChunkDataSerializer.cpp
@@ -182,19 +182,11 @@ void cChunkDataSerializer::Serialize80(AString & a_Data)
// Blocktypes converter (1.8 included the meta into the blocktype):
unsigned short Blocks[ARRAYCOUNT(m_BlockTypes)];
- for (int RelX = 0; RelX < cChunkDef::Width; RelX++)
+ for (size_t Index = 0; Index < cChunkDef::NumBlocks; Index++)
{
- for (int RelZ = 0; RelZ < cChunkDef::Width; RelZ++)
- {
- for (int RelY = 0; RelY < cChunkDef::Height; RelY++)
- {
- int Index = cChunkDef::MakeIndexNoCheck(RelX, RelY, RelZ);
- BLOCKTYPE BlockType = m_BlockTypes[Index];
- NIBBLETYPE BlockMeta = m_BlockMetas[Index / 2] >> ((Index & 1) * 4) & 0x0f;
-
- Blocks[Index] = ((unsigned short)BlockType << 4) | ((unsigned short)BlockMeta & 15);
- }
- }
+ BLOCKTYPE BlockType = m_BlockTypes[Index];
+ NIBBLETYPE BlockMeta = m_BlockMetas[Index / 2] >> ((Index & 1) * 4) & 0x0f;
+ Blocks[Index] = ((unsigned short)BlockType << 4) | ((unsigned short)BlockMeta);
}
const int BiomeDataSize = cChunkDef::Width * cChunkDef::Width;
@@ -216,23 +208,13 @@ void cChunkDataSerializer::Serialize80(AString & a_Data)
// Two bitmaps; we're aways sending the full chunk with no additional data, so the bitmaps are 0xffff and 0, respectively
// Also, no endian flipping is needed because of the const values
unsigned short BitMap = 0xffff;
- a_Data.append((const char *)&BitMap, sizeof(short));
+ a_Data.append((const char *)&BitMap, sizeof(unsigned short));
// Write chunk size:
UInt32 ChunkSize = htonl((UInt32)DataSize);
+ a_Data.append((const char *)&ChunkSize, 4);
- unsigned char b[5]; // // A 32-bit integer can be encoded by at most 5 bytes
- size_t idx = 0;
- UInt32 Value = ChunkSize;
- do
- {
- b[idx] = (Value & 0x7f) | ((Value > 0x7f) ? 0x80 : 0x00);
- Value = Value >> 7;
- idx++;
- } while (Value > 0);
- a_Data.append((const char *)b, idx);
-
- a_Data.append(AllData, ChunkSize); // Chunk data
+ a_Data.append(AllData, DataSize); // Chunk data
}