Skip to content

Commit

Permalink
Fix reduce not correctly combining results
Browse files Browse the repository at this point in the history
Signed-off-by: TheSilkMiner <thesilkminer@outlook.com>
  • Loading branch information
TheSilkMiner committed May 23, 2021
1 parent 39cfe63 commit 4830dce
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Expand Up @@ -11,6 +11,7 @@
import java.lang.annotation.Target;
import java.util.List;
import java.util.Optional;
import java.util.function.BinaryOperator;

/**
* Represents a handler for a specific type of recipe indicated by the generic parameter.
Expand Down Expand Up @@ -164,12 +165,12 @@ public ReplacementNotSupportedException(final String message, final Throwable ca
* {@code ingredient} (i.e. {@code ingredient != result.get()}).
*/
static <U> Optional<U> attemptReplacing(final U ingredient, final Class<U> type, final List<IReplacementRule> rules) {
// TODO("Needs testing")
final BinaryOperator<Optional<U>> combiner = (oldOpt, newOpt) -> newOpt.isPresent()? newOpt : oldOpt;
return rules.stream()
.reduce(
Optional.empty(),
(optional, rule) -> rule.getReplacement(optional.orElse(ingredient), type),
(oldOptional, newOptional) -> newOptional.isPresent()? newOptional : oldOptional
(optional, rule) -> combiner.apply(optional, rule.getReplacement(optional.orElse(ingredient), type)),
combiner
);
}

Expand Down
Expand Up @@ -8,7 +8,7 @@
import java.util.List;
import java.util.stream.Collectors;

public final class ActionReplaceRecipe extends ActionRecipeBase {
public class ActionReplaceRecipe extends ActionRecipeBase {
private final ActionAddRecipe addRecipe;
private final ActionRemoveRecipeByName removeRecipe;
private final ResourceLocation oldName;
Expand Down
Expand Up @@ -71,7 +71,6 @@ public IRecipe<?> getRecipe() {

@ZenCodeType.Method
public void replace(final IIngredient from, final IIngredient to) {
// TODO("")
Replacer.forRecipes(this).replaceFully(from, to).execute();
Replacer.forRecipes(this).replace(from, to).execute();
}
}

0 comments on commit 4830dce

Please sign in to comment.