ItemFactory::get() now consistently throws SavedDataLoadingException on any error, including unknown items

This commit is contained in:
Dylan K. Taylor
2022-06-27 17:14:43 +01:00
parent 2fd9b751b6
commit 541a624d48
7 changed files with 69 additions and 68 deletions

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace pocketmine\inventory;
use pocketmine\data\SavedDataLoadingException;
use pocketmine\item\Durable;
use pocketmine\item\Item;
use pocketmine\utils\SingletonTrait;
@ -40,8 +41,10 @@ final class CreativeInventory{
$creativeItems = json_decode(file_get_contents(Path::join(\pocketmine\BEDROCK_DATA_PATH, "creativeitems.json")), true);
foreach($creativeItems as $data){
$item = Item::jsonDeserialize($data);
if($item->getName() === "Unknown"){
try{
$item = Item::jsonDeserialize($data);
}catch(SavedDataLoadingException){
//unknown item
continue;
}
$this->add($item);