From 4d6fb2b92535db9f1c437038659be353f5d8beaa Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 6 Jul 2022 23:57:29 +0100 Subject: [PATCH] Removed ItemFactory --- src/item/ItemFactory.php | 93 ------------------- .../item/ItemSerializerDeserializerTest.php | 4 +- 2 files changed, 2 insertions(+), 95 deletions(-) delete mode 100644 src/item/ItemFactory.php diff --git a/src/item/ItemFactory.php b/src/item/ItemFactory.php deleted file mode 100644 index 49b594363..000000000 --- a/src/item/ItemFactory.php +++ /dev/null @@ -1,93 +0,0 @@ -isNull()){ - continue; - } - $this->register($item); - } - } - - /** - * Maps an item type to its corresponding ID. This is necessary to ensure that the item is correctly loaded when - * reading data from disk storage. - * - * NOTE: If you are registering a new item type, you will need to add it to the creative inventory yourself - it - * will not automatically appear there. - * - * @throws \RuntimeException if something attempted to override an already-registered item without specifying the - * $override parameter. - */ - public function register(Item $item, bool $override = false) : void{ - $id = $item->getTypeId(); - - if(!$override && $this->isRegistered($id)){ - throw new \RuntimeException("Trying to overwrite an already registered item"); - } - - $this->list[$id] = clone $item; - } - - private static function itemToBlockId(int $id) : int{ - if($id > 0){ - throw new \InvalidArgumentException("ID $id is not a block ID"); - } - return -$id; - } - - /** - * Returns whether the specified item ID is already registered in the item factory. - */ - public function isRegistered(int $id) : bool{ - if($id <= 0){ - return BlockFactory::getInstance()->isRegistered(self::itemToBlockId($id)); - } - - return isset($this->list[$id]); - } - - /** - * @return Item[] - */ - public function getAllKnownTypes() : array{ - return $this->list; - } -} diff --git a/tests/phpunit/data/bedrock/item/ItemSerializerDeserializerTest.php b/tests/phpunit/data/bedrock/item/ItemSerializerDeserializerTest.php index 80ff0c4a4..a7617735c 100644 --- a/tests/phpunit/data/bedrock/item/ItemSerializerDeserializerTest.php +++ b/tests/phpunit/data/bedrock/item/ItemSerializerDeserializerTest.php @@ -25,7 +25,7 @@ namespace pocketmine\data\bedrock\item; use PHPUnit\Framework\TestCase; use pocketmine\block\BlockFactory; -use pocketmine\item\ItemFactory; +use pocketmine\item\VanillaItems; use pocketmine\world\format\io\GlobalBlockStateHandlers; final class ItemSerializerDeserializerTest extends TestCase{ @@ -39,7 +39,7 @@ final class ItemSerializerDeserializerTest extends TestCase{ } public function testAllVanillaItemsSerializableAndDeserializable() : void{ - foreach(ItemFactory::getInstance()->getAllKnownTypes() as $item){ + foreach(VanillaItems::getAll() as $item){ if($item->isNull()){ continue; }