aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-06-20 01:16:36 +0800
committershedaniel <daniel@shedaniel.me>2021-06-20 01:16:36 +0800
commit0239bf2fb623863164da37df7f059d29805ed1b9 (patch)
treeaa5074669dc81cf994c2fdccd5d7ab6622fd8af3 /api
parent3d90cdd1204b6b6a2c57b121cdf82de2448bb951 (diff)
downloadRoughlyEnoughItems-0239bf2fb623863164da37df7f059d29805ed1b9.tar.gz
RoughlyEnoughItems-0239bf2fb623863164da37df7f059d29805ed1b9.tar.bz2
RoughlyEnoughItems-0239bf2fb623863164da37df7f059d29805ed1b9.zip
Add registerRecipeFiller for checking recipe types
Diffstat (limited to 'api')
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java62
1 files changed, 56 insertions, 6 deletions
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,13 +78,20 @@ public interface DisplayRegistry extends RecipeManagerContext<REIClientPlugin> {
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
*
* @return an unmodifiable map of displays
@@ -183,6 +188,51 @@ public interface DisplayRegistry extends RecipeManagerContext<REIClientPlugin> {
* @param <T> the type of object
* @param <D> the type of display
*/
+ default <T extends Recipe<?>, D extends Display> void registerRecipeFiller(Class<T> typeClass, RecipeType<? super T> recipeType, Function<? extends T, D> filler) {
+ registerRecipeFiller(typeClass, type -> Objects.equals(recipeType, type), filler);
+ }
+
+ /**
+ * Registers a display filler, to be filled during {@link #tryFillDisplay(Object)}.
+ * <p>
+ * 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 <T> the type of object
+ * @param <D> the type of display
+ */
+ default <T extends Recipe<?>, D extends Display> void registerRecipeFiller(Class<T> typeClass, Predicate<RecipeType<? super T>> recipeType, Function<? extends T, D> filler) {
+ registerRecipeFiller(typeClass, recipeType, Predicates.alwaysTrue(), filler);
+ }
+
+ /**
+ * Registers a display filler, to be filled during {@link #tryFillDisplay(Object)}.
+ * <p>
+ * 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 <T> the type of object
+ * @param <D> the type of display
+ */
+ default <T extends Recipe<?>, D extends Display> void registerRecipeFiller(Class<T> typeClass, Predicate<RecipeType<? super T>> recipeType, Predicate<? extends T> predicate, Function<? extends T, D> filler) {
+ registerFiller(typeClass, recipe -> recipeType.test((RecipeType<? super T>) recipe.getType()) && ((Predicate<T>) predicate).test(recipe), filler);
+ }
+
+ /**
+ * Registers a display filler, to be filled during {@link #tryFillDisplay(Object)}.
+ * <p>
+ * 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 <T> the type of object
+ * @param <D> the type of display
+ */
default <T, D extends Display> void registerFiller(Class<T> typeClass, Function<? extends T, D> filler) {
registerFiller(typeClass, Predicates.alwaysTrue(), filler);
}