From 12aa9dcbd806a6054acedcef053a89a98a4c25be Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 21 Feb 2021 22:55:57 +0800 Subject: a Signed-off-by: shedaniel --- .../me/shedaniel/rei/api/DisplayRegistryb.java | 214 +++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 api/src/main/java/me/shedaniel/rei/api/DisplayRegistryb.java (limited to 'api/src/main') diff --git a/api/src/main/java/me/shedaniel/rei/api/DisplayRegistryb.java b/api/src/main/java/me/shedaniel/rei/api/DisplayRegistryb.java new file mode 100644 index 000000000..7485f37c3 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/DisplayRegistryb.java @@ -0,0 +1,214 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api; + +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.api.registry.display.Display; +import me.shedaniel.rei.api.registry.display.DisplayCategory; +import me.shedaniel.rei.impl.Internals; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeManager; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.function.Predicate; + +@Environment(EnvType.CLIENT) +public interface DisplayRegistryb { + /** + * @return the instance of {@link DisplayRegistry} + */ + @NotNull + static DisplayRegistry getInstance() { + return Internals.getDisplayRegistry(); + } + + AutoTransferHandler registerAutoCraftingHandler(AutoTransferHandler handler); + + void registerFocusedStackProvider(FocusedStackProvider provider); + + @Nullable + @ApiStatus.Internal + EntryStack getScreenFocusedStack(Screen screen); + + List getSortedAutoCraftingHandler(); + + /** + * Gets all craftable items from materials. + * + * @param inventoryItems the materials + * @return the list of craftable entries + */ + List> findCraftableEntriesByItems(Iterable> inventoryItems); + + /** + * Gets all craftable items from materials. + * + * @param inventoryItems the materials + * @return the list of craftable entries + */ + default List> findCraftableEntriesByItems(List> inventoryItems) { + return findCraftableEntriesByItems((Iterable>) inventoryItems); + } + + Map, List> buildMapFor(ClientHelper.ViewSearchBuilder builder); + + /** + * Gets a map of recipes for an entry + * + * @param stack the stack to be crafted + * @return the map of recipes + */ + Map, List> getRecipesFor(EntryStack stack); + + /** + * Gets a map of usages for an entry + * + * @param stack the stack to be used + * @return the map of recipes + */ + Map, List> getUsagesFor(EntryStack stack); + + /** + * Gets the optional of the auto crafting button area from a category + * + * @param category the category of the display + * @return the optional of auto crafting button area + */ + Optional getAutoCraftButtonArea(DisplayCategory category); + + /** + * Registers a auto crafting button area + * + * @param category the category of the button area + * @param rectangle the button area + */ + void registerAutoCraftButtonArea(ResourceLocation category, ButtonAreaSupplier rectangle); + + /** + * Removes the auto crafting button + * + * @param category the category of the button + */ + default void removeAutoCraftButton(ResourceLocation category) { + registerAutoCraftButtonArea(category, bounds -> null); + } + + + List getAllRecipesFromCategory(DisplayCategory category); + + /** + * Registers a recipe visibility handler + * + * @param visibilityHandler the handler to be registered + */ + void registerRecipeVisibilityHandler(DisplayVisibilityHandler visibilityHandler); + + /** + * Unregisters a recipe visibility handler + * + * @param visibilityHandler the handler to be unregistered + */ + void unregisterRecipeVisibilityHandler(DisplayVisibilityHandler visibilityHandler); + + /** + * Gets an unmodifiable list of recipe visibility handlers + * + * @return the unmodifiable list of handlers + */ + List getDisplayVisibilityHandlers(); + + /** + * Checks if the display is invisible by querying the recipe visibility handlers + * + * @param display the display to be checked + * @return whether the display should be invisible + */ + boolean isDisplayNotVisible(Display display); + + /** + * Checks if the display is visible by querying the recipe visibility handlers + * + * @param display the display to be checked + * @return whether the display should be visible + */ + boolean isDisplayVisible(Display display); + + /** + * Registers a click area for a container screen. + * + * @param rectangle The click area that is offset to the container screen's top left corner. + * @param screenClass The class of the screen. + * @param categories The categories of result. + * @param The screen type to be registered to. + */ + default > void registerContainerClickArea(Rectangle rectangle, Class screenClass, ResourceLocation... categories) { + registerContainerClickArea(screen -> rectangle, screenClass, categories); + } + + /** + * Registers a click area for a container screen. + * + * @param rectangleSupplier The click area supplier that is offset to the container screen's top left corner. + * @param screenClass The class of the screen. + * @param categories The categories of result. + * @param The screen type to be registered to. + */ + > void registerContainerClickArea(ScreenClickAreaProvider rectangleSupplier, Class screenClass, ResourceLocation... categories); + + /** + * Registers a click area for a screen. + * + * @param rectangleSupplier The click area supplier that is offset to the window's top left corner. + * @param screenClass The class of the screen. + * @param categories The categories of result. + * @param The screen type to be registered to. + */ + void registerClickArea(ScreenClickAreaProvider rectangleSupplier, Class screenClass, ResourceLocation... categories); + + /** + * Registers a click area handler for a screen. A handler allows more specific implementation of click areas. + * + * @param screenClass The class of the screen. + * @param handler The click area handler that is offset to the window's top left corner. + * @param The screen type to be registered to. + * @see #registerClickArea(ScreenClickAreaProvider, Class, ResourceLocation...) for a simpler way to handle areas without custom categories. + */ + void registerClickArea(Class screenClass, ClickAreaHandler handler); + + @ApiStatus.Internal + boolean arePluginsLoading(); +} + -- cgit