diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-05-14 01:33:54 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-05-14 01:33:54 +0800 |
| commit | c0ab2792b100457f42a63da8bae071feea8253a8 (patch) | |
| tree | 761fcc6d686dd103b4ff33f91b86582411ae4480 /src/main/java/me/shedaniel/rei/api/ClientHelper.java | |
| parent | d22b619c0d9870df72fb10c153ead3801bf1a971 (diff) | |
| download | RoughlyEnoughItems-c0ab2792b100457f42a63da8bae071feea8253a8.tar.gz RoughlyEnoughItems-c0ab2792b100457f42a63da8bae071feea8253a8.tar.bz2 RoughlyEnoughItems-c0ab2792b100457f42a63da8bae071feea8253a8.zip | |
Update to 20w20a
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'src/main/java/me/shedaniel/rei/api/ClientHelper.java')
| -rw-r--r-- | src/main/java/me/shedaniel/rei/api/ClientHelper.java | 104 |
1 files changed, 93 insertions, 11 deletions
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,15 +75,11 @@ public interface ClientHelper { * * @param map the map of recipes */ + @ApiStatus.ScheduledForRemoval + @Deprecated void openRecipeViewingScreen(Map<RecipeCategory<?>, List<RecipeDisplay>> map); /** - * Registers REI's keybinds using Fabric API. - */ - @ApiStatus.Internal - void registerFabricKeyBinds(); - - /** * Tries to cheat stack using either packets or commands. * * @param stack the stack to cheat in @@ -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<Identifier> categories); + @Deprecated + @ApiStatus.ScheduledForRemoval + default boolean executeViewAllRecipesFromCategories(List<Identifier> 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<Identifier> categories); + + default ViewSearchBuilder addAllCategories() { + return addCategories(CollectionUtils.map(RecipeHelper.getInstance().getAllCategories(), RecipeCategory::getIdentifier)); + } + + @NotNull Set<Identifier> getCategories(); + + ViewSearchBuilder addRecipesFor(EntryStack stack); + + @NotNull List<EntryStack> getRecipesFor(); + + ViewSearchBuilder addUsagesFor(EntryStack stack); + + @NotNull List<EntryStack> 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<RecipeCategory<?>, List<RecipeDisplay>> buildMap(); + } } |
