1
0

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
This commit is contained in:
madmaxoft@gmail.com 2012-03-12 19:29:31 +00:00
parent b789d5ebf6
commit cb1edaf6df
5 changed files with 55 additions and 15 deletions

View File

@ -395,3 +395,38 @@ enum ENUM_ITEM_ID
E_ITEM_11_DISC = 2266, E_ITEM_11_DISC = 2266,
}; };
//tolua_end //tolua_end
/// Biome IDs, as stored in the Anvil format and sent in the MapChunk packet
enum eBiomeID
{
biOcean = 0,
biPlains = 1,
biDesert = 2,
biExtremeHills = 3,
biForest = 4,
biTaiga = 5,
biSwampland = 6,
biRiver = 7,
biHell = 8, // Nether?
biSky = 9,
biFrozenOcean = 10,
biFrozenRiver = 11,
biIcePlains = 12,
biIceMountains = 13,
biMushroomIsland = 14,
biMushroomShore = 15,
biBeach = 16,
biDesertHills = 17,
biForestHills = 18,
biTaigaHills = 19,
biExtremeHillsEdge = 20,
biJungle = 21,
biJungleHills = 22,
} ;

View File

@ -22,6 +22,7 @@ cChunkSender::cChunkSender(void) :
super("ChunkSender"), super("ChunkSender"),
m_World(NULL) m_World(NULL)
{ {
memset(m_BiomeData, biPlains, sizeof(m_BiomeData));
} }
@ -171,7 +172,7 @@ void cChunkSender::SendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cClientHa
return; return;
} }
cPacket_PreChunk PreChunk(a_ChunkX, a_ChunkZ, true); cPacket_PreChunk PreChunk(a_ChunkX, a_ChunkZ, true);
cPacket_MapChunk MapChunk(a_ChunkX, a_ChunkY, a_ChunkZ, m_BlockData); cPacket_MapChunk MapChunk(a_ChunkX, a_ChunkY, a_ChunkZ, m_BlockData, m_BiomeData);
// Send: // Send:
if (a_Client == NULL) if (a_Client == NULL)

View File

@ -102,6 +102,7 @@ protected:
// Data about the chunk that is being sent: // Data about the chunk that is being sent:
char m_BlockData[cChunk::c_BlockDataSize]; char m_BlockData[cChunk::c_BlockDataSize];
char m_BiomeData[cChunk::c_ChunkWidth * cChunk::c_ChunkWidth];
PacketList m_Packets; // Accumulator for the entity-packets to send PacketList m_Packets; // Accumulator for the entity-packets to send
// cIsThread override: // cIsThread override:

View File

@ -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; 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_PosX = a_ChunkX; // Chunk coordinates now, instead of block coordinates
m_PosZ = a_ChunkZ; m_PosZ = a_ChunkZ;
m_bContiguous = false; m_bContiguous = true; // false = no biome data, true = with biome data
m_BitMap1 = 0; m_BitMap1 = 0;
m_BitMap2 = 0; m_BitMap2 = 0;
m_UnusedInt = 0; m_UnusedInt = 0;
unsigned int DataSize = (cChunk::c_ChunkHeight / 16) * (4096 + 2048 + 2048 + 2048); const int BlockDataSize = (cChunk::c_ChunkHeight / 16) * (4096 + 2048 + 2048 + 2048);
std::auto_ptr<char> AllData(new char[ DataSize ]); const int BiomeDataSize = cChunk::c_ChunkWidth * cChunk::c_ChunkWidth;
char AllData [ BlockDataSize + BiomeDataSize ];
#if AXIS_ORDER == AXIS_ORDER_YZX #if AXIS_ORDER == AXIS_ORDER_YZX
memset( AllData.get(), 0, DataSize ); memset( AllData, 0, BlockDataSize );
unsigned int iterator = 0; unsigned int iterator = 0;
for ( int i = 0; i < (cChunk::c_ChunkHeight / 16); ++i ) 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 ) 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); int idx = cChunk::MakeIndex(x, y + i * 16, z);
AllData.get()[iterator] = a_BlockData[idx]; AllData[iterator] = a_BlockData[idx];
++iterator; ++iterator;
} // for y, z, x } // 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 ) 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; ++iterator;
} // for x } // for x
} // for y, z } // 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 ) 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; ++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 ) 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; ++iterator;
} }
} }
} }
memcpy(AllData + BlockDataSize, a_BiomeData, BiomeDataSize);
#elif AXIS_ORDER == AXIS_ORDER_XZY #elif AXIS_ORDER == AXIS_ORDER_XZY
for ( int i = 0; i < 16; ++i ) for ( int i = 0; i < 16; ++i )
{ {
m_BitMap1 |= (1 << i); m_BitMap1 |= (1 << i);
} }
memcpy( AllData.get(), a_BlockData, DataSize ); memcpy(AllData, a_BlockData, BlockDataSize);
#endif memcpy(AllData + BlockDataSize, a_BiomeData, BiomeDataSize);
#endif // AXIS_ORDER
uLongf CompressedSize = compressBound( DataSize ); uLongf CompressedSize = compressBound( sizeof(AllData) );
char * CompressedBlockData = new char[CompressedSize]; 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_CompressedData = CompressedBlockData;
m_CompressedSize = CompressedSize; m_CompressedSize = CompressedSize;

View File

@ -33,7 +33,7 @@ public:
{ m_PacketID = E_MAP_CHUNK; m_CompressedData = 0; } { m_PacketID = E_MAP_CHUNK; m_CompressedData = 0; }
cPacket_MapChunk( const cPacket_MapChunk & a_Copy ); 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(); ~cPacket_MapChunk();
virtual cPacket* Clone() const { return new cPacket_MapChunk(*this); } virtual cPacket* Clone() const { return new cPacket_MapChunk(*this); }