From 7b3aaa362734a1c591fd967de86766cfe17c8066 Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Sun, 1 Sep 2024 11:48:16 +0300 Subject: [PATCH] Fixed all recipes always being saved even without changes --- .../java/dev/latvian/mods/kubejs/recipe/KubeRecipe.java | 6 +++--- .../dev/latvian/mods/kubejs/recipe/RecipeTypeFunction.java | 2 +- .../dev/latvian/mods/kubejs/recipe/RecipesKubeEvent.java | 2 +- .../mods/kubejs/recipe/schema/KubeRecipeFactory.java | 4 ++-- .../mods/kubejs/recipe/schema/RecipeConstructor.java | 2 +- .../dev/latvian/mods/kubejs/recipe/schema/RecipeSchema.java | 3 +-- src/main/java/dev/latvian/mods/kubejs/script/ConsoleJS.java | 4 ++-- 7 files changed, 11 insertions(+), 12 deletions(-) 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 47e209703..a6d56750b 100644 --- a/src/main/java/dev/latvian/mods/kubejs/recipe/KubeRecipe.java +++ b/src/main/java/dev/latvian/mods/kubejs/recipe/KubeRecipe.java @@ -152,15 +152,15 @@ public KubeRecipe set(Context cx, String key, Object value) { throw new MissingComponentException(key, null, valueMap.keySet()).source(sourceLine); } - public void initValues(boolean created) { - if (created) { + public void initValues(boolean save) { + if (save) { save(); } if (!type.schemaType.schema.keys.isEmpty()) { valueMap = new RecipeComponentValueMap(type.schemaType.schema.keys); - if (created) { + if (save) { for (var v : valueMap.holders) { if (v.key.optional()) { v.value = Cast.to(v.key.optional.getDefaultValue(type.schemaType)); diff --git a/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeTypeFunction.java b/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeTypeFunction.java index 0f36310a5..76a780a99 100644 --- a/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeTypeFunction.java +++ b/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeTypeFunction.java @@ -41,7 +41,7 @@ public KubeRecipe call(Context cx, Scriptable scope, Scriptable thisObj, Object[ try { return createRecipe(cx, sourceLine, args0); } catch (Throwable cause) { - var r = schemaType.schema.recipeFactory.create(this, sourceLine); + var r = schemaType.schema.recipeFactory.create(this, sourceLine, true); r.creationError = true; event.failedCount.incrementAndGet(); ConsoleJS.SERVER.error("Failed to create a '" + idString + "' recipe from args " + Arrays.toString(args0), sourceLine, cause, SKIP_ERROR); 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 a8ff4ec5f..4bb3c822e 100644 --- a/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesKubeEvent.java +++ b/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesKubeEvent.java @@ -553,7 +553,7 @@ public KubeRecipe custom(Context cx, JsonObject json) { r.afterLoaded(); return addRecipe(r, true); } catch (Throwable cause) { - var r = type.schemaType.schema.recipeFactory.create(type, sourceLine); + var r = type.schemaType.schema.recipeFactory.create(type, sourceLine, true); r.creationError = true; ConsoleJS.SERVER.error("Failed to create custom recipe from json " + JsonUtils.toString(json), sourceLine, cause, POST_SKIP_ERROR); r.json = json; diff --git a/src/main/java/dev/latvian/mods/kubejs/recipe/schema/KubeRecipeFactory.java b/src/main/java/dev/latvian/mods/kubejs/recipe/schema/KubeRecipeFactory.java index 093c57b3e..0f6707890 100644 --- a/src/main/java/dev/latvian/mods/kubejs/recipe/schema/KubeRecipeFactory.java +++ b/src/main/java/dev/latvian/mods/kubejs/recipe/schema/KubeRecipeFactory.java @@ -16,11 +16,11 @@ public KubeRecipeFactory(ResourceLocation id, Class recipeType, Supplier {