Throw a more specific exception on unknown block IDs

This commit is contained in:
Dylan K. Taylor 2022-06-24 22:52:28 +01:00
parent 8b80c70b9c
commit be2fe160b3
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 32 additions and 2 deletions

View File

@ -23,6 +23,6 @@ declare(strict_types=1);
namespace pocketmine\data\bedrock\block;
final class BlockStateDeserializeException extends \RuntimeException{
class BlockStateDeserializeException extends \RuntimeException{
}

View File

@ -2534,7 +2534,7 @@ final class BlockStateToBlockObjectDeserializer implements BlockStateDeserialize
public function deserializeBlock(BlockStateData $blockStateData) : Block{
$id = $blockStateData->getName();
if(!array_key_exists($id, $this->deserializeFuncs)){
throw new BlockStateDeserializeException("Unknown block ID \"$id\"");
throw new UnsupportedBlockStateException("Unknown block ID \"$id\"");
}
$reader = new Reader($blockStateData);
$block = $this->deserializeFuncs[$id]($reader);

View File

@ -0,0 +1,30 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\data\bedrock\block\convert;
use pocketmine\data\bedrock\block\BlockStateDeserializeException;
final class UnsupportedBlockStateException extends BlockStateDeserializeException{
}