10 #include "../OSSupport/GZipFile.h"
26 throw std::runtime_error(fmt::format(
"Cannot parse the NBT in the schematic file \"{}\".", a_FileName));
43 throw std::runtime_error(
"Cannot parse the NBT in the schematic data.");
77 if (Materials.compare(
"Alpha") != 0)
79 throw std::runtime_error(fmt::format(
"Materials tag is present and \"{}\" instead of \"Alpha\". Possibly a wrong-format schematic file.", Materials));
86 (TSizeX < 0) || (TSizeY < 0) || (TSizeZ < 0) ||
92 throw std::runtime_error(fmt::format(
93 "Dimensions are missing from the schematic file ({}, {}, {}), ({}, {}, {})",
94 TSizeX, TSizeY, TSizeZ,
95 (TSizeX >= 0) ? a_NBT.
GetType(TSizeX) : -1,
96 (TSizeY >= 0) ? a_NBT.
GetType(TSizeY) : -1,
97 (TSizeZ >= 0) ? a_NBT.
GetType(TSizeZ) : -1
104 if ((SizeX < 1) || (SizeX > 65535) || (SizeY < 1) || (SizeY > 65535) || (SizeZ < 1) || (SizeZ > 65535))
106 throw std::runtime_error(fmt::format(
"Dimensions are invalid in the schematic file: {}, {}, {}", SizeX, SizeY, SizeZ));
113 throw std::runtime_error(fmt::format(
"BlockTypes are invalid in the schematic file: {}", TBlockTypes));
125 (TOffsetX < 0) || (TOffsetY < 0) || (TOffsetZ < 0) ||
143 LOG(
"BlockTypes truncated in the schematic file (exp %u, got %u bytes). Loading partial.",
144 static_cast<unsigned>(NumTypeBytes),
static_cast<unsigned>(a_NBT.
GetDataLength(TBlockTypes))
155 LOG(
"BlockMetas truncated in the schematic file (exp %u, got %u bytes). Loading partial.",
156 static_cast<unsigned>(NumMetaBytes),
static_cast<unsigned>(a_NBT.
GetDataLength(TBlockMetas))
182 Writer.
AddByteArray(
"Blocks", Dummy.data(), Dummy.size());
191 Writer.
AddByteArray(
"Data", Dummy.data(), Dummy.size());
std::basic_string_view< std::byte > ContiguousByteBufferView
std::basic_string< std::byte > ContiguousByteBuffer
void LOG(std::string_view a_Format, const Args &... args)
void Write(const std::string &a_FileName, ContiguousByteBufferView a_Contents)
Writes a_Contents into file, compressing it along the way.
Compression::Result ReadRestOfFile(const std::string &a_FileName)
Reads the rest of the file and returns the decompressed contents.
NIBBLETYPE * GetBlockMetas(void) const
Vector3i m_WEOffset
An extra data value sometimes stored in the .schematic file.
void SetWEOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ)
bool SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
Clears the data stored and prepares a fresh new block area with the specified dimensions.
size_t GetBlockCount(void) const
bool HasBlockTypes(void) const
BLOCKTYPE * GetBlockTypes(void) const
Returns the internal pointer to the block types.
bool HasBlockMetas(void) const
void Clear(void)
Clears the data stored to reclaim memory.
Contains the result of a compression or extraction operation.
Contains routines for data compression.
Result CompressGZip(ContiguousByteBufferView Input)
Contains routines for data extraction.
Result ExtractGZip(ContiguousByteBufferView Input)
Parses and contains the parsed data Also implements data accessor functions for tree traversal and va...
Int16 GetShort(int a_Tag) const
Returns the value stored in a Short tag.
const std::byte * GetData(int a_Tag) const
Returns the data stored in this tag.
eTagType GetType(int a_Tag) const
int FindChildByName(int a_Tag, const AString &a_Name) const
Returns the direct child tag of the specified name, or -1 if no such tag.
size_t GetDataLength(int a_Tag) const
Returns the length of the tag's data, in bytes.
int GetRoot(void) const
Returns the root tag of the hierarchy.
Int32 GetInt(int a_Tag) const
Returns the value stored in an Int tag.
AString GetString(int a_Tag) const
Returns the value stored in a String tag.
void AddByteArray(const AString &a_Name, const char *a_Value, size_t a_NumElements)
void AddShort(const AString &a_Name, Int16 a_Value)
void AddInt(const AString &a_Name, Int32 a_Value)
void AddString(const AString &a_Name, std::string_view a_Value)
void BeginList(const AString &a_Name, eTagType a_ChildrenType)
ContiguousByteBufferView GetResult(void) const
static void SaveToSchematicFile(const cBlockArea &a_BlockArea, const std::string &a_FileName)
Saves the area into a .schematic file.
static void LoadFromSchematicString(cBlockArea &a_BlockArea, ContiguousByteBufferView a_SchematicData)
Loads an area from a string containing the .schematic file data.
static Compression::Result SaveToSchematicString(const cBlockArea &a_BlockArea)
Saves the area into a string containing the .schematic file data.
static void LoadFromSchematicFile(cBlockArea &a_BlockArea, const std::string &a_FileName)
Loads an area from a .schematic file.
static ContiguousByteBuffer SaveToSchematicNBT(const cBlockArea &a_BlockArea)
Saves the area into a NBT representation and returns the NBT data as a string.
static void LoadFromSchematicNBT(cBlockArea &a_BlockArea, const cParsedNBT &a_NBT)
Loads the area from a schematic file uncompressed and parsed into a NBT tree.