mirror of
https://github.com/AlmostReliable/almostunified.git
synced 2024-11-14 19:25:13 -05:00
Fix duplicates will not be removed after check
This commit is contained in:
parent
fff3c442d8
commit
d2a219f00d
3 changed files with 49 additions and 31 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -102,13 +102,18 @@ 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue