-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize adding ingredients to recipes for lookups
- Loading branch information
Showing
12 changed files
with
211 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 10 additions & 35 deletions
45
Library/src/main/java/mezz/jei/library/gui/recipes/RecipeLayoutIngredientSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,27 @@ | ||
package mezz.jei.library.gui.recipes; | ||
|
||
import mezz.jei.api.ingredients.IIngredientType; | ||
import mezz.jei.api.ingredients.ITypedIngredient; | ||
import mezz.jei.api.recipe.RecipeIngredientRole; | ||
import mezz.jei.library.gui.recipes.layout.builder.RecipeSlotIngredients; | ||
import mezz.jei.library.gui.recipes.supplier.builder.IngredientSlotBuilder; | ||
import mezz.jei.library.ingredients.IIngredientSupplier; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
import java.util.Map; | ||
|
||
public class RecipeLayoutIngredientSupplier implements IIngredientSupplier { | ||
private final List<RecipeSlotIngredients> slots; | ||
private final Map<RecipeIngredientRole, IngredientSlotBuilder> ingredientSlotBuilders; | ||
|
||
public RecipeLayoutIngredientSupplier(List<RecipeSlotIngredients> slots) { | ||
this.slots = slots; | ||
public RecipeLayoutIngredientSupplier(Map<RecipeIngredientRole, IngredientSlotBuilder> ingredientSlotBuilders) { | ||
this.ingredientSlotBuilders = ingredientSlotBuilders; | ||
} | ||
|
||
@Override | ||
public Stream<? extends IIngredientType<?>> getIngredientTypes(RecipeIngredientRole role) { | ||
return slots.stream() | ||
.filter(slot -> slot.role() == role) | ||
.map(RecipeSlotIngredients::types) | ||
.flatMap(Collection::stream) | ||
.distinct(); | ||
} | ||
|
||
@Override | ||
public <T> Stream<T> getIngredientStream(IIngredientType<T> ingredientType, RecipeIngredientRole role) { | ||
return slots.stream() | ||
.filter(slot -> slot.role() == role) | ||
.flatMap(slot -> slot.ingredients().stream()) | ||
.map(ingredientType::castIngredient) | ||
.flatMap(Optional::stream); | ||
} | ||
|
||
@Override | ||
public Collection<Optional<ITypedIngredient<?>>> getIngredients(RecipeIngredientRole role) { | ||
List<Optional<ITypedIngredient<?>>> ingredients = new ArrayList<>(); | ||
|
||
for (RecipeSlotIngredients slot : slots) { | ||
if (slot.role() == role) { | ||
ingredients.addAll(slot.ingredients()); | ||
} | ||
public Collection<ITypedIngredient<?>> getIngredients(RecipeIngredientRole role) { | ||
IngredientSlotBuilder ingredientSlotBuilder = ingredientSlotBuilders.get(role); | ||
if (ingredientSlotBuilder == null) { | ||
return List.of(); | ||
} | ||
|
||
return ingredients; | ||
return ingredientSlotBuilder.getAllIngredients(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/RecipeSlotIngredients.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.