BlockStateDictionary: extract a more generic helper method for decoding block palette files

This commit is contained in:
Dylan K. Taylor
2022-07-06 14:37:46 +01:00
parent dc8f65c0dd
commit a8728a02f6
3 changed files with 19 additions and 20 deletions

View File

@ -29,11 +29,9 @@ use pocketmine\data\bedrock\block\BlockStateStringValues;
use pocketmine\data\bedrock\block\BlockTypeNames;
use pocketmine\errorhandler\ErrorToExceptionHandler;
use pocketmine\nbt\NbtException;
use pocketmine\nbt\TreeRoot;
use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer;
use pocketmine\network\mcpe\convert\BlockStateDictionary;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Utils;
use function array_map;
use function array_values;
use function asort;
use function count;
@ -183,10 +181,7 @@ if($paletteRaw === false){
}
try{
$states = array_map(
fn(TreeRoot $root) => BlockStateData::fromNbt($root->mustGetCompoundTag()),
(new NetworkNbtSerializer())->readMultiple($paletteRaw)
);
$states = BlockStateDictionary::loadPaletteFromString($paletteRaw);
}catch(NbtException){
fwrite(STDERR, "Invalid block palette file $argv[1]\n");
exit(1);