mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +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\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));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user