Skip to content

Commit

Permalink
Add API for requesting craftable items by output, required for #127
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Oct 16, 2024
1 parent 4c60561 commit 970ec31
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ public interface ITerminalStorageTabIngredientCraftingHandler<O extends ITermina
*/
public <T, M> Collection<O> getCraftingOptions(TerminalStorageTabIngredientComponentServer<T, M> tab, int channel);

/**
* Get all crafting options in the given tab that produce the given output instance.
* @param tab An ingredient tab.
* @param channel The channel to get the options for.
* @param instance The expect output instance.
* @param matchCondition The expected output match condition.
* @param <T> The instance type.
* @param <M> The matching condition parameter.
* @return Crafting options.
*/
public <T, M> Collection<O> getCraftingOptionsWithOutput(TerminalStorageTabIngredientComponentServer<T, M> tab, int channel, T instance, M matchCondition);

/**
* Serialize a crafting option to NBT.
* @param craftingOption A crafting option.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ public <T, M> int[] getChannels(TerminalStorageTabIngredientComponentServer<T, M
public <T, M> Collection<TerminalCraftingOptionRecipeDefinition<?, ?>> getCraftingOptions(TerminalStorageTabIngredientComponentServer<T, M> tab, int channel) {
IngredientComponent<T, M> ingredientComponent = tab.getIngredientNetwork().getComponent();
IIngredientMatcher<T, M> matcher = ingredientComponent.getMatcher();
return getCraftingOptionsWithOutput(tab, channel, matcher.getEmptyInstance(), matcher.getAnyMatchCondition());
}

@Override
public <T, M> Collection<TerminalCraftingOptionRecipeDefinition<?, ?>> getCraftingOptionsWithOutput(TerminalStorageTabIngredientComponentServer<T, M> tab, int channel, T instance, M matchCondition) {
IngredientComponent<T, M> ingredientComponent = tab.getIngredientNetwork().getComponent();
IRecipeIndex recipeIndex = getRecipeIndex(tab.getNetwork(), channel);
Iterable<IRecipeDefinition> recipes = () -> recipeIndex.getRecipes(ingredientComponent, matcher.getEmptyInstance(), matcher.getAnyMatchCondition());
Iterable<IRecipeDefinition> recipes = () -> recipeIndex.getRecipes(ingredientComponent, instance, matchCondition);
return StreamSupport.stream(recipes.spliterator(), false)
.map((recipe) -> new TerminalCraftingOptionRecipeDefinition<>(ingredientComponent, recipe))
.collect(Collectors.toList());
Expand Down

0 comments on commit 970ec31

Please sign in to comment.