BlockFactory: simplify get() code

This commit is contained in:
Dylan K. Taylor 2021-08-21 15:41:00 +01:00
parent 4023a024ce
commit 686bf398d5
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -957,18 +957,13 @@ class BlockFactory{
throw new \InvalidArgumentException("Block meta value $meta is out of bounds");
}
/** @var Block|null $block */
$block = null;
try{
$index = ($id << Block::INTERNAL_METADATA_BITS) | $meta;
if($this->fullList[$index] !== null){
$block = clone $this->fullList[$index];
}
}catch(\RuntimeException $e){
$index = ($id << Block::INTERNAL_METADATA_BITS) | $meta;
if($index < 0 || $index >= $this->fullList->getSize()){
throw new \InvalidArgumentException("Block ID $id is out of bounds");
}
if($block === null){
if($this->fullList[$index] !== null){
$block = clone $this->fullList[$index];
}else{
$block = new UnknownBlock(new BID($id, $meta), BlockBreakInfo::instant());
}