Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wildcard ingredients in the recipe search tree #1735

Merged
merged 2 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/java/gregtech/api/recipes/RecipeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,9 @@ private boolean recurseIngredientTreeAdd(@Nonnull Recipe recipe, @Nonnull List<L
});

// left branches are always either empty or contain recipes.
// If there's a recipe present, the addition is finished
if (r.left().isPresent()) return true;
// If there's a recipe present, the addition is finished for this ingredient
// Cannot return here, since each ingredient to add is a separate path to the recipe
if (r.left().isPresent()) continue;

// recursive part: apply the addition for the next ingredient in the list, for the right branch.
// the right branch only contains ingredients, or is empty when the left branch is present
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/gregtech/api/recipes/RecipeMapTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gregtech.api.recipes;

import gregtech.Bootstrap;
import gregtech.api.GTValues;
import gregtech.api.recipes.builders.SimpleRecipeBuilder;
import gregtech.api.recipes.map.AbstractMapIngredient;
import gregtech.api.recipes.map.MapFluidIngredient;
Expand Down Expand Up @@ -249,4 +250,23 @@ public void MapHashCollision() {

MatcherAssert.assertThat(map.keySet().size(), is(2));
}

@Test
public void wildcardInput() {
// test that all variants of a wildcard input can be used to find a recipe
RecipeMap<?> recipeMap = new RecipeMap<>("test", 1, 4, 0, 0, new SimpleRecipeBuilder(), false);
recipeMap.recipeBuilder()
.inputs(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, GTValues.W))
.outputs(new ItemStack(Blocks.COBBLESTONE, 1))
.EUt(1).duration(1)
.buildAndRegister();

for (int i = 0; i < 16; i++) { // Blocks.STAINED_HARDENED_CLAY has 16 variants
Recipe recipe = recipeMap.findRecipe(Integer.MAX_VALUE,
Collections.singletonList(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, i)),
Collections.emptyList());

MatcherAssert.assertThat(recipe, notNullValue());
}
}
}