From ec13aa659a0ec9826cd79bc6734b594e45b971cf Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 12 May 2020 23:28:17 +0100 Subject: [PATCH] ItemFactory: do not explode on invalid damage values for durables just treat them as unknown items instead this might break some use cases, but at least this way they won't crash the server when read from disk and they won't get lost either. --- src/item/ItemFactory.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/item/ItemFactory.php b/src/item/ItemFactory.php index 2f54c4ec6..0f00937d3 100644 --- a/src/item/ItemFactory.php +++ b/src/item/ItemFactory.php @@ -409,7 +409,11 @@ class ItemFactory{ }elseif(isset($this->list[$zero = self::getListOffset($id, 0)]) and $this->list[$zero] instanceof Durable){ /** @var Durable $item */ $item = clone $this->list[$zero]; - $item->setDamage($meta); + try{ + $item->setDamage($meta); + }catch(\InvalidArgumentException $e){ + $item = new Item($id, $meta); + } }elseif($id < 256){ //intentionally includes negatives, for extended block IDs $item = new ItemBlock($id, $meta); }