Skip to content

Commit

Permalink
Backport CustomFilteringRule fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Witixin1512 committed Feb 24, 2024
1 parent 615c12d commit 3dcd0e4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeManager;
import java.util.Optional;

Expand All @@ -33,9 +34,9 @@ public void testCustomFilteringRule(GameTestHelper helper, ScriptBuilder builder
RecipeManager recipeManager = helper.getLevel().getServer().getRecipeManager();

//Test that the recipes were indeed replaced
Optional<? extends Recipe<?>> recipe = recipeManager.byKey(new ResourceLocation("crafttweaker:autogenerated/replacer/minecraft.diamond_block.1"));
Optional<? extends Recipe<?>> unreplaced = recipeManager.byKey(new ResourceLocation("minecraft:diamond_boots"));
boolean wasReplaced = recipe.isPresent() && recipe.get().getIngredients().get(0).test(Items.APPLE.getDefaultInstance());
Optional<? extends RecipeHolder<?>> recipe = recipeManager.byKey(new ResourceLocation("crafttweaker:autogenerated/replacer/minecraft.diamond_block.1"));
Optional<? extends RecipeHolder<?>> unreplaced = recipeManager.byKey(new ResourceLocation("minecraft:diamond_boots"));
boolean wasReplaced = recipe.isPresent() && recipe.get().value().getIngredients().get(0).test(Items.APPLE.getDefaultInstance());
//Check that the replaced one was indeed replaced and that the other one was not
assertThat("Custom filtering rule did not work", wasReplaced && unreplaced.isPresent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import crafttweaker.api.recipe.replacement.type.CustomFilteringRule;
import crafttweaker.api.ingredient.IIngredient;

Replacer.create()
.filter(CustomFilteringRule.of(rec => rec.ingredients.length > 6))
.filter(CustomFilteringRule.of(rec => rec.value.ingredients.length > 6))
.replace<IIngredient>(
<recipecomponent:crafttweaker:input/ingredients>,
<targetingstrategy:crafttweaker:shallow>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.blamejared.crafttweaker.api.bracket.custom.RecipeTypeBracketHandler;
import com.blamejared.crafttweaker.api.recipe.manager.base.IRecipeManager;
import com.blamejared.crafttweaker.api.recipe.replacement.IFilteringRule;
import com.blamejared.crafttweaker.api.util.GenericUtil;
import com.blamejared.crafttweaker_annotations.annotations.Document;
import net.minecraft.world.Container;
import net.minecraft.world.item.crafting.Recipe;
Expand Down Expand Up @@ -81,7 +82,7 @@ public static CustomFilteringRule of(final BiPredicate<IRecipeManager<?>, Recipe
* @since 11.0.0
*/
@ZenCodeType.Method("of")
public static CustomFilteringRule ofZen(final Predicate<RecipeHolder<Container>> predicate) {
public static CustomFilteringRule ofZen(final Predicate<RecipeHolder<Recipe<Container>>> predicate) {

return of(GenericUtil.<Predicate<RecipeHolder<?>>>uncheck(predicate));
}
Expand Down

0 comments on commit 3dcd0e4

Please sign in to comment.