From cb1edaf6df5575c28b50462bc98c5a6072b449b5 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 12 Mar 2012 19:29:31 +0000 Subject: Fixed MapChunk packets to include (fake) biome data, makes clients happy git-svn-id: http://mc-server.googlecode.com/svn/trunk@403 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/packets/cPacket_MapChunk.cpp | 29 ++++++++++++++++------------- source/packets/cPacket_MapChunk.h | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'source/packets') diff --git a/source/packets/cPacket_MapChunk.cpp b/source/packets/cPacket_MapChunk.cpp index 791b81425..18b924f15 100644 --- a/source/packets/cPacket_MapChunk.cpp +++ b/source/packets/cPacket_MapChunk.cpp @@ -19,7 +19,7 @@ cPacket_MapChunk::~cPacket_MapChunk() -cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, char * a_BlockData) +cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const char * a_BlockData, const char * a_BiomeData) { m_PacketID = E_MAP_CHUNK; @@ -29,18 +29,19 @@ cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cha m_PosX = a_ChunkX; // Chunk coordinates now, instead of block coordinates m_PosZ = a_ChunkZ; - m_bContiguous = false; + m_bContiguous = true; // false = no biome data, true = with biome data m_BitMap1 = 0; m_BitMap2 = 0; m_UnusedInt = 0; - unsigned int DataSize = (cChunk::c_ChunkHeight / 16) * (4096 + 2048 + 2048 + 2048); - std::auto_ptr AllData(new char[ DataSize ]); + const int BlockDataSize = (cChunk::c_ChunkHeight / 16) * (4096 + 2048 + 2048 + 2048); + const int BiomeDataSize = cChunk::c_ChunkWidth * cChunk::c_ChunkWidth; + char AllData [ BlockDataSize + BiomeDataSize ]; #if AXIS_ORDER == AXIS_ORDER_YZX - memset( AllData.get(), 0, DataSize ); + memset( AllData, 0, BlockDataSize ); unsigned int iterator = 0; for ( int i = 0; i < (cChunk::c_ChunkHeight / 16); ++i ) @@ -49,7 +50,7 @@ cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cha for ( int y = 0; y < 16; ++y ) for( int z = 0; z < 16; ++z ) for( int x = 0; x < 16; ++x ) { int idx = cChunk::MakeIndex(x, y + i * 16, z); - AllData.get()[iterator] = a_BlockData[idx]; + AllData[iterator] = a_BlockData[idx]; ++iterator; } // for y, z, x } @@ -62,7 +63,7 @@ cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cha { for ( int x = 0; x < 8; ++x ) { - AllData.get()[iterator] = cChunk::GetNibble(Meta, x * 2 + 0, y + i * 16, z) | (cChunk::GetNibble(Meta, x * 2 + 1, y + i * 16, z ) << 4); + AllData[iterator] = cChunk::GetNibble(Meta, x * 2 + 0, y + i * 16, z) | (cChunk::GetNibble(Meta, x * 2 + 1, y + i * 16, z ) << 4); ++iterator; } // for x } // for y, z @@ -76,7 +77,7 @@ cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cha { for ( int x = 0; x < 8; ++x ) { - AllData.get()[iterator] = cChunk::GetNibble(Light, x * 2 + 0, y + i * 16, z ) | (cChunk::GetNibble(Light, x * 2 + 1, y + i * 16, z ) << 4); + AllData[iterator] = cChunk::GetNibble(Light, x * 2 + 0, y + i * 16, z ) | (cChunk::GetNibble(Light, x * 2 + 1, y + i * 16, z ) << 4); ++iterator; } } @@ -90,23 +91,25 @@ cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cha { for( int x = 0; x < 8; ++x ) { - AllData.get()[iterator] = cChunk::GetNibble(SkyLight, x * 2 + 0, y + i * 16, z ) | (cChunk::GetNibble(SkyLight, x * 2 + 1, y + i * 16, z ) << 4); + AllData[iterator] = cChunk::GetNibble(SkyLight, x * 2 + 0, y + i * 16, z ) | (cChunk::GetNibble(SkyLight, x * 2 + 1, y + i * 16, z ) << 4); ++iterator; } } } + memcpy(AllData + BlockDataSize, a_BiomeData, BiomeDataSize); #elif AXIS_ORDER == AXIS_ORDER_XZY for ( int i = 0; i < 16; ++i ) { m_BitMap1 |= (1 << i); } - memcpy( AllData.get(), a_BlockData, DataSize ); -#endif + memcpy(AllData, a_BlockData, BlockDataSize); + memcpy(AllData + BlockDataSize, a_BiomeData, BiomeDataSize); +#endif // AXIS_ORDER - uLongf CompressedSize = compressBound( DataSize ); + uLongf CompressedSize = compressBound( sizeof(AllData) ); char * CompressedBlockData = new char[CompressedSize]; - compress2( (Bytef*)CompressedBlockData, &CompressedSize, (const Bytef*)AllData.get(), DataSize, Z_DEFAULT_COMPRESSION); + compress2( (Bytef*)CompressedBlockData, &CompressedSize, (const Bytef*)AllData, sizeof(AllData), Z_DEFAULT_COMPRESSION); m_CompressedData = CompressedBlockData; m_CompressedSize = CompressedSize; diff --git a/source/packets/cPacket_MapChunk.h b/source/packets/cPacket_MapChunk.h index db4192457..1dd05f9ef 100644 --- a/source/packets/cPacket_MapChunk.h +++ b/source/packets/cPacket_MapChunk.h @@ -33,7 +33,7 @@ public: { m_PacketID = E_MAP_CHUNK; m_CompressedData = 0; } cPacket_MapChunk( const cPacket_MapChunk & a_Copy ); - cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, char * a_BlockData); + cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const char * a_BlockData, const char * a_BiomeData); ~cPacket_MapChunk(); virtual cPacket* Clone() const { return new cPacket_MapChunk(*this); } -- cgit v1.2.3