Skip to content

Commit

Permalink
fix crash on empty recipe JSONs
Browse files Browse the repository at this point in the history
  • Loading branch information
rlnt committed Oct 23, 2024
1 parent 0d41ce5 commit ba06760
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ private RecipeLink(ResourceLocation id, JsonObject originalRecipe, ResourceLocat

@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public Map<ResourceLocation, List<RecipeLink>> groupRecipesByType(Map<ResourceLo
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()))
Expand Down

0 comments on commit ba06760

Please sign in to comment.