fix crash on empty recipe JSONs

This commit is contained in:
rlnt 2024-10-23 22:36:50 +02:00
parent 0d41ce5184
commit ba06760073
No known key found for this signature in database
3 changed files with 7 additions and 5 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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()))