From fa416d05b29a8c30a50f8869155a80644fe47755 Mon Sep 17 00:00:00 2001 From: Smyler Date: Thu, 6 Jun 2024 21:48:04 +0200 Subject: [PATCH] Preserve litematic subversion --- litemapy/info.py | 3 ++- litemapy/schematic.py | 10 ++++++++-- tests/litematics/valid/Subversion.litematic | Bin 0 -> 324 bytes tests/test_schematics.py | 11 +++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 tests/litematics/valid/Subversion.litematic diff --git a/litemapy/info.py b/litemapy/info.py index 42075fc..e2ab182 100644 --- a/litemapy/info.py +++ b/litemapy/info.py @@ -1,4 +1,5 @@ -LITEMATIC_VERSION = 6 # Litematic version we are trying to imitate from Litematica (1.18.2-0.11.3) +LITEMATIC_VERSION = 6 +LITEMATIC_SUBVERSION = 1 SPONGE_VERSION = 2 # Sponge format version used by WorldEdit (https://github.com/SpongePowered/Schematic-Specification) MC_DATA_VERSION = 2975 # Minecraft 1.18.2 (https://minecraft.wiki/w/Data_version) DEFAULT_NAME = "Unnamed" # Default name given to schematics and regions if unspecified diff --git a/litemapy/schematic.py b/litemapy/schematic.py index 60eaf69..7974dd5 100644 --- a/litemapy/schematic.py +++ b/litemapy/schematic.py @@ -24,6 +24,7 @@ class Schematic: description: str region: dict[str, 'Region'] lm_version: int + lm_subversion: int mc_version: int created: int modified: int @@ -33,7 +34,8 @@ class Schematic: def __init__(self, name: str = DEFAULT_NAME, author: str = "", description: str = "", regions: Optional[dict[str, 'Region']] = None, - lm_version: int = LITEMATIC_VERSION, mc_version: int = MC_DATA_VERSION + lm_version: int = LITEMATIC_VERSION, lm_subversion: int = LITEMATIC_SUBVERSION, + mc_version: int = MC_DATA_VERSION ) -> None: """ Schematic can be created by optionally providing metadata and regions, or leaving them blank or default. @@ -59,6 +61,7 @@ def __init__(self, self.__regions.update(regions) self.mc_version = mc_version self.lm_version = lm_version + self.lm_subversion = lm_subversion self.__preview = IntArray([]) def save(self, file_path: str, update_meta: bool = True, save_soft: bool = True, gzipped: bool = True, @@ -94,6 +97,7 @@ def to_nbt(self, save_soft: bool = True) -> Compound: raise ValueError("Empty schematic does not have any regions") root = Compound() root["Version"] = Int(self.lm_version) + root["SubVersion"] = Int(self.lm_subversion) root["MinecraftDataVersion"] = Int(self.mc_version) meta = Compound() enclose = Compound() @@ -133,6 +137,7 @@ def from_nbt(nbt: Compound) -> 'Schematic': """ meta: Compound = nbt["Metadata"] lm_version: Int = nbt["Version"] + lm_subversion: Int = nbt.get("SubVersion", 0) mc_version: Int = nbt["MinecraftDataVersion"] width = int(meta["EnclosingSize"]["x"]) height = int(meta["EnclosingSize"]["y"]) @@ -144,7 +149,8 @@ def from_nbt(nbt: Compound) -> 'Schematic': for key, value in nbt["Regions"].items(): reg = Region.from_nbt(value) regions[str(key)] = reg - schematic = Schematic(name=name, author=author, description=desc, regions=regions, lm_version=lm_version, + schematic = Schematic(name=name, author=author, description=desc, regions=regions, + lm_version=lm_version, lm_subversion=lm_subversion, mc_version=mc_version) if schematic.width != width: raise CorruptedSchematicError( diff --git a/tests/litematics/valid/Subversion.litematic b/tests/litematics/valid/Subversion.litematic new file mode 100644 index 0000000000000000000000000000000000000000..0d97f3c787b1b5dd44dfe54ed6bf2cc2d2d559f0 GIT binary patch literal 324 zcmV-K0lWSmiwFP!00000|8-GIPQx%1oRFwVlU4|c)3AfK?20PVc8g5%S}YtJIgUho z16CZA1s6anFTX}C@Mi4Mc;1X113s>oQd4Hd&dr4rTe77z8km0g2+t>sVnj=FB4Z(nq8V)?&Ltnm@agtOeys~l}Ga7y|dp1L$xIYsbX&O>V-cpsL6LpxHCv;qf?7@RAb1;Y zv}Vi^BW#V!_)JcaG_I-RO0~6zW^FcOT&+mwoW2pPWjh*d6Ro&a9k%O)t`oXWKKSxr zyAq0=qquJ0hng1s