mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 14:05:35 +00:00
BlockStateDictionaryEntry: encode property names as well as values
sadly we need these to reconstruct the state upon deserialization
This commit is contained in:
parent
d8e77c1920
commit
4f32f5e0b7
@ -25,9 +25,9 @@ namespace pocketmine\network\mcpe\convert;
|
|||||||
|
|
||||||
use pocketmine\data\bedrock\block\BlockStateData;
|
use pocketmine\data\bedrock\block\BlockStateData;
|
||||||
use pocketmine\nbt\LittleEndianNbtSerializer;
|
use pocketmine\nbt\LittleEndianNbtSerializer;
|
||||||
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\Tag;
|
use pocketmine\nbt\tag\Tag;
|
||||||
use pocketmine\nbt\TreeRoot;
|
use pocketmine\nbt\TreeRoot;
|
||||||
use function array_map;
|
|
||||||
use function count;
|
use function count;
|
||||||
use function ksort;
|
use function ksort;
|
||||||
use const SORT_STRING;
|
use const SORT_STRING;
|
||||||
@ -74,7 +74,7 @@ final class BlockStateDictionaryEntry{
|
|||||||
if($rawProperties === ""){
|
if($rawProperties === ""){
|
||||||
return [];
|
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
|
//TODO: make a more efficient encoding - NBT will do for now, but it's not very compact
|
||||||
ksort($properties, SORT_STRING);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user