mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Merge 'minor-next' into 'major-next'
Automatic merge performed by: https://github.com/pmmp/RestrictedActions/actions/runs/13878654456
This commit is contained in:
commit
510ef94698
@ -209,6 +209,10 @@ class RuntimeBlockStateRegistry{
|
||||
return $block;
|
||||
}
|
||||
|
||||
public function hasStateId(int $stateId) : bool{
|
||||
return isset($this->fullList[$stateId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Block[]
|
||||
* @phpstan-return array<int, Block>
|
||||
|
@ -33,6 +33,7 @@ use pocketmine\block\DoublePitcherCrop;
|
||||
use pocketmine\block\Opaque;
|
||||
use pocketmine\block\PinkPetals;
|
||||
use pocketmine\block\PitcherCrop;
|
||||
use pocketmine\block\RuntimeBlockStateRegistry;
|
||||
use pocketmine\block\Slab;
|
||||
use pocketmine\block\Stair;
|
||||
use pocketmine\block\SweetBerryBush;
|
||||
@ -97,11 +98,21 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{
|
||||
public function deserialize(BlockStateData $stateData) : int{
|
||||
if(count($stateData->getStates()) === 0){
|
||||
//if a block has zero properties, we can keep a map of string ID -> internal blockstate ID
|
||||
return $this->simpleCache[$stateData->getName()] ??= $this->deserializeBlock($stateData)->getStateId();
|
||||
return $this->simpleCache[$stateData->getName()] ??= $this->deserializeToStateId($stateData);
|
||||
}
|
||||
|
||||
//we can't cache blocks that have properties - go ahead and deserialize the slow way
|
||||
return $this->deserializeBlock($stateData)->getStateId();
|
||||
return $this->deserializeToStateId($stateData);
|
||||
}
|
||||
|
||||
private function deserializeToStateId(BlockStateData $stateData) : int{
|
||||
$stateId = $this->deserializeBlock($stateData)->getStateId();
|
||||
//plugin devs seem to keep missing this and causing core crashes, so we need to verify this at the earliest
|
||||
//available opportunity
|
||||
if(!RuntimeBlockStateRegistry::getInstance()->hasStateId($stateId)){
|
||||
throw new \LogicException("State ID $stateId returned by deserializer for " . $stateData->getName() . " is not registered in RuntimeBlockStateRegistry");
|
||||
}
|
||||
return $stateId;
|
||||
}
|
||||
|
||||
/** @phpstan-param \Closure(Reader) : Block $c */
|
||||
|
Loading…
x
Reference in New Issue
Block a user