From 4f32f5e0b71e2dc37d03671bde8ec87f036d4983 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 5 May 2023 13:41:06 +0100 Subject: [PATCH] BlockStateDictionaryEntry: encode property names as well as values sadly we need these to reconstruct the state upon deserialization --- src/network/mcpe/convert/BlockStateDictionaryEntry.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/network/mcpe/convert/BlockStateDictionaryEntry.php b/src/network/mcpe/convert/BlockStateDictionaryEntry.php index 57cc29c0c..8c6244da5 100644 --- a/src/network/mcpe/convert/BlockStateDictionaryEntry.php +++ b/src/network/mcpe/convert/BlockStateDictionaryEntry.php @@ -25,9 +25,9 @@ namespace pocketmine\network\mcpe\convert; use pocketmine\data\bedrock\block\BlockStateData; use pocketmine\nbt\LittleEndianNbtSerializer; +use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\Tag; use pocketmine\nbt\TreeRoot; -use function array_map; use function count; use function ksort; use const SORT_STRING; @@ -74,7 +74,7 @@ final class BlockStateDictionaryEntry{ if($rawProperties === ""){ return []; } - return array_map(fn(TreeRoot $root) => $root->getTag(), (new LittleEndianNbtSerializer())->readMultiple($rawProperties)); + return (new LittleEndianNbtSerializer())->read($rawProperties)->mustGetCompoundTag()->getValue(); } /** @@ -86,6 +86,10 @@ final class BlockStateDictionaryEntry{ } //TODO: make a more efficient encoding - NBT will do for now, but it's not very compact ksort($properties, SORT_STRING); - return (new LittleEndianNbtSerializer())->writeMultiple(array_map(fn(Tag $tag) => new TreeRoot($tag), $properties)); + $tag = new CompoundTag(); + foreach($properties as $k => $v){ + $tag->setTag($k, $v); + } + return (new LittleEndianNbtSerializer())->write(new TreeRoot($tag)); } }