summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage
diff options
context:
space:
mode:
Diffstat (limited to 'src/WorldStorage')
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp17
-rw-r--r--src/WorldStorage/NBTChunkSerializer.h13
-rwxr-xr-xsrc/WorldStorage/WSSAnvil.cpp67
-rwxr-xr-xsrc/WorldStorage/WSSAnvil.h5
4 files changed, 50 insertions, 52 deletions
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index 8c60aac0d..1e8543648 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -7,6 +7,7 @@
#include "EnchantmentSerializer.h"
#include "../ItemGrid.h"
#include "../StringCompression.h"
+#include "../UUID.h"
#include "FastNBT.h"
#include "../BlockEntities/BeaconEntity.h"
@@ -67,11 +68,11 @@ void cNBTChunkSerializer::Finish(void)
m_Writer.EndList();
}
- // If light not valid, reset it to all zeroes:
+ // If light not valid, reset it to defaults:
if (!m_IsLightValid)
{
- memset(m_BlockLight, 0, sizeof(m_BlockLight));
- memset(m_BlockSkyLight, 0, sizeof(m_BlockSkyLight));
+ m_Data.FillBlockLight(0x00);
+ m_Data.FillSkyLight(0x0f);
}
// Check if "Entity" and "TileEntities" lists exists. MCEdit requires this.
@@ -382,7 +383,7 @@ void cNBTChunkSerializer::AddMobHeadEntity(cMobHeadEntity * a_MobHead)
// The new Block Entity format for a Mob Head. See: https://minecraft.gamepedia.com/Head#Block_entity
m_Writer.BeginCompound("Owner");
- m_Writer.AddString("Id", a_MobHead->GetOwnerUUID());
+ m_Writer.AddString("Id", a_MobHead->GetOwnerUUID().ToShortString());
m_Writer.AddString("Name", a_MobHead->GetOwnerName());
m_Writer.BeginCompound("Properties");
m_Writer.BeginList("textures", TAG_Compound);
@@ -679,9 +680,9 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
{
m_Writer.AddString("Owner", Wolf->GetOwnerName());
}
- if (!Wolf->GetOwnerUUID().empty())
+ if (!Wolf->GetOwnerUUID().IsNil())
{
- m_Writer.AddString("OwnerUUID", Wolf->GetOwnerUUID());
+ m_Writer.AddString("OwnerUUID", Wolf->GetOwnerUUID().ToShortString());
}
m_Writer.AddByte("Sitting", Wolf->IsSitting() ? 1 : 0);
m_Writer.AddByte("Angry", Wolf->IsAngry() ? 1 : 0);
@@ -709,9 +710,9 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
{
m_Writer.AddString("Owner", Ocelot->GetOwnerName());
}
- if (!Ocelot->GetOwnerUUID().empty())
+ if (!Ocelot->GetOwnerUUID().IsNil())
{
- m_Writer.AddString("OwnerUUID", Ocelot->GetOwnerUUID());
+ m_Writer.AddString("OwnerUUID", Ocelot->GetOwnerUUID().ToShortString());
}
m_Writer.AddByte("Sitting", Ocelot->IsSitting() ? 1 : 0);
m_Writer.AddInt ("CatType", Ocelot->GetOcelotType());
diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h
index 3637ea655..50d98a518 100644
--- a/src/WorldStorage/NBTChunkSerializer.h
+++ b/src/WorldStorage/NBTChunkSerializer.h
@@ -1,4 +1,4 @@
-
+
// NBTChunkSerializer.h
// Declares the cNBTChunkSerializer class that is used for saving individual chunks into NBT format used by Anvil
@@ -55,7 +55,7 @@ class cPainting;
class cNBTChunkSerializer :
- public cChunkDataSeparateCollector
+ public cChunkDataCopyCollector
{
public:
cChunkDef::BiomeMap m_Biomes;
@@ -69,15 +69,12 @@ public:
/** Close NBT tags that we've opened */
void Finish(void);
- bool IsLightValid(void) const {return m_IsLightValid; }
+ bool IsLightValid(void) const { return m_IsLightValid; }
protected:
- /* From cChunkDataSeparateCollector we inherit:
- - m_BlockTypes[]
- - m_BlockMetas[]
- - m_BlockLight[]
- - m_BlockSkyLight[] */
+ /* From cChunkDataCopyCollector we inherit:
+ - cChunkData m_Data */
cFastNBTWriter & m_Writer;
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 7aa3eb0cd..a3251481f 100755
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -515,23 +515,25 @@ bool cWSSAnvil::SaveChunkToNBT(const cChunkCoords & a_Chunk, cFastNBTWriter & a_
// Save blockdata:
a_Writer.BeginList("Sections", TAG_Compound);
- size_t SliceSizeBlock = cChunkDef::Width * cChunkDef::Width * 16;
- size_t SliceSizeNibble = SliceSizeBlock / 2;
- const char * BlockTypes = reinterpret_cast<const char *>(Serializer.m_BlockTypes);
- const char * BlockMetas = reinterpret_cast<const char *>(Serializer.m_BlockMetas);
- #ifdef DEBUG_SKYLIGHT
- const char * BlockLight = reinterpret_cast<const char *>(Serializer.m_BlockSkyLight);
- #else
- const char * BlockLight = reinterpret_cast<const char *>(Serializer.m_BlockLight);
- #endif
- const char * BlockSkyLight = reinterpret_cast<const char *>(Serializer.m_BlockSkyLight);
- for (int Y = 0; Y < 16; Y++)
+ for (size_t Y = 0; Y != cChunkData::NumSections; ++Y)
{
+ auto Section = Serializer.m_Data.GetSection(Y);
+ if (Section == nullptr)
+ {
+ continue;
+ }
+
a_Writer.BeginCompound("");
- a_Writer.AddByteArray("Blocks", BlockTypes + static_cast<unsigned int>(Y) * SliceSizeBlock, SliceSizeBlock);
- a_Writer.AddByteArray("Data", BlockMetas + static_cast<unsigned int>(Y) * SliceSizeNibble, SliceSizeNibble);
- a_Writer.AddByteArray("SkyLight", BlockSkyLight + static_cast<unsigned int>(Y) * SliceSizeNibble, SliceSizeNibble);
- a_Writer.AddByteArray("BlockLight", BlockLight + static_cast<unsigned int>(Y) * SliceSizeNibble, SliceSizeNibble);
+ a_Writer.AddByteArray("Blocks", reinterpret_cast<const char *>(Section->m_BlockTypes), ARRAYCOUNT(Section->m_BlockTypes));
+ a_Writer.AddByteArray("Data", reinterpret_cast<const char *>(Section->m_BlockMetas), ARRAYCOUNT(Section->m_BlockMetas));
+
+ #ifdef DEBUG_SKYLIGHT
+ a_Writer.AddByteArray("BlockLight", reinterpret_cast<const char *>(Section->m_BlockSkyLight), ARRAYCOUNT(Section->m_BlockSkyLight));
+ #else
+ a_Writer.AddByteArray("BlockLight", reinterpret_cast<const char *>(Section->m_BlockLight), ARRAYCOUNT(Section->m_BlockLight));
+ #endif
+
+ a_Writer.AddByteArray("SkyLight", reinterpret_cast<const char *>(Section->m_BlockSkyLight), ARRAYCOUNT(Section->m_BlockSkyLight));
a_Writer.AddByte("Y", static_cast<unsigned char>(Y));
a_Writer.EndCompound();
}
@@ -1398,12 +1400,13 @@ cBlockEntity * cWSSAnvil::LoadMobHeadFromNBT(const cParsedNBT & a_NBT, int a_Tag
int ownerLine = a_NBT.FindChildByName(a_TagIdx, "Owner");
if (ownerLine >= 0)
{
- AString OwnerName, OwnerUUID, OwnerTexture, OwnerTextureSignature;
+ AString OwnerName, OwnerTexture, OwnerTextureSignature;
+ cUUID OwnerUUID;
currentLine = a_NBT.FindChildByName(ownerLine, "Id");
if (currentLine >= 0)
{
- OwnerUUID = a_NBT.GetString(currentLine);
+ OwnerUUID.FromString(a_NBT.GetString(currentLine));
}
currentLine = a_NBT.FindChildByName(ownerLine, "Name");
@@ -2526,7 +2529,7 @@ void cWSSAnvil::LoadOcelotFromNBT(cEntityList & a_Entities, const cParsedNBT & a
}
auto OwnerInfo = LoadEntityOwner(a_NBT, a_TagIdx);
- if (!OwnerInfo.first.empty() && !OwnerInfo.second.empty())
+ if (!OwnerInfo.first.empty() && !OwnerInfo.second.IsNil())
{
Monster->SetOwner(OwnerInfo.first, OwnerInfo.second);
Monster->SetIsTame(true);
@@ -2927,7 +2930,7 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N
}
auto OwnerInfo = LoadEntityOwner(a_NBT, a_TagIdx);
- if (!OwnerInfo.first.empty() && !OwnerInfo.second.empty())
+ if (!OwnerInfo.first.empty() && !OwnerInfo.second.IsNil())
{
Monster->SetOwner(OwnerInfo.first, OwnerInfo.second);
Monster->SetIsTame(true);
@@ -3064,43 +3067,39 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT
-std::pair<AString, AString> cWSSAnvil::LoadEntityOwner(const cParsedNBT & a_NBT, int a_TagIdx)
+std::pair<AString, cUUID> cWSSAnvil::LoadEntityOwner(const cParsedNBT & a_NBT, int a_TagIdx)
{
// Load the owner information. OwnerUUID or Owner may be specified, possibly both:
- AString OwnerUUID, OwnerName;
+ AString OwnerName;
+ cUUID OwnerUUID;
int OwnerUUIDIdx = a_NBT.FindChildByName(a_TagIdx, "OwnerUUID");
if (OwnerUUIDIdx > 0)
{
- OwnerUUID = a_NBT.GetString(OwnerUUIDIdx);
+ OwnerUUID.FromString(a_NBT.GetString(OwnerUUIDIdx));
}
int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner");
if (OwnerIdx > 0)
{
OwnerName = a_NBT.GetString(OwnerIdx);
}
- if (OwnerName.empty() && OwnerUUID.empty())
+ if (OwnerName.empty() && OwnerUUID.IsNil())
{
// There is no owner, bail out:
- return std::pair<AString, AString>();
+ return {};
}
// Convert name to UUID, if needed:
- if (OwnerUUID.empty())
+ if (OwnerUUID.IsNil())
{
// This entity has only playername stored (pre-1.7.6), look up the UUID
// The lookup is blocking, but we're running in a separate thread, so it's ok
OwnerUUID = cRoot::Get()->GetMojangAPI().GetUUIDFromPlayerName(OwnerName);
- if (OwnerUUID.empty())
+ if (OwnerUUID.IsNil())
{
// Not a known player, un-tame the entity by bailing out
- return std::pair<AString, AString>();
+ return {};
}
}
- else
- {
- // Normalize the UUID:
- OwnerUUID = cMojangAPI::MakeUUIDShort(OwnerUUID);
- }
// Convert UUID to name, if needed:
if (OwnerName.empty())
@@ -3110,11 +3109,11 @@ std::pair<AString, AString> cWSSAnvil::LoadEntityOwner(const cParsedNBT & a_NBT,
if (OwnerName.empty())
{
// Not a known player, un-tame the entity by bailing out
- return std::pair<AString, AString>();
+ return {};
}
}
- return std::make_pair(OwnerName, OwnerUUID);
+ return { OwnerName, OwnerUUID };
}
diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h
index a53d8d8c4..0f32d1a2e 100755
--- a/src/WorldStorage/WSSAnvil.h
+++ b/src/WorldStorage/WSSAnvil.h
@@ -20,6 +20,7 @@ class cItemGrid;
class cMonster;
class cProjectileEntity;
class cHangingEntity;
+class cUUID;
@@ -230,8 +231,8 @@ protected:
void LoadPigZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
/** Loads the owner name and UUID from the entity at the specified NBT tag.
- Returns a pair of {name, uuid}. If the entity is not owned, both are empty strings. */
- std::pair<AString, AString> LoadEntityOwner(const cParsedNBT & a_NBT, int a_TagIdx);
+ Returns a pair of {name, uuid}. If the entity is not owned, name is an empty string and uuid is nil. */
+ std::pair<AString, cUUID> LoadEntityOwner(const cParsedNBT & a_NBT, int a_TagIdx);
/** Loads entity common data from the NBT compound; returns true if successful */
bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx);