From 101a0ba47f960cd17d3fc588486cb7f346198443 Mon Sep 17 00:00:00 2001 From: Relentless Date: Tue, 23 Aug 2022 23:22:30 +0200 Subject: [PATCH 1/3] move all unified recipes to own namespace --- .../almostreliable/unified/recipe/RecipeDumper.java | 2 +- .../com/almostreliable/unified/recipe/RecipeLink.java | 10 +++++----- .../unified/recipe/RecipeTransformer.java | 11 +++++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeDumper.java b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeDumper.java index ca8c0895..bcbd842f 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeDumper.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeDumper.java @@ -67,7 +67,7 @@ private void dumpDuplicates(StringBuilder stringBuilder) { .sorted(Comparator.comparing(r -> r.getId().toString())) .map(recipe -> "\t\t- " + recipe.getId() + "\n") .collect(Collectors.joining("", - "\t" + link.getMaster().getId() + " (Renamed to: " + link.createNewRecipeId() + ")\n", + "\t" + link.getMaster().getId() + " (Renamed to: " + link.getMaster().createNewRecipeId() + ")\n", "\n"))).collect(Collectors.joining("", type + " {\n", "}\n\n"))); }); } diff --git a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java index 988b8fb6..5f3c441b 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java @@ -170,6 +170,11 @@ public JsonObject getActual() { return getUnified() != null ? getUnified() : getOriginal(); } + public ResourceLocation createNewRecipeId() { + String newId = String.format("%s_%s", getId().getNamespace(), getId().getPath()); + return new ResourceLocation(BuildConfig.MOD_ID, newId); + } + public static final class DuplicateLink { private final Set recipes = new HashSet<>(); private RecipeLink currentMaster; @@ -200,10 +205,5 @@ public Set getRecipes() { public String toString() { return "Link{currentMaster=" + currentMaster + ", recipes=" + recipes.size() + "}"; } - - public ResourceLocation createNewRecipeId() { - String id = String.format("%s_%s", currentMaster.getId().getNamespace(), currentMaster.getId().getPath()); - return new ResourceLocation(BuildConfig.MOD_ID, id); - } } } diff --git a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeTransformer.java b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeTransformer.java index e5799de6..fe4bc3a7 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeTransformer.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeTransformer.java @@ -118,8 +118,15 @@ private void transformRecipes(List recipeLinks, BiConsumer onRemove.accept(recipe.getId())); - onAdd.accept(link.createNewRecipeId(), link.getMaster().getActual()); + link.getRecipes().forEach(recipe -> { + onRemove.accept(recipe.getId()); + unified.remove(recipe); + }); + onAdd.accept(link.getMaster().createNewRecipeId(), link.getMaster().getActual()); + } + for (RecipeLink link : unified) { + onRemove.accept(link.getId()); + onAdd.accept(link.createNewRecipeId(), link.getActual()); } } From 853e10f1fa023761615764e6940421fd470b92bb Mon Sep 17 00:00:00 2001 From: LLytho <29131229+LLytho@users.noreply.github.com> Date: Wed, 24 Aug 2022 17:13:49 +0200 Subject: [PATCH 2/3] Change id gen for unified/duplicate recipes --- .../unified/recipe/RecipeDumper.java | 72 +++++++++---------- .../unified/recipe/RecipeLink.java | 16 ++++- 2 files changed, 49 insertions(+), 39 deletions(-) diff --git a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeDumper.java b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeDumper.java index bcbd842f..d24b6024 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeDumper.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeDumper.java @@ -30,24 +30,24 @@ public void dump(boolean dumpOverview, boolean dumpUnify, boolean dumpDuplicate) String last = "# Last execution: " + format.format(new Date(startTime)); if (dumpOverview) { - StringBuilder overviewBuilder = new StringBuilder(); - overviewBuilder.append(last).append("\n"); - dumpOverview(overviewBuilder); - write(overviewBuilder, AlmostUnifiedPlatform.INSTANCE.getLogPath(), "overview_dump.txt"); + FileUtils.write(AlmostUnifiedPlatform.INSTANCE.getLogPath(), "overview_dump.txt", sb -> { + sb.append(last).append("\n"); + dumpOverview(sb); + }); } if (dumpUnify) { - StringBuilder unifyStringBuilder = new StringBuilder(); - unifyStringBuilder.append(last).append("\n"); - dumpUnifyRecipes(unifyStringBuilder, true); - write(unifyStringBuilder, AlmostUnifiedPlatform.INSTANCE.getLogPath(), "unify_dump.txt"); + FileUtils.write(AlmostUnifiedPlatform.INSTANCE.getLogPath(), "unify_dump.txt", sb -> { + sb.append(last).append("\n"); + dumpUnifyRecipes(sb); + }); } if (dumpDuplicate) { - StringBuilder duplicatesStringBuilder = new StringBuilder(); - duplicatesStringBuilder.append(last).append("\n"); - dumpDuplicates(duplicatesStringBuilder); - write(duplicatesStringBuilder, AlmostUnifiedPlatform.INSTANCE.getLogPath(), "duplicates_dump.txt"); + FileUtils.write(AlmostUnifiedPlatform.INSTANCE.getLogPath(), "duplicates_dump.txt", sb -> { + sb.append(last).append("\n"); + dumpDuplicates(sb); + }); } } @@ -61,17 +61,22 @@ private void dumpDuplicates(StringBuilder stringBuilder) { .toList(); if (duplicates.isEmpty()) return; - stringBuilder.append(duplicates.stream().map(link -> link - .getRecipes() + stringBuilder.append(duplicates .stream() - .sorted(Comparator.comparing(r -> r.getId().toString())) - .map(recipe -> "\t\t- " + recipe.getId() + "\n") - .collect(Collectors.joining("", - "\t" + link.getMaster().getId() + " (Renamed to: " + link.getMaster().createNewRecipeId() + ")\n", - "\n"))).collect(Collectors.joining("", type + " {\n", "}\n\n"))); + .map(this::createDuplicatesDump) + .collect(Collectors.joining("", type + " {\n", "}\n\n"))); }); } + private String createDuplicatesDump(RecipeLink.DuplicateLink link) { + return link + .getRecipes() + .stream() + .sorted(Comparator.comparing(r -> r.getId().toString())) + .map(r -> "\t\t- " + r.getId() + "\n") + .collect(Collectors.joining("", String.format("\t%s\n", link.getMaster().getDumpInfo()), "\n")); + } + private void dumpOverview(StringBuilder stringBuilder) { stringBuilder .append("# Overview:\n") @@ -127,22 +132,21 @@ private void dumpOverview(StringBuilder stringBuilder) { }); } - private void dumpUnifyRecipes(StringBuilder stringBuilder, boolean full) { + private void dumpUnifyRecipes(StringBuilder stringBuilder) { getSortedUnifiedRecipeTypes().forEach(type -> { stringBuilder.append(type.toString()).append(" {\n"); getSortedUnifiedRecipes(type).forEach(recipe -> { - stringBuilder.append("\t- ").append(recipe.getId()).append("\n"); - if (full) { - stringBuilder - .append("\t\t Original: ") - .append(recipe.getOriginal().toString()) - .append("\n"); - stringBuilder - .append("\t\t Transformed: ") - .append(recipe.getUnified() == null ? "NOT UNIFIED" : recipe.getUnified().toString()) - .append("\n\n"); - } + stringBuilder + .append("\t- ") + .append(recipe.getDumpInfo()) + .append("\n") + .append("\t\t Original: ") + .append(recipe.getOriginal().toString()) + .append("\n") + .append("\t\t Transformed: ") + .append(recipe.getUnified() == null ? "NOT UNIFIED" : recipe.getUnified().toString()) + .append("\n\n"); }); stringBuilder.append("}\n\n"); @@ -165,13 +169,7 @@ private Stream getSortedUnifiedRecipes(ResourceLocation type) { return result.getUnifiedRecipes(type).stream().sorted(Comparator.comparing(r -> r.getId().toString())); } - private void write(StringBuilder stringBuilder, Path path, String fileName) { - FileUtils.write(path, fileName, sb -> sb.append(stringBuilder)); - } - private long getTotalTime() { return endTime - startTime; } - - } diff --git a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java index 5f3c441b..5776c97b 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java @@ -171,8 +171,20 @@ public JsonObject getActual() { } public ResourceLocation createNewRecipeId() { - String newId = String.format("%s_%s", getId().getNamespace(), getId().getPath()); - return new ResourceLocation(BuildConfig.MOD_ID, newId); + StringBuilder sb = new StringBuilder(); + if (isUnified()) sb.append("u"); + if (hasDuplicateLink()) sb.append("d"); + if (sb.length() > 0) sb.append("/"); + sb.append(getId().getNamespace()).append("/").append(getId().getPath()); + return new ResourceLocation(BuildConfig.MOD_ID, sb.toString()); + } + + public String getDumpInfo() { + if (isUnified() || hasDuplicateLink()) { + return getId() + " (Renamed to: " + createNewRecipeId() + ")"; + } + + return getId().toString(); } public static final class DuplicateLink { From 06c2df5c64728026cd7158a3e6801b4514f15b9b Mon Sep 17 00:00:00 2001 From: Relentless Date: Wed, 24 Aug 2022 20:40:15 +0200 Subject: [PATCH 3/3] change string builder empty check [skip build] --- .../main/java/com/almostreliable/unified/recipe/RecipeLink.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java index 5776c97b..8afa2adb 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java @@ -174,7 +174,7 @@ public ResourceLocation createNewRecipeId() { StringBuilder sb = new StringBuilder(); if (isUnified()) sb.append("u"); if (hasDuplicateLink()) sb.append("d"); - if (sb.length() > 0) sb.append("/"); + if (!sb.isEmpty()) sb.append("/"); sb.append(getId().getNamespace()).append("/").append(getId().getPath()); return new ResourceLocation(BuildConfig.MOD_ID, sb.toString()); }