From 83d7980edea88c04358b1a8f4c1d028e9835afe9 Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Wed, 6 Dec 2023 04:03:34 +0200 Subject: [PATCH] Fixed concurrency issue --- .../mods/kubejs/client/KubeJSErrorScreen.java | 6 +++-- .../latvian/mods/kubejs/recipe/RecipeJS.java | 10 +------- .../mods/kubejs/recipe/RecipesEventJS.java | 24 ++++++++++++++++--- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/client/KubeJSErrorScreen.java b/common/src/main/java/dev/latvian/mods/kubejs/client/KubeJSErrorScreen.java index de2f2d74d..9994fa23b 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/client/KubeJSErrorScreen.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/client/KubeJSErrorScreen.java @@ -196,11 +196,13 @@ public Entry(ErrorList errorList, Minecraft minecraft, int index, ConsoleLine li if (line.source.isEmpty()) { if (line.externalFile != null) { this.scriptLineText = Component.literal(line.externalFile.getFileName().toString()).getVisualOrderText(); + } else if (line.line == 0) { + this.scriptLineText = Component.literal("Internal Error").getVisualOrderText(); } else { this.scriptLineText = Component.literal("#" + line.line).getVisualOrderText(); } } else { - this.scriptLineText = Component.literal((line.source + "#") + line.line).getVisualOrderText(); + this.scriptLineText = Component.literal(line.source + "#" + line.line).getVisualOrderText(); } var sb = new StringBuilder(); @@ -262,7 +264,7 @@ public void open() { throw new IllegalStateException("Error"); } } catch (Exception ignored) { - if (Files.isRegularFile(path)) { + if (Files.isRegularFile(path) && !path.getFileName().toString().endsWith(".js")) { path = path.getParent(); } diff --git a/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeJS.java b/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeJS.java index 95e694729..fa73c1b0f 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeJS.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeJS.java @@ -412,15 +412,7 @@ public ResourceLocation getOrCreateId() { ids = RecipeSchema.normalizeId(ids).replace(':', '_').replace('/', '_'); } - int i = 2; - id = new ResourceLocation(prefix + ids); - - while (type.event.takenIds.containsKey(id)) { - id = new ResourceLocation(prefix + ids + '_' + i); - i++; - } - - type.event.takenIds.put(id, this); + id = type.event.takeId(this, prefix, ids); } return id; diff --git a/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesEventJS.java b/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesEventJS.java index bda8151d7..55dbdb468 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesEventJS.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesEventJS.java @@ -47,7 +47,6 @@ import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -95,7 +94,13 @@ private static String recipeToString(Recipe recipe) { var in = new ArrayList<>(); for (var ingredient : recipe.getIngredients()) { - in.add(Arrays.asList(ingredient.getItems())); + var list = new ArrayList(); + + for (var item : ingredient.getItems()) { + list.add(item.kjs$toItemString()); + } + + in.add(list); } map.put("in", in); @@ -104,7 +109,7 @@ private static String recipeToString(Recipe recipe) { } try { - map.put("out", recipe.getResultItem(UtilsJS.staticRegistryAccess)); + map.put("out", recipe.getResultItem(UtilsJS.staticRegistryAccess).kjs$toItemString()); } catch (Exception ex) { map.put("out_error", ex.toString()); } @@ -685,6 +690,19 @@ public void printExamples(String type) { } } + public synchronized ResourceLocation takeId(RecipeJS recipe, String prefix, String ids) { + int i = 2; + var id = new ResourceLocation(prefix + ids); + + while (takenIds.containsKey(id)) { + id = new ResourceLocation(prefix + ids + '_' + i); + i++; + } + + takenIds.put(id, recipe); + return id; + } + public void setItemErrors(boolean b) { RecipeJS.itemErrors = b; }