diff options
Diffstat (limited to 'src/WorldStorage/SchematicFileSerializer.cpp')
-rw-r--r-- | src/WorldStorage/SchematicFileSerializer.cpp | 66 |
1 files changed, 41 insertions, 25 deletions
diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp index 656a98709..d808bb53e 100644 --- a/src/WorldStorage/SchematicFileSerializer.cpp +++ b/src/WorldStorage/SchematicFileSerializer.cpp @@ -1,7 +1,8 @@ // SchematicFileSerializer.cpp -// Implements the cSchematicFileSerializer class representing the interface to load and save cBlockArea to a .schematic file +// Implements the cSchematicFileSerializer class representing the interface to load and save cBlockArea to a .schematic +// file #include "Globals.h" @@ -33,7 +34,10 @@ void cSchematicFileSerializer::LoadFromSchematicFile(cBlockArea & a_BlockArea, c -void cSchematicFileSerializer::LoadFromSchematicString(cBlockArea & a_BlockArea, const ContiguousByteBufferView a_SchematicData) +void cSchematicFileSerializer::LoadFromSchematicString( + cBlockArea & a_BlockArea, + const ContiguousByteBufferView a_SchematicData +) { const auto Extracted = Compression::Extractor().ExtractGZip(a_SchematicData); const cParsedNBT NBT(Extracted.GetView()); @@ -76,22 +80,23 @@ void cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, co AString Materials = a_NBT.GetString(TMaterials); if (Materials.compare("Alpha") != 0) { - throw std::runtime_error(fmt::format("Materials tag is present and \"{}\" instead of \"Alpha\". Possibly a wrong-format schematic file.", Materials)); + throw std::runtime_error(fmt::format( + "Materials tag is present and \"{}\" instead of \"Alpha\". Possibly a wrong-format schematic file.", + Materials + )); } } int TSizeX = a_NBT.FindChildByName(a_NBT.GetRoot(), "Width"); int TSizeY = a_NBT.FindChildByName(a_NBT.GetRoot(), "Height"); int TSizeZ = a_NBT.FindChildByName(a_NBT.GetRoot(), "Length"); - if ( - (TSizeX < 0) || (TSizeY < 0) || (TSizeZ < 0) || - (a_NBT.GetType(TSizeX) != TAG_Short) || - (a_NBT.GetType(TSizeY) != TAG_Short) || - (a_NBT.GetType(TSizeZ) != TAG_Short) - ) + if ((TSizeX < 0) || (TSizeY < 0) || (TSizeZ < 0) || (a_NBT.GetType(TSizeX) != TAG_Short) || + (a_NBT.GetType(TSizeY) != TAG_Short) || (a_NBT.GetType(TSizeZ) != TAG_Short)) { throw std::runtime_error(fmt::format( "Dimensions are missing from the schematic file ({}, {}, {}), ({}, {}, {})", - TSizeX, TSizeY, TSizeZ, + TSizeX, + TSizeY, + TSizeZ, (TSizeX >= 0) ? a_NBT.GetType(TSizeX) : -1, (TSizeY >= 0) ? a_NBT.GetType(TSizeY) : -1, (TSizeZ >= 0) ? a_NBT.GetType(TSizeZ) : -1 @@ -103,7 +108,9 @@ void cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, co int SizeZ = a_NBT.GetShort(TSizeZ); if ((SizeX < 1) || (SizeX > 65535) || (SizeY < 1) || (SizeY > 65535) || (SizeZ < 1) || (SizeZ > 65535)) { - throw std::runtime_error(fmt::format("Dimensions are invalid in the schematic file: {}, {}, {}", SizeX, SizeY, SizeZ)); + throw std::runtime_error( + fmt::format("Dimensions are invalid in the schematic file: {}, {}, {}", SizeX, SizeY, SizeZ) + ); } int TBlockTypes = a_NBT.FindChildByName(a_NBT.GetRoot(), "Blocks"); @@ -115,18 +122,19 @@ void cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, co bool AreMetasPresent = (TBlockMetas > 0) && (a_NBT.GetType(TBlockMetas) == TAG_ByteArray); a_BlockArea.Clear(); - a_BlockArea.SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (cBlockArea::baTypes | cBlockArea::baMetas) : cBlockArea::baTypes); + a_BlockArea.SetSize( + SizeX, + SizeY, + SizeZ, + AreMetasPresent ? (cBlockArea::baTypes | cBlockArea::baMetas) : cBlockArea::baTypes + ); int TOffsetX = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetX"); int TOffsetY = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetY"); int TOffsetZ = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetZ"); - if ( - (TOffsetX < 0) || (TOffsetY < 0) || (TOffsetZ < 0) || - (a_NBT.GetType(TOffsetX) != TAG_Int) || - (a_NBT.GetType(TOffsetY) != TAG_Int) || - (a_NBT.GetType(TOffsetZ) != TAG_Int) - ) + if ((TOffsetX < 0) || (TOffsetY < 0) || (TOffsetZ < 0) || (a_NBT.GetType(TOffsetX) != TAG_Int) || + (a_NBT.GetType(TOffsetY) != TAG_Int) || (a_NBT.GetType(TOffsetZ) != TAG_Int)) { // Not every schematic file has an offset, so we shoudn't give a warn message. a_BlockArea.SetWEOffset(0, 0, 0); @@ -141,8 +149,8 @@ void cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, co if (a_NBT.GetDataLength(TBlockTypes) < NumTypeBytes) { LOG("BlockTypes truncated in the schematic file (exp %u, got %u bytes). Loading partial.", - static_cast<unsigned>(NumTypeBytes), static_cast<unsigned>(a_NBT.GetDataLength(TBlockTypes)) - ); + static_cast<unsigned>(NumTypeBytes), + static_cast<unsigned>(a_NBT.GetDataLength(TBlockTypes))); NumTypeBytes = a_NBT.GetDataLength(TBlockTypes); } memcpy(a_BlockArea.GetBlockTypes(), a_NBT.GetData(TBlockTypes), NumTypeBytes); @@ -153,8 +161,8 @@ void cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, co if (a_NBT.GetDataLength(TBlockMetas) < NumMetaBytes) { LOG("BlockMetas truncated in the schematic file (exp %u, got %u bytes). Loading partial.", - static_cast<unsigned>(NumMetaBytes), static_cast<unsigned>(a_NBT.GetDataLength(TBlockMetas)) - ); + static_cast<unsigned>(NumMetaBytes), + static_cast<unsigned>(a_NBT.GetDataLength(TBlockMetas))); NumMetaBytes = a_NBT.GetDataLength(TBlockMetas); } memcpy(a_BlockArea.GetBlockMetas(), a_NBT.GetData(TBlockMetas), NumMetaBytes); @@ -168,13 +176,17 @@ void cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, co ContiguousByteBuffer cSchematicFileSerializer::SaveToSchematicNBT(const cBlockArea & a_BlockArea) { cFastNBTWriter Writer("Schematic"); - Writer.AddShort("Width", static_cast<Int16>(a_BlockArea.m_Size.x)); + Writer.AddShort("Width", static_cast<Int16>(a_BlockArea.m_Size.x)); Writer.AddShort("Height", static_cast<Int16>(a_BlockArea.m_Size.y)); Writer.AddShort("Length", static_cast<Int16>(a_BlockArea.m_Size.z)); Writer.AddString("Materials", "Alpha"); if (a_BlockArea.HasBlockTypes()) { - Writer.AddByteArray("Blocks", reinterpret_cast<const char *>(a_BlockArea.GetBlockTypes()), a_BlockArea.GetBlockCount()); + Writer.AddByteArray( + "Blocks", + reinterpret_cast<const char *>(a_BlockArea.GetBlockTypes()), + a_BlockArea.GetBlockCount() + ); } else { @@ -183,7 +195,11 @@ ContiguousByteBuffer cSchematicFileSerializer::SaveToSchematicNBT(const cBlockAr } if (a_BlockArea.HasBlockMetas()) { - Writer.AddByteArray("Data", reinterpret_cast<const char *>(a_BlockArea.GetBlockMetas()), a_BlockArea.GetBlockCount()); + Writer.AddByteArray( + "Data", + reinterpret_cast<const char *>(a_BlockArea.GetBlockMetas()), + a_BlockArea.GetBlockCount() + ); } else { |