Update ItemUtil.java

This commit is contained in:
Aleksey 2020-12-27 16:19:15 +03:00
parent 220b16fa42
commit 66c2506fa3

View file

@ -55,13 +55,14 @@ public class ItemUtil {
@Nullable @Nullable
public static ItemStack fromJsonRecipe(JsonObject recipe) { public static ItemStack fromJsonRecipe(JsonObject recipe) {
if (!recipe.has("item")) return null;
try { try {
if (!recipe.has("item")) {
throw new IllegalStateException("Invalid JsonObject. Entry 'item' does not exists!");
}
Identifier itemId = new Identifier(JsonHelper.getString(recipe, "item")); Identifier itemId = new Identifier(JsonHelper.getString(recipe, "item"));
Item item = Registry.ITEM.getOrEmpty(itemId).orElseThrow(() -> { Item item = Registry.ITEM.getOrEmpty(itemId).orElseThrow(() -> {
return new IllegalStateException("Output item " + itemId + " does not exists!"); return new IllegalStateException("Output item " + itemId + " does not exists!");
}); });
if (item == null) return null;
int count = JsonHelper.getInt(recipe, "count", 1); int count = JsonHelper.getInt(recipe, "count", 1);
return new ItemStack(item, count); return new ItemStack(item, count);
} catch (Exception ex) { } catch (Exception ex) {