Skip to content

Commit

Permalink
Added even more null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Jul 18, 2024
1 parent 5f42258 commit 09a2a76
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/dev/latvian/mods/kubejs/recipe/KubeRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ public void post(RecipeManagerKJS recipeManager, Map<ResourceLocation, JsonEleme
private RecipeHolder<?> createRecipe(KubeRecipe r) {
try {
var rec = r.createRecipe();

var path = r.kjs$getMod() + "/" + r.getPath();

if (!r.removed && DataExport.export != null) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 09a2a76

Please sign in to comment.