From 3972f663b7274c2af34029848ddd344ca43aa086 Mon Sep 17 00:00:00 2001 From: Yousef Abdrabo <47288146+YousefOnWeb@users.noreply.github.com> Date: Wed, 21 May 2025 09:16:59 +0300 Subject: [PATCH] Enforce native Python str for blockData in MCStructure.setBlock to ensure correct palette generation This commit addresses an issue where schem could be generated with an incomplete block palette (making it corrupt) if non-native Python string types (e.g., ``numpy.str_``) were passed as ``blockData`` to ``MCStructure.setBlock()``. The reason the block palette could be incomplete in this case is because ``MCStructure.getBlockPalette()`` method filters keys from ``_blockPalette`` using the check: ``type(key) == str``. --- mcschematic.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mcschematic.py b/mcschematic.py index 7f19e61..b7a5458 100644 --- a/mcschematic.py +++ b/mcschematic.py @@ -1259,8 +1259,16 @@ def setBlock(self, position: tuple[int, int, int], blockData: str): :param position: The position to place the blockData at :param blockData: The blockData to place + :raises TypeError: if blockData is not a native Python string. """ + # validate blockData type + if not isinstance(blockData, str) or type(blockData) != str: + raise TypeError( + f"blockData must be a native Python string (str), but got type {type(blockData)}. " + f"Value: '{str(blockData)[:100]}{'...' if len(str(blockData)) > 100 else ''}'" + ) + # We have a different treatment between block entities # and normal blocks. #if not self._isBlockDataBlockEntity(blockData):