From 686bf398d5d83e3bb089e72c79ba2cdb69ad3db8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 Aug 2021 15:41:00 +0100 Subject: [PATCH] BlockFactory: simplify get() code --- src/block/BlockFactory.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/block/BlockFactory.php b/src/block/BlockFactory.php index b4a82575be..7f5d156ffa 100644 --- a/src/block/BlockFactory.php +++ b/src/block/BlockFactory.php @@ -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()); }