Fixed usages of BlockDataUpgrader which weren't accounting for thrown exceptions

This commit is contained in:
Dylan K. Taylor
2023-05-02 17:13:31 +01:00
parent 4d0cecbac2
commit 6beb80b8fe
5 changed files with 39 additions and 17 deletions

View File

@ -37,6 +37,7 @@ use pocketmine\block\UnknownBlock;
use pocketmine\block\VanillaBlocks;
use pocketmine\data\bedrock\BiomeIds;
use pocketmine\data\bedrock\block\BlockStateData;
use pocketmine\data\bedrock\block\BlockStateDeserializeException;
use pocketmine\data\SavedDataLoadingException;
use pocketmine\entity\Entity;
use pocketmine\entity\EntityFactory;
@ -526,9 +527,10 @@ class World implements ChunkManager{
if($item !== null){
$block = $item->getBlock();
}elseif(preg_match("/^-?\d+$/", $name) === 1){
//TODO: this may throw if the ID/meta was invalid
$blockStateData = GlobalBlockStateHandlers::getUpgrader()->upgradeIntIdMeta((int) $name, 0);
if($blockStateData === null){
//TODO: this is a really sketchy hack - remove this as soon as possible
try{
$blockStateData = GlobalBlockStateHandlers::getUpgrader()->upgradeIntIdMeta((int) $name, 0);
}catch(BlockStateDeserializeException){
continue;
}
$block = RuntimeBlockStateRegistry::getInstance()->fromStateId(GlobalBlockStateHandlers::getDeserializer()->deserialize($blockStateData));

View File

@ -67,9 +67,10 @@ abstract class BaseWorldProvider implements WorldProvider{
$newPalette = [];
foreach($palette as $k => $legacyIdMeta){
$newStateData = $this->blockDataUpgrader->upgradeIntIdMeta($legacyIdMeta >> 4, $legacyIdMeta & 0xf);
if($newStateData === null){
//TODO: remember data for unknown states so we can implement them later
//TODO: remember data for unknown states so we can implement them later
try{
$newStateData = $this->blockDataUpgrader->upgradeIntIdMeta($legacyIdMeta >> 4, $legacyIdMeta & 0xf);
}catch(BlockStateDeserializeException $e){
$newStateData = GlobalBlockStateHandlers::getUnknownBlockStateData();
}