From f81849e55062538d81f4b89162c70c735b9c0def Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 17 Oct 2018 15:02:52 +0100 Subject: [PATCH] ItemFactory: fix special case handling for durable items, close #2483 --- src/pocketmine/item/ItemFactory.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/item/ItemFactory.php b/src/pocketmine/item/ItemFactory.php index a796eaf36..d3bfb0c3f 100644 --- a/src/pocketmine/item/ItemFactory.php +++ b/src/pocketmine/item/ItemFactory.php @@ -347,8 +347,16 @@ class ItemFactory{ $sublist = self::$list[self::getListOffset($id)]; /** @var Item|null $listed */ - if($sublist !== null and isset($sublist[$meta])){ - $item = clone $sublist[$meta]; + if($sublist !== null){ + if(isset($sublist[$meta])){ + $item = clone $sublist[$meta]; + }elseif(isset($sublist[0]) and $sublist[0] instanceof Durable){ + /** @var Durable $item */ + $item = clone $sublist[0]; + $item->setDamage($meta); + }else{ + throw new \InvalidArgumentException("Unknown variant $meta of item ID $id"); + } }elseif($id < 256){ //intentionally includes negatives, for extended block IDs /* Blocks must have a damage value 0-15, but items can have damage value -1 to indicate that they are * crafting ingredients with any-damage. */ @@ -363,9 +371,6 @@ class ItemFactory{ $item->setCount($count); $item->setCompoundTag($tags); - if($item instanceof Durable){ //nasty, but necessary for BC reasons - $item->setDamage($meta); - } return $item; }