diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c6aff1..26494bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ All notable changes to this project will be documented in this file. ## Unreleased -- / + +- fixed crash on empty recipe JSONs ## [1.2.1] - 2024-10-22 diff --git a/Common/src/main/java/com/almostreliable/unified/unification/recipe/RecipeLink.java b/Common/src/main/java/com/almostreliable/unified/unification/recipe/RecipeLink.java index 823e418..f881b03 100644 --- a/Common/src/main/java/com/almostreliable/unified/unification/recipe/RecipeLink.java +++ b/Common/src/main/java/com/almostreliable/unified/unification/recipe/RecipeLink.java @@ -32,13 +32,13 @@ public final class RecipeLink implements RecipeData { @Nullable public static RecipeLink of(ResourceLocation id, JsonObject originalRecipe) { - ResourceLocation type = ResourceLocation.tryParse(originalRecipe.get("type").getAsString()); - if (type == null) { + try { + ResourceLocation type = ResourceLocation.parse(originalRecipe.get("type").getAsString()); + return new RecipeLink(id, originalRecipe, type); + } catch (Exception e) { AlmostUnifiedCommon.LOGGER.warn("Could not detect recipe type for recipe '{}', skipping.", id); return null; } - - return new RecipeLink(id, originalRecipe, type); } public static RecipeLink ofOrThrow(ResourceLocation id, JsonObject originalRecipe) { diff --git a/Common/src/main/java/com/almostreliable/unified/unification/recipe/RecipeTransformer.java b/Common/src/main/java/com/almostreliable/unified/unification/recipe/RecipeTransformer.java index a1f58e2..68cf581 100644 --- a/Common/src/main/java/com/almostreliable/unified/unification/recipe/RecipeTransformer.java +++ b/Common/src/main/java/com/almostreliable/unified/unification/recipe/RecipeTransformer.java @@ -112,6 +112,7 @@ public class RecipeTransformer { return recipes .entrySet() .stream() + .filter(entry -> entry.getValue() instanceof JsonObject jsonObject && !jsonObject.isEmpty()) .map(entry -> RecipeLink.of(entry.getKey(), entry.getValue().getAsJsonObject())) .filter(Objects::nonNull) .sorted(Comparator.comparing(entry -> entry.getId().toString()))