summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage/WSSAnvil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/WorldStorage/WSSAnvil.cpp')
-rwxr-xr-xsrc/WorldStorage/WSSAnvil.cpp67
1 files changed, 33 insertions, 34 deletions
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 };
}