From 0239bf2fb623863164da37df7f059d29805ed1b9 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 20 Jun 2021 01:16:36 +0800 Subject: Add registerRecipeFiller for checking recipe types --- .../client/registry/display/DisplayRegistry.java | 62 +++++++++++++++++++--- 1 file changed, 56 insertions(+), 6 deletions(-) (limited to 'api') diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java index 1c9ac5d0c..be9c107ef 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java @@ -33,11 +33,9 @@ import me.shedaniel.rei.api.common.registry.RecipeManagerContext; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeType; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.Function; import java.util.function.Predicate; @@ -80,12 +78,19 @@ public interface DisplayRegistry extends RecipeManagerContext { int displaySize(); /** - * Registers a recipe display + * Registers a display. * - * @param display the recipe display + * @param display the display */ void add(Display display); + /** + * Registers a display by the object provided, to be filled during {@link #tryFillDisplay(Object)}. + * + * @param object the object to be filled + */ + void add(Object object); + /** * Returns an unmodifiable map of displays visible to the player * @@ -172,6 +177,51 @@ public interface DisplayRegistry extends RecipeManagerContext { */ List getVisibilityPredicates(); + /** + * Registers a display filler, to be filled during {@link #tryFillDisplay(Object)}. + *

+ * Vanilla {@link Recipe} are by default filled, display filters + * can be used to automatically generate displaies for vanilla {@link Recipe}. + * + * @param typeClass the type of {@code T} + * @param filler the filler, taking a {@code T} and returning a {@code D} + * @param the type of object + * @param the type of display + */ + default , D extends Display> void registerRecipeFiller(Class typeClass, RecipeType recipeType, Function filler) { + registerRecipeFiller(typeClass, type -> Objects.equals(recipeType, type), filler); + } + + /** + * Registers a display filler, to be filled during {@link #tryFillDisplay(Object)}. + *

+ * Vanilla {@link Recipe} are by default filled, display filters + * can be used to automatically generate displaies for vanilla {@link Recipe}. + * + * @param typeClass the type of {@code T} + * @param filler the filler, taking a {@code T} and returning a {@code D} + * @param the type of object + * @param the type of display + */ + default , D extends Display> void registerRecipeFiller(Class typeClass, Predicate> recipeType, Function filler) { + registerRecipeFiller(typeClass, recipeType, Predicates.alwaysTrue(), filler); + } + + /** + * Registers a display filler, to be filled during {@link #tryFillDisplay(Object)}. + *

+ * Vanilla {@link Recipe} are by default filled, display filters + * can be used to automatically generate displaies for vanilla {@link Recipe}. + * + * @param typeClass the type of {@code T} + * @param filler the filler, taking a {@code T} and returning a {@code D} + * @param the type of object + * @param the type of display + */ + default , D extends Display> void registerRecipeFiller(Class typeClass, Predicate> recipeType, Predicate predicate, Function filler) { + registerFiller(typeClass, recipe -> recipeType.test((RecipeType) recipe.getType()) && ((Predicate) predicate).test(recipe), filler); + } + /** * Registers a display filler, to be filled during {@link #tryFillDisplay(Object)}. *

-- cgit