diff --git a/CHANGELOG.md b/CHANGELOG.md index 33a2065..c825698 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning]. -## [Unreleased] -- / +## [0.0.2] - 2022-08-23 + +Fix duplicates will not be removed after check ## [0.0.1] - 2022-08-21 @@ -17,5 +18,5 @@ Initial beta release! [semantic versioning]: https://semver.org/spec/v2.0.0.html -[unreleased]: https://github.com/AlmostReliable/almostunified/compare/v1.18-0.0.1-beta...HEAD +[0.0.2]: https://github.com/AlmostReliable/almostunified/releases/tag/v1.18-0.0.2-beta [0.0.1]: https://github.com/AlmostReliable/almostunified/releases/tag/v1.18-0.0.1-beta diff --git a/Common/src/main/java/com/almostreliable/unified/mixin/RecipeManagerMixin.java b/Common/src/main/java/com/almostreliable/unified/mixin/RecipeManagerMixin.java index 593ba86..e362fbf 100644 --- a/Common/src/main/java/com/almostreliable/unified/mixin/RecipeManagerMixin.java +++ b/Common/src/main/java/com/almostreliable/unified/mixin/RecipeManagerMixin.java @@ -22,7 +22,7 @@ public class RecipeManagerMixin { AlmostUnified.reloadRuntime(); AlmostUnified.getRuntime().run(object); } catch (Exception e) { - AlmostUnified.LOG.error(e); + AlmostUnified.LOG.error(e.getMessage(), e); } } } 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 16166d3..ee3458f 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java @@ -83,10 +83,10 @@ public class RecipeLink { return duplicateLink; } - private void setDuplicateLink(@Nullable DuplicateLink duplicateLink) { + private void updateDuplicateLink(@Nullable DuplicateLink duplicateLink) { Objects.requireNonNull(duplicateLink); - if (hasDuplicateLink()) { - throw new IllegalStateException("Recipe already linked"); + if (hasDuplicateLink() && getDuplicateLink() != duplicateLink) { + throw new IllegalStateException("Recipe is already linked to " + getDuplicateLink()); } this.duplicateLink = duplicateLink; @@ -122,34 +122,48 @@ public class RecipeLink { * Checks for duplicate against given recipe data. If recipe data already has a duplicate link, * the master from the link will be used. Otherwise, we will create a new link if needed. * - * @param recipe Recipe data to check for duplicate against. + * @param otherRecipe Recipe data to check for duplicate against. * @param compareSettings Settings to use for comparison. * @return True if recipe is a duplicate, false otherwise. */ - public boolean handleDuplicate(RecipeLink recipe, JsonCompare.CompareSettings compareSettings) { - if (hasDuplicateLink()) { - throw new IllegalStateException("Recipe already linked"); + public boolean handleDuplicate(RecipeLink otherRecipe, JsonCompare.CompareSettings compareSettings) { + DuplicateLink selfDuplicate = getDuplicateLink(); + DuplicateLink otherDuplicate = otherRecipe.getDuplicateLink(); + + if (selfDuplicate != null && otherDuplicate != null) { + return selfDuplicate == otherDuplicate; } - DuplicateLink link = recipe.getDuplicateLink(); - if (link != null) { - RecipeLink compare = RecipeLink.compare(this, link.getMaster(), compareSettings); - if (compare != null) { - link.updateMaster(this); - setDuplicateLink(link); - return true; - } - } else { - RecipeLink compare = RecipeLink.compare(this, recipe, compareSettings); - if (compare != null) { - DuplicateLink newLink = new DuplicateLink(compare); - setDuplicateLink(newLink); - recipe.setDuplicateLink(newLink); - return true; + if (selfDuplicate == null && otherDuplicate == null) { + RecipeLink compare = RecipeLink.compare(this, otherRecipe, compareSettings); + if (compare == null) { + return false; } + + DuplicateLink newLink = new DuplicateLink(compare); + updateDuplicateLink(newLink); + otherRecipe.updateDuplicateLink(newLink); + return true; } - return false; + if (otherDuplicate != null) { + RecipeLink compare = RecipeLink.compare(this, otherDuplicate.getMaster(), compareSettings); + if (compare == null) { + return false; + } + otherDuplicate.updateMaster(compare); + updateDuplicateLink(otherDuplicate); + return true; + } + + // selfDuplicate != null + RecipeLink compare = RecipeLink.compare(selfDuplicate.getMaster(), otherRecipe, compareSettings); + if (compare == null) { + return false; + } + selfDuplicate.updateMaster(compare); + otherRecipe.updateDuplicateLink(selfDuplicate); + return true; } public JsonObject getActual() { 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 c128c6e..b0ee711 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeTransformer.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeTransformer.java @@ -102,13 +102,18 @@ public class RecipeTransformer { private void transformRecipes(List recipeLinks, BiConsumer onAdd, Consumer onRemove) { Set duplicates = new HashSet<>(recipeLinks.size()); + List unified = new ArrayList<>(recipeLinks.size()); for (RecipeLink curRecipe : recipeLinks) { unifyRecipe(curRecipe); if (curRecipe.isUnified()) { onAdd.accept(curRecipe.getId(), curRecipe.getUnified()); - if (handleDuplicate(curRecipe, recipeLinks)) { - duplicates.add(curRecipe.getDuplicateLink()); - } + unified.add(curRecipe); + } + } + + for (RecipeLink unifiedLink : unified) { + if (handleDuplicate(unifiedLink, recipeLinks)) { + duplicates.add(unifiedLink.getDuplicateLink()); } } @@ -142,6 +147,7 @@ public class RecipeTransformer { } JsonCompare.CompareSettings compareSettings = duplicationConfig.getCompareSettings(curRecipe.getType()); + boolean foundDuplicate = false; for (RecipeLink recipeLink : recipes) { if (!curRecipe.getType().equals(recipeLink.getType())) { throw new IllegalStateException( @@ -152,12 +158,10 @@ public class RecipeTransformer { continue; } - if (curRecipe.handleDuplicate(recipeLink, compareSettings)) { - return true; - } + foundDuplicate |= curRecipe.handleDuplicate(recipeLink, compareSettings); } - return false; + return foundDuplicate; } /** diff --git a/gradle.properties b/gradle.properties index 2cd756a..d991c95 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Project -version = 0.0.1 +version = 0.0.2 group = com.almostreliable.unified license = LGPL-3.0 mixinVersion = 0.8.5