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

@ -23,17 +23,14 @@ declare(strict_types=1);
namespace pocketmine\tools\generate_block_palette_spec;
use pocketmine\data\bedrock\block\BlockStateData;
use pocketmine\errorhandler\ErrorToExceptionHandler;
use pocketmine\nbt\NbtException;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\StringTag;
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 count;
use function dirname;
@ -54,10 +51,7 @@ if(count($argv) !== 3){
[, $inputFile, $outputFile] = $argv;
try{
$states = array_map(
fn(TreeRoot $root) => BlockStateData::fromNbt($root->mustGetCompoundTag()),
(new NetworkNbtSerializer())->readMultiple(ErrorToExceptionHandler::trapAndRemoveFalse(fn() => file_get_contents($inputFile)))
);
$states = BlockStateDictionary::loadPaletteFromString(ErrorToExceptionHandler::trapAndRemoveFalse(fn() => file_get_contents($inputFile)));
}catch(NbtException){
fwrite(STDERR, "Invalid block palette file $argv[1]\n");
exit(1);