From 05e2bef5ce7f08db75452b00ef9595e05765727a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 16 Sep 2021 14:53:19 +0100 Subject: [PATCH] ItemFactory: fix crash when checking if blockitem IDs are registered --- src/item/ItemFactory.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/item/ItemFactory.php b/src/item/ItemFactory.php index 2c9961132..5fb7438a1 100644 --- a/src/item/ItemFactory.php +++ b/src/item/ItemFactory.php @@ -432,6 +432,10 @@ class ItemFactory{ $this->list[self::getListOffset($identifier->getId(), $identifier->getMeta())] = clone $item; } + private static function itemToBlockId(int $id) : int{ + return $id < 0 ? 255 - $id : $id; + } + /** * @deprecated This method should ONLY be used for deserializing data, e.g. from a config or database. For all other * purposes, use VanillaItems. @@ -456,7 +460,7 @@ class ItemFactory{ } }elseif($id < 256){ //intentionally includes negatives, for extended block IDs //TODO: do not assume that item IDs and block IDs are the same or related - $item = new ItemBlock(new ItemIdentifier($id, $meta), BlockFactory::getInstance()->get($id < 0 ? 255 - $id : $id, $meta & 0xf)); + $item = new ItemBlock(new ItemIdentifier($id, $meta), BlockFactory::getInstance()->get(self::itemToBlockId($id), $meta & 0xf)); } } @@ -481,7 +485,7 @@ class ItemFactory{ */ public function isRegistered(int $id, int $variant = 0) : bool{ if($id < 256){ - return BlockFactory::getInstance()->isRegistered($id); + return BlockFactory::getInstance()->isRegistered(self::itemToBlockId($id)); } return isset($this->list[self::getListOffset($id, $variant)]);