Skip to content

Commit

Permalink
Fixed all recipes always being saved even without changes
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Sep 1, 2024
1 parent e806423 commit 7b3aaa3
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/main/java/dev/latvian/mods/kubejs/recipe/KubeRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public KubeRecipeFactory(ResourceLocation id, Class<?> recipeType, Supplier<? ex
this(id, TypeInfo.of(recipeType), factory);
}

public KubeRecipe create(RecipeTypeFunction type, SourceLine sourceLine) {
public KubeRecipe create(RecipeTypeFunction type, SourceLine sourceLine, boolean save) {
var r = factory.get();
r.sourceLine = sourceLine;
r.type = type;
r.initValues(true);
r.initValues(save);
return r;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public String toString() {
}

public KubeRecipe create(Context cx, SourceLine sourceLine, RecipeTypeFunction type, RecipeSchemaType schemaType, ComponentValueMap from) {
var r = schemaType.schema.recipeFactory.create(type, sourceLine);
var r = schemaType.schema.recipeFactory.create(type, sourceLine, true);
r.json = new JsonObject();
r.json.addProperty("type", type.idString);
r.newRecipe = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,10 @@ public boolean constructorsGenerated() {
}

public KubeRecipe deserialize(SourceLine sourceLine, RecipeTypeFunction type, @Nullable ResourceLocation id, JsonObject json) {
var r = recipeFactory.create(type, sourceLine);
var r = recipeFactory.create(type, sourceLine, id == null);
r.id = id;
r.json = json;
r.newRecipe = id == null;
r.initValues(id == null);
r.originalJson = json == null || id == null ? null : (JsonObject) JsonUtils.copy(json);
r.deserialize(false);
return r;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/latvian/mods/kubejs/script/ConsoleJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,9 @@ public void handleError(ConsoleLine line, Throwable error, @Nullable Pattern exi
public Component errorsComponent(String command) {
return Component.empty()
.append(TextIcons.error())
.append(Component.literal(" KubeJS errors found [" + errors.size() + "]! Click here for more info").kjs$red())
.append(Component.literal(" KubeJS errors found [" + errors.size() + "]!").kjs$red())
.kjs$clickRunCommand(command)
.kjs$hover(Component.literal("Click to show"));
.kjs$hover(Component.literal("Click to show more info"));
}

private static final class VarFunc implements Comparable<VarFunc> {
Expand Down

0 comments on commit 7b3aaa3

Please sign in to comment.