1
0

MCServer world compatiblity with vanilla and mcedit.

This commit is contained in:
Howaner 2014-09-23 19:16:17 +02:00
parent 33f8091d5f
commit 366af5067b
3 changed files with 52 additions and 5 deletions

View File

@ -765,6 +765,22 @@ void cNBTChunkSerializer::LightIsValid(bool a_IsLightValid)
void cNBTChunkSerializer::HeightMap(const cChunkDef::HeightMap * a_HeightMap)
{
for (int RelX = 0; RelX < cChunkDef::Width; RelX++)
{
for (int RelZ = 0; RelZ < cChunkDef::Width; RelZ++)
{
int Height = cChunkDef::GetHeight(*a_HeightMap, RelX, RelZ);
m_VanillaHeightMap[(RelZ << 4) | RelX] = Height;
}
}
}
void cNBTChunkSerializer::BiomeData(const cChunkDef::BiomeMap * a_BiomeMap) void cNBTChunkSerializer::BiomeData(const cChunkDef::BiomeMap * a_BiomeMap)
{ {
memcpy(m_Biomes, a_BiomeMap, sizeof(m_Biomes)); memcpy(m_Biomes, a_BiomeMap, sizeof(m_Biomes));

View File

@ -59,6 +59,7 @@ class cNBTChunkSerializer :
public: public:
cChunkDef::BiomeMap m_Biomes; cChunkDef::BiomeMap m_Biomes;
unsigned char m_VanillaBiomes[cChunkDef::Width * cChunkDef::Width]; unsigned char m_VanillaBiomes[cChunkDef::Width * cChunkDef::Width];
int m_VanillaHeightMap[cChunkDef::Width * cChunkDef::Width];
bool m_BiomesAreValid; bool m_BiomesAreValid;
@ -125,6 +126,7 @@ protected:
// cChunkDataSeparateCollector overrides: // cChunkDataSeparateCollector overrides:
virtual void LightIsValid(bool a_IsLightValid) override; virtual void LightIsValid(bool a_IsLightValid) override;
virtual void HeightMap(const cChunkDef::HeightMap * a_HeightMap) override;
virtual void BiomeData(const cChunkDef::BiomeMap * a_BiomeMap) override; virtual void BiomeData(const cChunkDef::BiomeMap * a_BiomeMap) override;
virtual void Entity(cEntity * a_Entity) override; virtual void Entity(cEntity * a_Entity) override;
virtual void BlockEntity(cBlockEntity * a_Entity) override; virtual void BlockEntity(cBlockEntity * a_Entity) override;

View File

@ -96,10 +96,26 @@ cWSSAnvil::cWSSAnvil(cWorld * a_World, int a_CompressionFactor) :
if (!cFile::Exists(fnam)) if (!cFile::Exists(fnam))
{ {
cFastNBTWriter Writer; cFastNBTWriter Writer;
Writer.BeginCompound(""); Writer.BeginCompound("Data");
Writer.AddInt("SpawnX", (int)(a_World->GetSpawnX())); Writer.AddByte("allowCommands", 1);
Writer.AddInt("SpawnY", (int)(a_World->GetSpawnY())); Writer.AddByte("Difficulty", 2);
Writer.AddInt("SpawnZ", (int)(a_World->GetSpawnZ())); Writer.AddByte("hardcore", 0);
Writer.AddByte("initialized", 1);
Writer.AddByte("MapFeatures", 1);
Writer.AddByte("raining", a_World->IsWeatherRain() ? 1 : 0);
Writer.AddByte("thundering", a_World->IsWeatherStorm() ? 1 : 0);
Writer.AddInt("GameType", (int)a_World->GetGameMode());
Writer.AddInt("generatorVersion", 1);
Writer.AddInt("SpawnX", (int)a_World->GetSpawnX());
Writer.AddInt("SpawnY", (int)a_World->GetSpawnY());
Writer.AddInt("SpawnZ", (int)a_World->GetSpawnZ());
Writer.AddInt("version", 19133);
Writer.AddLong("DayTime", (Int64)a_World->GetTimeOfDay());
Writer.AddLong("Time", a_World->GetWorldAge());
Writer.AddLong("SizeOnDisk", 0);
Writer.AddString("generatorName", "default");
Writer.AddString("generatorOptions", "");
Writer.AddString("LevelName", a_World->GetName());
Writer.EndCompound(); Writer.EndCompound();
Writer.Finish(); Writer.Finish();
@ -440,6 +456,13 @@ bool cWSSAnvil::SaveChunkToNBT(const cChunkCoords & a_Chunk, cFastNBTWriter & a_
a_Writer.BeginCompound("Level"); a_Writer.BeginCompound("Level");
a_Writer.AddInt("xPos", a_Chunk.m_ChunkX); a_Writer.AddInt("xPos", a_Chunk.m_ChunkX);
a_Writer.AddInt("zPos", a_Chunk.m_ChunkZ); a_Writer.AddInt("zPos", a_Chunk.m_ChunkZ);
// Add "Entities" and "TileEntities". MCEdit can't load the chunk if one of these lists doesn't exists.
a_Writer.BeginList("Entities", TAG_Compound);
a_Writer.EndList();
a_Writer.BeginList("TileEntities", TAG_Compound);
a_Writer.EndList();
cNBTChunkSerializer Serializer(a_Writer); cNBTChunkSerializer Serializer(a_Writer);
if (!m_World->GetChunkData(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, Serializer)) if (!m_World->GetChunkData(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, Serializer))
{ {
@ -454,7 +477,10 @@ bool cWSSAnvil::SaveChunkToNBT(const cChunkCoords & a_Chunk, cFastNBTWriter & a_
a_Writer.AddByteArray("Biomes", (const char *)(Serializer.m_VanillaBiomes), ARRAYCOUNT(Serializer.m_VanillaBiomes)); a_Writer.AddByteArray("Biomes", (const char *)(Serializer.m_VanillaBiomes), ARRAYCOUNT(Serializer.m_VanillaBiomes));
a_Writer.AddIntArray ("MCSBiomes", (const int *)(Serializer.m_Biomes), ARRAYCOUNT(Serializer.m_Biomes)); a_Writer.AddIntArray ("MCSBiomes", (const int *)(Serializer.m_Biomes), ARRAYCOUNT(Serializer.m_Biomes));
} }
// Save heightmap (Vanilla require this):
a_Writer.AddIntArray("HeightMap", (const int *)Serializer.m_VanillaHeightMap, ARRAYCOUNT(Serializer.m_VanillaHeightMap));
// Save blockdata: // Save blockdata:
a_Writer.BeginList("Sections", TAG_Compound); a_Writer.BeginList("Sections", TAG_Compound);
size_t SliceSizeBlock = cChunkDef::Width * cChunkDef::Width * 16; size_t SliceSizeBlock = cChunkDef::Width * cChunkDef::Width * 16;
@ -485,6 +511,9 @@ bool cWSSAnvil::SaveChunkToNBT(const cChunkCoords & a_Chunk, cFastNBTWriter & a_
{ {
a_Writer.AddByte("MCSIsLightValid", 1); a_Writer.AddByte("MCSIsLightValid", 1);
} }
// Save the world age to the chunk data. Required by vanilla and mcedit.
a_Writer.AddLong("LastUpdate", m_World->GetWorldAge());
// Store the flag that the chunk has all the ores, trees, dungeons etc. MCS chunks are always complete. // Store the flag that the chunk has all the ores, trees, dungeons etc. MCS chunks are always complete.
a_Writer.AddByte("TerrainPopulated", 1); a_Writer.AddByte("TerrainPopulated", 1);