diff options
Diffstat (limited to 'src/main/java/lv/enes/mc/eris_alchemy/utils/ItemUtils.java')
| -rw-r--r-- | src/main/java/lv/enes/mc/eris_alchemy/utils/ItemUtils.java | 15 |
1 files changed, 15 insertions, 0 deletions
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 7ac7358..0801d11 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 | |||
| @@ -1,12 +1,18 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.utils; | 1 | package lv.enes.mc.eris_alchemy.utils; |
| 2 | 2 | ||
| 3 | import com.google.gson.JsonObject; | ||
| 4 | import com.google.gson.JsonSyntaxException; | ||
| 5 | import lv.enes.mc.eris_alchemy.ErisAlchemy; | ||
| 3 | import net.minecraft.core.Holder; | 6 | import net.minecraft.core.Holder; |
| 4 | import net.minecraft.core.registries.BuiltInRegistries; | 7 | import net.minecraft.core.registries.BuiltInRegistries; |
| 5 | import net.minecraft.resources.ResourceLocation; | 8 | import net.minecraft.resources.ResourceLocation; |
| 6 | import net.minecraft.world.item.Item; | 9 | import net.minecraft.world.item.Item; |
| 7 | import net.minecraft.world.item.ItemStack; | 10 | import net.minecraft.world.item.ItemStack; |
| 11 | import net.minecraft.world.item.crafting.ShapedRecipe; | ||
| 8 | import net.minecraft.world.level.ItemLike; | 12 | import net.minecraft.world.level.ItemLike; |
| 9 | 13 | ||
| 14 | import java.util.Optional; | ||
| 15 | |||
| 10 | public final class ItemUtils { | 16 | public final class ItemUtils { |
| 11 | public static Item get(ResourceLocation id) { | 17 | public static Item get(ResourceLocation id) { |
| 12 | return BuiltInRegistries.ITEM.get(id); | 18 | return BuiltInRegistries.ITEM.get(id); |
| @@ -24,5 +30,14 @@ public final class ItemUtils { | |||
| 24 | return getId(stack.getItem()); | 30 | return getId(stack.getItem()); |
| 25 | } | 31 | } |
| 26 | 32 | ||
| 33 | public static Optional<ItemStack> itemStackFromJson(JsonObject json) { | ||
| 34 | try { | ||
| 35 | return Optional.of(ShapedRecipe.itemStackFromJson(json)); | ||
| 36 | } catch (JsonSyntaxException ex) { | ||
| 37 | ErisAlchemy.LOGGER.error("Exception while trying to parse item stack from JSON", ex); | ||
| 38 | return Optional.empty(); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 27 | private ItemUtils() {} | 42 | private ItemUtils() {} |
| 28 | } | 43 | } |