Skip to content

Commit

Permalink
Fixed concurrency issue
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Dec 6, 2023
1 parent 0912c5b commit 83d7980
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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("<unknown source>#" + 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();
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String>();

for (var item : ingredient.getItems()) {
list.add(item.kjs$toItemString());
}

in.add(list);
}

map.put("in", in);
Expand All @@ -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());
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 83d7980

Please sign in to comment.