From 09a2a76408100be6bdcbf229ea7c9bd68d307acb Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Fri, 19 Jul 2024 02:01:53 +0300 Subject: [PATCH] Added even more null checks --- gradle.properties | 2 +- .../dev/latvian/mods/kubejs/recipe/KubeRecipe.java | 13 +++++++++---- .../mods/kubejs/recipe/RecipesKubeEvent.java | 6 ++++++ .../kubejs/recipe/match/ReplacementMatchInfo.java | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 3895582dc..3d35dd728 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ modrinth_id=umyGl7zF minecraft_version=1.21 mod_version=2100.7.0 -neoforge_version=21.0.86-beta +neoforge_version=21.0.106-beta parchment_version=2024.07.07 rhino_version=2100.2.5-build.41 architectury_version=13.0.4 diff --git a/src/main/java/dev/latvian/mods/kubejs/recipe/KubeRecipe.java b/src/main/java/dev/latvian/mods/kubejs/recipe/KubeRecipe.java index 76972bf79..391424036 100644 --- a/src/main/java/dev/latvian/mods/kubejs/recipe/KubeRecipe.java +++ b/src/main/java/dev/latvian/mods/kubejs/recipe/KubeRecipe.java @@ -482,7 +482,7 @@ public RecipeHolder createRecipe() { if (recipeIngredientActions != null && !recipeIngredientActions.isEmpty()) { try { json.add(KubeJSCraftingRecipe.INGREDIENT_ACTIONS_KEY, IngredientActionHolder.LIST_CODEC.encodeStart(type.event.registries.json(), recipeIngredientActions).getOrThrow()); - } catch (Exception ex) { + } catch (Throwable ex) { ConsoleJS.SERVER.error("", new KubeRuntimeException("Failed to encode " + KubeJSCraftingRecipe.INGREDIENT_ACTIONS_KEY, ex).source(sourceLine), RecipesKubeEvent.CREATE_RECIPE_SKIP_ERROR); } } @@ -497,10 +497,15 @@ public RecipeHolder createRecipe() { var o = new JsonObject(); o.addProperty("stage", json.get(KubeJSCraftingRecipe.STAGE_KEY).getAsString()); o.add("recipe", json); - var recipe = type.event.registries.decodeJson(type.event.stageSerializer.codec(), o); - return new RecipeHolder<>(id, recipe); + + try { + var recipe = type.event.registries.decodeJson(type.event.stageSerializer.codec(), o); + return recipe == null ? null : new RecipeHolder<>(id, recipe); + } catch (Throwable ex) { + ConsoleJS.SERVER.error("", new KubeRuntimeException("Failed to decode " + id + " from json " + o, ex).source(sourceLine), RecipesKubeEvent.CREATE_RECIPE_SKIP_ERROR); + } } - } else if (originalRecipe != null) { + } else if (originalRecipe != null && originalRecipe.getValue() != null) { return new RecipeHolder<>(getOrCreateId(), originalRecipe.getValue()); } diff --git a/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesKubeEvent.java b/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesKubeEvent.java index 267558b17..7d1e9e418 100644 --- a/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesKubeEvent.java +++ b/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesKubeEvent.java @@ -380,6 +380,7 @@ public void post(RecipeManagerKJS recipeManager, Map createRecipe(KubeRecipe r) { try { var rec = r.createRecipe(); + var path = r.kjs$getMod() + "/" + r.getPath(); if (!r.removed && DataExport.export != null) { @@ -390,6 +391,11 @@ private RecipeHolder createRecipe(KubeRecipe r) { } } + //noinspection ConstantValue + if (rec == null || rec.value() == null) { + return null; + } + return rec; } catch (Throwable ex) { ConsoleJS.SERVER.warn("Error parsing recipe " + r + ": " + r.json, ex, POST_SKIP_ERROR); diff --git a/src/main/java/dev/latvian/mods/kubejs/recipe/match/ReplacementMatchInfo.java b/src/main/java/dev/latvian/mods/kubejs/recipe/match/ReplacementMatchInfo.java index 1354695ab..a249e3ae1 100644 --- a/src/main/java/dev/latvian/mods/kubejs/recipe/match/ReplacementMatchInfo.java +++ b/src/main/java/dev/latvian/mods/kubejs/recipe/match/ReplacementMatchInfo.java @@ -29,6 +29,6 @@ public static ReplacementMatchInfo wrap(Context cx, Object o, TypeInfo target) { @Override public String toString() { - return exact ? "{exact: true, match: " + match + "}" : String.valueOf(match); + return (exact || componentType.isPresent()) ? "{exact: " + exact + ", componentType: " + componentType.orElse(null) + ", match: " + match + "}" : String.valueOf(match); } }