Merge pull request #1449 from mc-server/WorldLoader
MCServer world compatiblity with vanilla and mcedit.
This commit is contained in:
commit
2867672815
@ -81,6 +81,18 @@ void cNBTChunkSerializer::Finish(void)
|
||||
memset(m_BlockLight, 0, sizeof(m_BlockLight));
|
||||
memset(m_BlockSkyLight, 0, sizeof(m_BlockSkyLight));
|
||||
}
|
||||
|
||||
// Check if "Entity" and "TileEntities" lists exists. MCEdit requires this.
|
||||
if (!m_HasHadEntity)
|
||||
{
|
||||
m_Writer.BeginList("Entities", TAG_Compound);
|
||||
m_Writer.EndList();
|
||||
}
|
||||
if (!m_HasHadBlockEntity)
|
||||
{
|
||||
m_Writer.BeginList("TileEntities", TAG_Compound);
|
||||
m_Writer.EndList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -765,6 +777,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)
|
||||
{
|
||||
memcpy(m_Biomes, a_BiomeMap, sizeof(m_Biomes));
|
||||
|
@ -59,6 +59,7 @@ class cNBTChunkSerializer :
|
||||
public:
|
||||
cChunkDef::BiomeMap m_Biomes;
|
||||
unsigned char m_VanillaBiomes[cChunkDef::Width * cChunkDef::Width];
|
||||
int m_VanillaHeightMap[cChunkDef::Width * cChunkDef::Width];
|
||||
bool m_BiomesAreValid;
|
||||
|
||||
|
||||
@ -125,6 +126,7 @@ protected:
|
||||
|
||||
// cChunkDataSeparateCollector overrides:
|
||||
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 Entity(cEntity * a_Entity) override;
|
||||
virtual void BlockEntity(cBlockEntity * a_Entity) override;
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include "../Entities/ItemFrame.h"
|
||||
|
||||
#include "../Protocol/MojangAPI.h"
|
||||
#include "Server.h"
|
||||
|
||||
|
||||
|
||||
@ -96,10 +97,26 @@ cWSSAnvil::cWSSAnvil(cWorld * a_World, int a_CompressionFactor) :
|
||||
if (!cFile::Exists(fnam))
|
||||
{
|
||||
cFastNBTWriter Writer;
|
||||
Writer.BeginCompound("");
|
||||
Writer.AddInt("SpawnX", (int)(a_World->GetSpawnX()));
|
||||
Writer.AddInt("SpawnY", (int)(a_World->GetSpawnY()));
|
||||
Writer.AddInt("SpawnZ", (int)(a_World->GetSpawnZ()));
|
||||
Writer.BeginCompound("Data");
|
||||
Writer.AddByte("allowCommands", 1);
|
||||
Writer.AddByte("Difficulty", 2);
|
||||
Writer.AddByte("hardcore", cRoot::Get()->GetServer()->IsHardcore() ? 1 : 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.Finish();
|
||||
|
||||
@ -440,6 +457,7 @@ bool cWSSAnvil::SaveChunkToNBT(const cChunkCoords & a_Chunk, cFastNBTWriter & a_
|
||||
a_Writer.BeginCompound("Level");
|
||||
a_Writer.AddInt("xPos", a_Chunk.m_ChunkX);
|
||||
a_Writer.AddInt("zPos", a_Chunk.m_ChunkZ);
|
||||
|
||||
cNBTChunkSerializer Serializer(a_Writer);
|
||||
if (!m_World->GetChunkData(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, Serializer))
|
||||
{
|
||||
@ -454,7 +472,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.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:
|
||||
a_Writer.BeginList("Sections", TAG_Compound);
|
||||
size_t SliceSizeBlock = cChunkDef::Width * cChunkDef::Width * 16;
|
||||
@ -485,6 +506,9 @@ bool cWSSAnvil::SaveChunkToNBT(const cChunkCoords & a_Chunk, cFastNBTWriter & a_
|
||||
{
|
||||
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.
|
||||
a_Writer.AddByte("TerrainPopulated", 1);
|
||||
|
Loading…
Reference in New Issue
Block a user