Merge remote-tracking branch 'origin/1.18' into 1.18

This commit is contained in:
Relentless 2022-08-23 13:42:39 +02:00
commit 9ea879b484
No known key found for this signature in database
GPG key ID: 759D97B8C6F25265
5 changed files with 54 additions and 35 deletions

View file

@ -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
<!-- Versions -->
[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

View file

@ -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);
}
}
}

View file

@ -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,36 +122,50 @@ 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");
}
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;
}
public boolean handleDuplicate(RecipeLink otherRecipe, JsonCompare.CompareSettings compareSettings) {
DuplicateLink selfDuplicate = getDuplicateLink();
DuplicateLink otherDuplicate = otherRecipe.getDuplicateLink();
if (selfDuplicate != null && otherDuplicate != null) {
return selfDuplicate == otherDuplicate;
}
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;
}
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() {
return getUnified() != null ? getUnified() : getOriginal();
}

View file

@ -102,14 +102,19 @@ public class RecipeTransformer {
private void transformRecipes(List<RecipeLink> recipeLinks, BiConsumer<ResourceLocation, JsonElement> onAdd, Consumer<ResourceLocation> onRemove) {
Set<RecipeLink.DuplicateLink> duplicates = new HashSet<>(recipeLinks.size());
List<RecipeLink> 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());
}
}
for (RecipeLink.DuplicateLink link : duplicates) {
@ -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;
}
/**

View file

@ -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