mirror of
https://github.com/AlmostReliable/almostunified.git
synced 2024-11-14 03:05:02 -05:00
fix crash on empty recipe JSONs
This commit is contained in:
parent
0d41ce5184
commit
ba06760073
3 changed files with 7 additions and 5 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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()))
|
||||
|
|
Loading…
Reference in a new issue