Update ItemUtil.java

This commit is contained in:
Aleksey 2020-12-27 16:13:51 +03:00
parent a0f7a2878d
commit 220b16fa42

View file

@ -22,7 +22,7 @@ public class ItemUtil {
Item item = stack.getItem(); Item item = stack.getItem();
return Registry.ITEM.getId(item) + ":" + stack.getCount(); return Registry.ITEM.getId(item) + ":" + stack.getCount();
} catch (Exception ex) { } catch (Exception ex) {
BetterEnd.LOGGER.catching(ex); BetterEnd.LOGGER.error("ItemStack serialization error!", ex);
} }
return ""; return "";
} }
@ -37,16 +37,18 @@ public class ItemUtil {
if (parts.length < 2) return null; if (parts.length < 2) return null;
if (parts.length == 2) { if (parts.length == 2) {
Identifier itemId = new Identifier(stackString); Identifier itemId = new Identifier(stackString);
Item item = Registry.ITEM.getOrEmpty(itemId).orElse(null); Item item = Registry.ITEM.getOrEmpty(itemId).orElseThrow(() -> {
if (item == null) return null; return new IllegalStateException("Output item " + itemId + " does not exists!");
});
return new ItemStack(item); return new ItemStack(item);
} }
Identifier itemId = new Identifier(parts[0], parts[1]); Identifier itemId = new Identifier(parts[0], parts[1]);
Item item = Registry.ITEM.getOrEmpty(itemId).orElse(null); Item item = Registry.ITEM.getOrEmpty(itemId).orElseThrow(() -> {
if (item == null) return null; return new IllegalStateException("Output item " + itemId + " does not exists!");
});
return new ItemStack(item, Integer.valueOf(parts[2])); return new ItemStack(item, Integer.valueOf(parts[2]));
} catch (Exception ex) { } catch (Exception ex) {
BetterEnd.LOGGER.catching(ex); BetterEnd.LOGGER.error("ItemStack deserialization error!", ex);
} }
return null; return null;
} }
@ -56,12 +58,14 @@ public class ItemUtil {
if (!recipe.has("item")) return null; if (!recipe.has("item")) return null;
try { try {
Identifier itemId = new Identifier(JsonHelper.getString(recipe, "item")); Identifier itemId = new Identifier(JsonHelper.getString(recipe, "item"));
Item item = Registry.ITEM.getOrEmpty(itemId).orElse(null); Item item = Registry.ITEM.getOrEmpty(itemId).orElseThrow(() -> {
return new IllegalStateException("Output item " + itemId + " does not exists!");
});
if (item == null) return null; 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) {
BetterEnd.LOGGER.catching(ex); BetterEnd.LOGGER.error("ItemStack deserialization error!", ex);
} }
return null; return null;
} }