From c0ab2792b100457f42a63da8bae071feea8253a8 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 14 May 2020 01:33:54 +0800 Subject: Update to 20w20a Signed-off-by: shedaniel --- .../java/me/shedaniel/rei/api/ClientHelper.java | 104 ++++++++++++++++++--- 1 file changed, 93 insertions(+), 11 deletions(-) (limited to 'src/main/java/me/shedaniel/rei/api/ClientHelper.java') diff --git a/src/main/java/me/shedaniel/rei/api/ClientHelper.java b/src/main/java/me/shedaniel/rei/api/ClientHelper.java index 6d9fac19a..67c99be13 100644 --- a/src/main/java/me/shedaniel/rei/api/ClientHelper.java +++ b/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -23,15 +23,23 @@ package me.shedaniel.rei.api; +import me.shedaniel.rei.gui.RecipeScreen; import me.shedaniel.rei.impl.ClientHelperImpl; +import me.shedaniel.rei.utils.CollectionUtils; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Set; public interface ClientHelper { @@ -67,14 +75,10 @@ public interface ClientHelper { * * @param map the map of recipes */ + @ApiStatus.ScheduledForRemoval + @Deprecated void openRecipeViewingScreen(Map, List> map); - /** - * Registers REI's keybinds using Fabric API. - */ - @ApiStatus.Internal - void registerFabricKeyBinds(); - /** * Tries to cheat stack using either packets or commands. * @@ -93,8 +97,14 @@ public interface ClientHelper { * @param stack the stack to find recipe for * @return whether the stack has any recipes to show */ - boolean executeRecipeKeyBind(EntryStack stack); + @Deprecated + @ApiStatus.ScheduledForRemoval + default boolean executeRecipeKeyBind(EntryStack stack) { + return openView(ViewSearchBuilder.builder().addRecipesFor(stack).setOutputNotice(stack).fillPreferredOpenedCategory()); + } + @Deprecated + @ApiStatus.ScheduledForRemoval default boolean executeRecipeKeyBind(ItemStack stack) { return executeRecipeKeyBind(EntryStack.create(stack)); } @@ -105,8 +115,14 @@ public interface ClientHelper { * @param stack the stack to find usage for * @return whether the stack has any usages to show */ - boolean executeUsageKeyBind(EntryStack stack); + @Deprecated + @ApiStatus.ScheduledForRemoval + default boolean executeUsageKeyBind(EntryStack stack) { + return openView(ViewSearchBuilder.builder().addUsagesFor(stack).setInputNotice(stack).fillPreferredOpenedCategory()); + } + @Deprecated + @ApiStatus.ScheduledForRemoval default boolean executeUsageKeyBind(ItemStack stack) { return executeUsageKeyBind(EntryStack.create(stack)); } @@ -165,9 +181,75 @@ public interface ClientHelper { * * @return whether there are any recipes to show */ - boolean executeViewAllRecipesKeyBind(); + @Deprecated + @ApiStatus.ScheduledForRemoval + default boolean executeViewAllRecipesKeyBind() { + return openView(ViewSearchBuilder.builder().addAllCategories().fillPreferredOpenedCategory()); + } - boolean executeViewAllRecipesFromCategory(Identifier category); + @Deprecated + @ApiStatus.ScheduledForRemoval + default boolean executeViewAllRecipesFromCategory(Identifier category) { + return openView(ViewSearchBuilder.builder().addCategory(category).fillPreferredOpenedCategory()); + } - boolean executeViewAllRecipesFromCategories(List categories); + @Deprecated + @ApiStatus.ScheduledForRemoval + default boolean executeViewAllRecipesFromCategories(List categories) { + return openView(ViewSearchBuilder.builder().addCategories(categories).fillPreferredOpenedCategory()); + } + + boolean openView(ViewSearchBuilder builder); + + interface ViewSearchBuilder { + static ViewSearchBuilder builder() { + return new ClientHelperImpl.ViewSearchBuilder(); + } + + ViewSearchBuilder addCategory(Identifier category); + + ViewSearchBuilder addCategories(Collection categories); + + default ViewSearchBuilder addAllCategories() { + return addCategories(CollectionUtils.map(RecipeHelper.getInstance().getAllCategories(), RecipeCategory::getIdentifier)); + } + + @NotNull Set getCategories(); + + ViewSearchBuilder addRecipesFor(EntryStack stack); + + @NotNull List getRecipesFor(); + + ViewSearchBuilder addUsagesFor(EntryStack stack); + + @NotNull List getUsagesFor(); + + ViewSearchBuilder setPreferredOpenedCategory(@Nullable Identifier category); + + @Nullable + Identifier getPreferredOpenedCategory(); + + default ViewSearchBuilder fillPreferredOpenedCategory() { + if (getPreferredOpenedCategory() == null) { + Screen currentScreen = MinecraftClient.getInstance().currentScreen; + if (currentScreen instanceof RecipeScreen) { + setPreferredOpenedCategory(((RecipeScreen) currentScreen).getCurrentCategory()); + } + } + return this; + } + + ViewSearchBuilder setInputNotice(@Nullable EntryStack stack); + + @Nullable + EntryStack getInputNotice(); + + ViewSearchBuilder setOutputNotice(@Nullable EntryStack stack); + + @Nullable + EntryStack getOutputNotice(); + + @NotNull + Map, List> buildMap(); + } } -- cgit