From 5296049d81a7d201eeb1f535b4223bd0ba21febb Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 1 Sep 2023 17:37:03 +0800 Subject: Update to 23w35a --- .../rei/api/client/registry/display/DisplayRegistry.java | 13 +++++++++---- .../rei/api/common/registry/RecipeManagerContext.java | 11 +++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'api/src/main/java/me/shedaniel') 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 fd34e4e84..5a3fb9d30 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 @@ -35,6 +35,7 @@ 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.RecipeHolder; import net.minecraft.world.item.crafting.RecipeType; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -219,7 +220,7 @@ public interface DisplayRegistry extends RecipeManagerContext { * @param the type of object * @param the type of display */ - default , D extends Display> void registerRecipeFiller(Class typeClass, RecipeType recipeType, Function filler) { + default , D extends Display> void registerRecipeFiller(Class typeClass, RecipeType recipeType, Function, @Nullable D> filler) { registerRecipeFiller(typeClass, type -> Objects.equals(recipeType, type), filler); } @@ -234,7 +235,7 @@ public interface DisplayRegistry extends RecipeManagerContext { * @param the type of object * @param the type of display */ - default , D extends Display> void registerRecipeFiller(Class typeClass, Predicate> recipeType, Function filler) { + default , D extends Display> void registerRecipeFiller(Class typeClass, Predicate> recipeType, Function, @Nullable D> filler) { registerRecipeFiller(typeClass, recipeType, Predicates.alwaysTrue(), filler); } @@ -249,8 +250,12 @@ public interface DisplayRegistry extends RecipeManagerContext { * @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); + default , D extends Display> void registerRecipeFiller(Class typeClass, Predicate> recipeType, Predicate> predicate, Function, @Nullable D> filler) { + registerFiller(RecipeHolder.class, recipe -> { + return typeClass.isInstance(recipe.value()) + && recipeType.test((RecipeType) recipe.value().getType()) + && ((Predicate>) predicate).test(recipe); + }, filler); } /** diff --git a/api/src/main/java/me/shedaniel/rei/api/common/registry/RecipeManagerContext.java b/api/src/main/java/me/shedaniel/rei/api/common/registry/RecipeManagerContext.java index f37e69473..878db7b98 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/registry/RecipeManagerContext.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/registry/RecipeManagerContext.java @@ -28,8 +28,9 @@ import me.shedaniel.rei.api.common.plugins.REIPlugin; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.RecipeManager; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -44,7 +45,7 @@ public interface RecipeManagerContext

> extends Reloadable /** * @return a list of sorted recipes */ - List> getAllSortedRecipes(); + List> getAllSortedRecipes(); /** * Returns the vanilla recipe manager @@ -53,14 +54,16 @@ public interface RecipeManagerContext

> extends Reloadable */ RecipeManager getRecipeManager(); - default Recipe byId(CompoundTag tag, String key) { + @Nullable + default RecipeHolder byId(CompoundTag tag, String key) { if (tag.contains(key, Tag.TAG_STRING)) { return getRecipeManager().byKey(new ResourceLocation(tag.getString(key))).orElse(null); } return null; } - default Recipe byId(ResourceLocation location) { + @Nullable + default RecipeHolder byId(ResourceLocation location) { return getRecipeManager().byKey(location).orElse(null); } } -- cgit