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.
This commit is contained in:
Dylan K. Taylor 2020-05-12 23:28:17 +01:00
parent ac4c1c9086
commit ec13aa659a

View File

@ -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);
}