mirror of
https://github.com/AlmostReliable/almostunified.git
synced 2024-11-14 19:25:13 -05:00
Merge remote-tracking branch 'origin/1.18' into 1.18
This commit is contained in:
commit
9ea879b484
5 changed files with 54 additions and 35 deletions
|
@ -5,8 +5,9 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog],
|
The format is based on [Keep a Changelog],
|
||||||
and this project adheres to [Semantic Versioning].
|
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
|
## [0.0.1] - 2022-08-21
|
||||||
|
|
||||||
|
@ -17,5 +18,5 @@ Initial beta release!
|
||||||
[semantic versioning]: https://semver.org/spec/v2.0.0.html
|
[semantic versioning]: https://semver.org/spec/v2.0.0.html
|
||||||
|
|
||||||
<!-- Versions -->
|
<!-- 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
|
[0.0.1]: https://github.com/AlmostReliable/almostunified/releases/tag/v1.18-0.0.1-beta
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class RecipeManagerMixin {
|
||||||
AlmostUnified.reloadRuntime();
|
AlmostUnified.reloadRuntime();
|
||||||
AlmostUnified.getRuntime().run(object);
|
AlmostUnified.getRuntime().run(object);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
AlmostUnified.LOG.error(e);
|
AlmostUnified.LOG.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,10 +83,10 @@ public class RecipeLink {
|
||||||
return duplicateLink;
|
return duplicateLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDuplicateLink(@Nullable DuplicateLink duplicateLink) {
|
private void updateDuplicateLink(@Nullable DuplicateLink duplicateLink) {
|
||||||
Objects.requireNonNull(duplicateLink);
|
Objects.requireNonNull(duplicateLink);
|
||||||
if (hasDuplicateLink()) {
|
if (hasDuplicateLink() && getDuplicateLink() != duplicateLink) {
|
||||||
throw new IllegalStateException("Recipe already linked");
|
throw new IllegalStateException("Recipe is already linked to " + getDuplicateLink());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.duplicateLink = duplicateLink;
|
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,
|
* 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.
|
* 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.
|
* @param compareSettings Settings to use for comparison.
|
||||||
* @return True if recipe is a duplicate, false otherwise.
|
* @return True if recipe is a duplicate, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean handleDuplicate(RecipeLink recipe, JsonCompare.CompareSettings compareSettings) {
|
public boolean handleDuplicate(RecipeLink otherRecipe, JsonCompare.CompareSettings compareSettings) {
|
||||||
if (hasDuplicateLink()) {
|
DuplicateLink selfDuplicate = getDuplicateLink();
|
||||||
throw new IllegalStateException("Recipe already linked");
|
DuplicateLink otherDuplicate = otherRecipe.getDuplicateLink();
|
||||||
}
|
|
||||||
|
if (selfDuplicate != null && otherDuplicate != null) {
|
||||||
DuplicateLink link = recipe.getDuplicateLink();
|
return selfDuplicate == otherDuplicate;
|
||||||
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;
|
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() {
|
public JsonObject getActual() {
|
||||||
return getUnified() != null ? getUnified() : getOriginal();
|
return getUnified() != null ? getUnified() : getOriginal();
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,14 +102,19 @@ public class RecipeTransformer {
|
||||||
|
|
||||||
private void transformRecipes(List<RecipeLink> recipeLinks, BiConsumer<ResourceLocation, JsonElement> onAdd, Consumer<ResourceLocation> onRemove) {
|
private void transformRecipes(List<RecipeLink> recipeLinks, BiConsumer<ResourceLocation, JsonElement> onAdd, Consumer<ResourceLocation> onRemove) {
|
||||||
Set<RecipeLink.DuplicateLink> duplicates = new HashSet<>(recipeLinks.size());
|
Set<RecipeLink.DuplicateLink> duplicates = new HashSet<>(recipeLinks.size());
|
||||||
|
List<RecipeLink> unified = new ArrayList<>(recipeLinks.size());
|
||||||
for (RecipeLink curRecipe : recipeLinks) {
|
for (RecipeLink curRecipe : recipeLinks) {
|
||||||
unifyRecipe(curRecipe);
|
unifyRecipe(curRecipe);
|
||||||
if (curRecipe.isUnified()) {
|
if (curRecipe.isUnified()) {
|
||||||
onAdd.accept(curRecipe.getId(), curRecipe.getUnified());
|
onAdd.accept(curRecipe.getId(), curRecipe.getUnified());
|
||||||
if (handleDuplicate(curRecipe, recipeLinks)) {
|
unified.add(curRecipe);
|
||||||
duplicates.add(curRecipe.getDuplicateLink());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (RecipeLink unifiedLink : unified) {
|
||||||
|
if (handleDuplicate(unifiedLink, recipeLinks)) {
|
||||||
|
duplicates.add(unifiedLink.getDuplicateLink());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (RecipeLink.DuplicateLink link : duplicates) {
|
for (RecipeLink.DuplicateLink link : duplicates) {
|
||||||
|
@ -142,6 +147,7 @@ public class RecipeTransformer {
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonCompare.CompareSettings compareSettings = duplicationConfig.getCompareSettings(curRecipe.getType());
|
JsonCompare.CompareSettings compareSettings = duplicationConfig.getCompareSettings(curRecipe.getType());
|
||||||
|
boolean foundDuplicate = false;
|
||||||
for (RecipeLink recipeLink : recipes) {
|
for (RecipeLink recipeLink : recipes) {
|
||||||
if (!curRecipe.getType().equals(recipeLink.getType())) {
|
if (!curRecipe.getType().equals(recipeLink.getType())) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
|
@ -152,12 +158,10 @@ public class RecipeTransformer {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curRecipe.handleDuplicate(recipeLink, compareSettings)) {
|
foundDuplicate |= curRecipe.handleDuplicate(recipeLink, compareSettings);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return foundDuplicate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Project
|
# Project
|
||||||
version = 0.0.1
|
version = 0.0.2
|
||||||
group = com.almostreliable.unified
|
group = com.almostreliable.unified
|
||||||
license = LGPL-3.0
|
license = LGPL-3.0
|
||||||
mixinVersion = 0.8.5
|
mixinVersion = 0.8.5
|
||||||
|
|
Loading…
Reference in a new issue