summaryrefslogtreecommitdiff
path: root/src/main/java/lv/enes/mc/eris_alchemy
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/lv/enes/mc/eris_alchemy')
-rw-r--r--src/main/java/lv/enes/mc/eris_alchemy/utils/IngredientProvider.java2
-rw-r--r--src/main/java/lv/enes/mc/eris_alchemy/utils/ItemUtils.java12
2 files changed, 12 insertions, 2 deletions
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/utils/IngredientProvider.java b/src/main/java/lv/enes/mc/eris_alchemy/utils/IngredientProvider.java
index 6390c88..89f8ca9 100644
--- a/src/main/java/lv/enes/mc/eris_alchemy/utils/IngredientProvider.java
+++ b/src/main/java/lv/enes/mc/eris_alchemy/utils/IngredientProvider.java
@@ -15,7 +15,7 @@ import java.util.function.Supplier;
15public class IngredientProvider implements JsonDeserializer<Supplier<Ingredient>> { 15public class IngredientProvider implements JsonDeserializer<Supplier<Ingredient>> {
16 public static Supplier<Ingredient> deserialize(JsonElement el) { 16 public static Supplier<Ingredient> deserialize(JsonElement el) {
17 if (el.isJsonObject()) { 17 if (el.isJsonObject()) {
18 return () -> ItemUtils.itemStackFromJson(el.getAsJsonObject()).map(Ingredient::of).orElse(Ingredient.EMPTY); 18 return () -> ItemUtils.ingredientFromJson(el.getAsJsonObject()).orElse(Ingredient.EMPTY);
19 } else if (el.isJsonPrimitive() && el.getAsJsonPrimitive().isString()) { 19 } else if (el.isJsonPrimitive() && el.getAsJsonPrimitive().isString()) {
20 return deserialize(el.getAsString().strip()); 20 return deserialize(el.getAsString().strip());
21 } else { 21 } else {
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/utils/ItemUtils.java b/src/main/java/lv/enes/mc/eris_alchemy/utils/ItemUtils.java
index 32b9e65..ccf8b43 100644
--- a/src/main/java/lv/enes/mc/eris_alchemy/utils/ItemUtils.java
+++ b/src/main/java/lv/enes/mc/eris_alchemy/utils/ItemUtils.java
@@ -8,6 +8,7 @@ import net.minecraft.core.registries.BuiltInRegistries;
8import net.minecraft.resources.ResourceLocation; 8import net.minecraft.resources.ResourceLocation;
9import net.minecraft.world.item.Item; 9import net.minecraft.world.item.Item;
10import net.minecraft.world.item.ItemStack; 10import net.minecraft.world.item.ItemStack;
11import net.minecraft.world.item.crafting.Ingredient;
11import net.minecraft.world.item.crafting.ShapedRecipe; 12import net.minecraft.world.item.crafting.ShapedRecipe;
12import net.minecraft.world.level.ItemLike; 13import net.minecraft.world.level.ItemLike;
13 14
@@ -30,11 +31,20 @@ public final class ItemUtils {
30 return getId(stack.getItem()); 31 return getId(stack.getItem());
31 } 32 }
32 33
34 public static Optional<Ingredient> ingredientFromJson(JsonObject json) {
35 try {
36 return Optional.of(Ingredient.fromJson(json, false));
37 } catch (JsonSyntaxException ex) {
38 ErisAlchemy.LOGGER.warn("Exception while trying to parse ingredient from JSON: {}", json, ex);
39 return Optional.empty();
40 }
41 }
42
33 public static Optional<ItemStack> itemStackFromJson(JsonObject json) { 43 public static Optional<ItemStack> itemStackFromJson(JsonObject json) {
34 try { 44 try {
35 return Optional.of(ShapedRecipe.itemStackFromJson(json)); 45 return Optional.of(ShapedRecipe.itemStackFromJson(json));
36 } catch (JsonSyntaxException ex) { 46 } catch (JsonSyntaxException ex) {
37 ErisAlchemy.LOGGER.warn("Exception while trying to parse item stack from JSON", ex); 47 ErisAlchemy.LOGGER.warn("Exception while trying to parse item stack from JSON: {}", json, ex);
38 return Optional.empty(); 48 return Optional.empty();
39 } 49 }
40 } 50 }