diff options
| author | 2025-08-17 16:01:05 +0300 | |
|---|---|---|
| committer | 2025-08-17 16:01:05 +0300 | |
| commit | 19e0b3ac8aa3fd80afb387d56e65828a8537cc2e (patch) | |
| tree | 2b217708d8dfa539695d88cbf68cb21f0a04183c /src | |
| parent | Update to new maven URL (diff) | |
| download | mc-eris-alchemy-19e0b3ac8aa3fd80afb387d56e65828a8537cc2e.tar.gz mc-eris-alchemy-19e0b3ac8aa3fd80afb387d56e65828a8537cc2e.tar.xz mc-eris-alchemy-19e0b3ac8aa3fd80afb387d56e65828a8537cc2e.zip | |
Allow tags in more places in fake recipes
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/lv/enes/mc/eris_alchemy/utils/IngredientProvider.java | 2 | ||||
| -rw-r--r-- | src/main/java/lv/enes/mc/eris_alchemy/utils/ItemUtils.java | 12 |
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; | |||
| 15 | public class IngredientProvider implements JsonDeserializer<Supplier<Ingredient>> { | 15 | public 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; | |||
| 8 | import net.minecraft.resources.ResourceLocation; | 8 | import net.minecraft.resources.ResourceLocation; |
| 9 | import net.minecraft.world.item.Item; | 9 | import net.minecraft.world.item.Item; |
| 10 | import net.minecraft.world.item.ItemStack; | 10 | import net.minecraft.world.item.ItemStack; |
| 11 | import net.minecraft.world.item.crafting.Ingredient; | ||
| 11 | import net.minecraft.world.item.crafting.ShapedRecipe; | 12 | import net.minecraft.world.item.crafting.ShapedRecipe; |
| 12 | import net.minecraft.world.level.ItemLike; | 13 | import 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 | } |