From fe3214554c3666065cf0647c5af30f0bf0948a35 Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Tue, 17 Sep 2024 15:51:48 +0100 Subject: [PATCH] Added support for old and new nbt versions (#37) * Added support for old and new nbt versions * Reformatted --- minecraft_model_reader/api/amulet/block.py | 9 ++++++--- setup.cfg | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/minecraft_model_reader/api/amulet/block.py b/minecraft_model_reader/api/amulet/block.py index 28d8647..fb77104 100644 --- a/minecraft_model_reader/api/amulet/block.py +++ b/minecraft_model_reader/api/amulet/block.py @@ -5,6 +5,11 @@ from typing import Iterable, Union, Optional, Any import amulet_nbt +if amulet_nbt.__major__ >= 4: + from amulet_nbt import read_snbt # type: ignore +else: + from amulet_nbt import from_snbt as read_snbt # type: ignore + PropertyValueType = Union[ amulet_nbt.TAG_Byte, amulet_nbt.TAG_Short, @@ -301,9 +306,7 @@ def parse_blockstate_string( properties = {} if snbt: - properties_dict = { - k: amulet_nbt.from_snbt(v) for k, v in sorted(properties.items()) - } + properties_dict = {k: read_snbt(v) for k, v in sorted(properties.items())} else: properties_dict = { k: amulet_nbt.TAG_String(v) for k, v in sorted(properties.items()) diff --git a/setup.cfg b/setup.cfg index 2416835..e4338ce 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,7 +20,7 @@ python_requires = ~=3.9 install_requires = Pillow>=10.0.1 numpy>=1.17 - amulet-nbt~=2.0 + amulet-nbt >= 2.0, < 5.0 platformdirs~=3.1 [options.packages.find]