From a56baa875630ffac06e421a7389854b5301ed7f0 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 21 Feb 2021 22:33:45 +0800 Subject: More Signed-off-by: shedaniel --- .../me/shedaniel/rei/api/ButtonAreaSupplier.java | 4 + .../java/me/shedaniel/rei/api/ClientHelper.java | 4 +- .../shedaniel/rei/api/DisplayBoundsRegistry.java | 99 -------- .../java/me/shedaniel/rei/api/DisplayRegistry.java | 92 +++++++ .../java/me/shedaniel/rei/api/EntryRegistry.java | 126 ---------- .../java/me/shedaniel/rei/api/ExclusionZones.java | 61 ----- .../me/shedaniel/rei/api/LiveDisplayGenerator.java | 45 ++++ .../me/shedaniel/rei/api/LiveRecipeGenerator.java | 52 ---- .../java/me/shedaniel/rei/api/OverlayDecider.java | 69 ------ .../main/java/me/shedaniel/rei/api/REIPlugin.java | 49 ---- .../java/me/shedaniel/rei/api/REIPluginEntry.java | 49 ++++ .../java/me/shedaniel/rei/api/RecipeRegistry.java | 266 --------------------- .../me/shedaniel/rei/api/gui/AbstractRenderer.java | 39 +++ .../me/shedaniel/rei/api/gui/DisplayRenderer.java | 1 - .../me/shedaniel/rei/api/gui/widgets/Widget.java | 9 +- .../me/shedaniel/rei/api/gui/widgets/Widgets.java | 54 ++++- .../rei/api/ingredient/entry/AbstractRenderer.java | 39 --- .../me/shedaniel/rei/api/plugins/REIPlugin.java | 114 +++++++++ .../me/shedaniel/rei/api/plugins/REIPluginV0.java | 97 -------- .../rei/api/registry/CategoryRegistry.java | 92 +++++-- .../shedaniel/rei/api/registry/DisplayerQuery.java | 4 + .../shedaniel/rei/api/registry/EntryRegistry.java | 150 ++++++++++++ .../shedaniel/rei/api/registry/PluginHandler.java | 4 +- .../rei/api/registry/RecipeManagerContext.java | 20 ++ .../rei/api/registry/display/Display.java | 10 +- .../rei/api/registry/display/DisplayCategory.java | 52 ++-- .../registry/screens/DisplayBoundsProvider.java | 23 ++ .../rei/api/registry/screens/ExclusionZones.java | 56 +++++ .../rei/api/registry/screens/OverlayDecider.java | 75 ++++++ .../rei/api/registry/screens/ScreenRegistry.java | 71 ++++++ .../me/shedaniel/rei/api/server/ContainerInfo.java | 4 +- .../me/shedaniel/rei/api/util/CollectionUtils.java | 39 +++ .../me/shedaniel/rei/api/util/Identifiable.java | 5 + .../main/java/me/shedaniel/rei/impl/Internals.java | 33 +-- 34 files changed, 957 insertions(+), 950 deletions(-) delete mode 100644 api/src/main/java/me/shedaniel/rei/api/DisplayBoundsRegistry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/DisplayRegistry.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/EntryRegistry.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ExclusionZones.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/LiveDisplayGenerator.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/LiveRecipeGenerator.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/OverlayDecider.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/REIPlugin.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/RecipeRegistry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/gui/AbstractRenderer.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/AbstractRenderer.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/plugins/REIPlugin.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/DisplayerQuery.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/EntryRegistry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/RecipeManagerContext.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/screens/DisplayBoundsProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/screens/ExclusionZones.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/screens/OverlayDecider.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/screens/ScreenRegistry.java (limited to 'api/src/main/java/me') diff --git a/api/src/main/java/me/shedaniel/rei/api/ButtonAreaSupplier.java b/api/src/main/java/me/shedaniel/rei/api/ButtonAreaSupplier.java index 64e4b27e8..65116400e 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ButtonAreaSupplier.java +++ b/api/src/main/java/me/shedaniel/rei/api/ButtonAreaSupplier.java @@ -28,7 +28,11 @@ import me.shedaniel.math.Rectangle; /** * The supplier for the + button area. */ +@FunctionalInterface public interface ButtonAreaSupplier { + static ButtonAreaSupplier defaultArea() { + return bounds -> new Rectangle(bounds.getMaxX() - 16, bounds.getMaxY() - 16, 10, 10); + } /** * Declares the button bounds diff --git a/api/src/main/java/me/shedaniel/rei/api/ClientHelper.java b/api/src/main/java/me/shedaniel/rei/api/ClientHelper.java index c1ff48e21..00cbb338b 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ClientHelper.java +++ b/api/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -24,10 +24,12 @@ package me.shedaniel.rei.api; import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.api.registry.CategoryRegistry; import me.shedaniel.rei.api.registry.display.Display; import me.shedaniel.rei.api.registry.display.DisplayCategory; import me.shedaniel.rei.api.util.CollectionUtils; import me.shedaniel.rei.api.util.FormattingUtils; +import me.shedaniel.rei.api.util.Identifiable; import me.shedaniel.rei.impl.Internals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -183,7 +185,7 @@ public interface ClientHelper { ViewSearchBuilder addCategories(Collection categories); default ViewSearchBuilder addAllCategories() { - return addCategories(CollectionUtils.map(RecipeRegistry.getInstance().getAllCategories(), DisplayCategory::getIdentifier)); + return addCategories(CollectionUtils.map(CategoryRegistry.getInstance(), Identifiable::getIdentifier)); } @NotNull Set getCategories(); diff --git a/api/src/main/java/me/shedaniel/rei/api/DisplayBoundsRegistry.java b/api/src/main/java/me/shedaniel/rei/api/DisplayBoundsRegistry.java deleted file mode 100644 index 14ea6d244..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/DisplayBoundsRegistry.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.gui.config.DisplayPanelLocation; -import me.shedaniel.rei.impl.Internals; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -@Environment(EnvType.CLIENT) -public interface DisplayBoundsRegistry { - - /** - * @return the instance of {@link DisplayBoundsRegistry} - */ - @NotNull - static DisplayBoundsRegistry getInstance() { - return Internals.getDisplayHelper(); - } - - List getSortedOverlayDeciders(Class screenClass); - - /** - * Gets all registered overlay deciders - * - * @return the list of registered overlay deciders - */ - List getAllOverlayDeciders(); - - /** - * Registers a bounds decider - * - * @param decider the decider to register - */ - void registerHandler(OverlayDecider decider); - - default void registerProvider(DisplayBoundsProvider provider) { - registerHandler(provider); - } - - /** - * Gets the left bounds of the overlay - * - * @param screen the current screen - * @return the left bounds - */ - Rectangle getOverlayBounds(DisplayPanelLocation location, T screen); - - @ApiStatus.Experimental - void resetCache(); - - ExclusionZones exclusionZones(); - - interface DisplayBoundsProvider extends OverlayDecider { - /** - * @param screen the screen - * @return the boundary of the base container panel. - */ - Rectangle getScreenBounds(T screen); - - /** - * Gets the base supported class for the bounds handler - * - * @return the base class - */ - Class getBaseSupportedClass(); - - @Override - default boolean isHandingScreen(Class screen) { - return getBaseSupportedClass().isAssignableFrom(screen); - } - } -} diff --git a/api/src/main/java/me/shedaniel/rei/api/DisplayRegistry.java b/api/src/main/java/me/shedaniel/rei/api/DisplayRegistry.java new file mode 100644 index 000000000..59879c891 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/DisplayRegistry.java @@ -0,0 +1,92 @@ +/* + * 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.rei.api.registry.RecipeManagerContext; +import me.shedaniel.rei.api.registry.Reloadable; +import me.shedaniel.rei.api.registry.display.Display; +import me.shedaniel.rei.impl.Internals; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.crafting.Recipe; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.function.Predicate; + +@Environment(EnvType.CLIENT) +public interface DisplayRegistry extends RecipeManagerContext, Reloadable { + /** + * @return the instance of {@link DisplayRegistry} + */ + @NotNull + static DisplayRegistry getInstance() { + return Internals.getDisplayRegistry(); + } + + /** + * Gets the total display count registered + * + * @return the recipe count + */ + int getDisplayCount(); + + /** + * Registers a recipe display. + * + * @param display the recipe display + */ + void registerDisplay(Display display); + + /** + * Gets the map of all recipes visible to the player + * + * @return the map of recipes + */ + Map> getAllRecipes(); + + /** + * Registers a live display generator. + * + * @param categoryId the identifier of the category + * @param generator the generator to register + */ + void registerLiveDisplayGenerator(ResourceLocation categoryId, LiveDisplayGenerator generator); + + /** + * Registers a display visibility handler. + * + * @param visibilityHandler the handler to be registered + */ + void registerRecipeVisibilityHandler(DisplayVisibilityHandler visibilityHandler); + + default > void registerRecipes(ResourceLocation category, Class recipeClass, Function mappingFunction) { + registerRecipes(category, recipe -> recipeClass.isAssignableFrom(recipe.getClass()), mappingFunction); + } + + > void registerRecipes(ResourceLocation category, Predicate recipeFilter, Function mappingFunction); +} diff --git a/api/src/main/java/me/shedaniel/rei/api/EntryRegistry.java b/api/src/main/java/me/shedaniel/rei/api/EntryRegistry.java deleted file mode 100644 index bdf2ef97b..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/EntryRegistry.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.impl.Internals; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.function.Predicate; -import java.util.stream.Stream; - -@Environment(EnvType.CLIENT) -public interface EntryRegistry { - - /** - * @return the instance of {@link me.shedaniel.rei.api.EntryRegistry} - */ - @NotNull - static EntryRegistry getInstance() { - return Internals.getEntryRegistry(); - } - - @NotNull - Stream> getEntryStacks(); - - @NotNull - List> getPreFilteredList(); - - @ApiStatus.Experimental - void refilter(); - - @NotNull - List appendStacksForItem(@NotNull Item item); - - /** - * Gets all possible stacks from an item - * - * @param item the item to find - * @return the array of possible stacks - */ - @NotNull - ItemStack[] getAllStacksFromItem(@NotNull Item item); - - default void registerEntry(@NotNull EntryStack stack) { - registerEntryAfter(null, stack); - } - - /** - * Registers an new stack to the entry list - * - * @param afterEntry the stack to put after - * @param stack the stack to register - */ - void registerEntryAfter(@Nullable EntryStack afterEntry, @NotNull EntryStack stack); - - /** - * Registers multiple stacks to the item list - * - * @param afterStack the stack to put after - * @param stacks the stacks to register - */ - default void registerEntriesAfter(@Nullable EntryStack afterStack, @NotNull EntryStack... stacks) { - registerEntriesAfter(afterStack, Arrays.asList(stacks)); - } - - /** - * Registers multiple stacks to the item list - * - * @param afterStack the stack to put after - * @param stacks the stacks to register - */ - void registerEntriesAfter(@Nullable EntryStack afterStack, @NotNull Collection<@NotNull ? extends EntryStack> stacks); - - /** - * Registers multiple stacks to the item list - * - * @param stacks the stacks to register - */ - default void registerEntries(@NotNull EntryStack... stacks) { - registerEntriesAfter(null, stacks); - } - - /** - * Checks if a stack is already registered - * - * @param stack the stack to check - * @return whether the stack has been registered - */ - boolean alreadyContain(EntryStack stack); - - @ApiStatus.Experimental - void removeEntry(EntryStack stack); - - @ApiStatus.Experimental - void removeEntryIf(Predicate> stackPredicate); -} diff --git a/api/src/main/java/me/shedaniel/rei/api/ExclusionZones.java b/api/src/main/java/me/shedaniel/rei/api/ExclusionZones.java deleted file mode 100644 index 244437991..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ExclusionZones.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -import java.util.List; -import java.util.function.Supplier; - -@Environment(EnvType.CLIENT) -public interface ExclusionZones extends OverlayDecider { - - static ExclusionZones getInstance() { - return DisplayBoundsRegistry.getInstance().exclusionZones(); - } - - /** - * Gets the exclusion zones by the screen class - * - * @param currentScreenClass the current screen class - * @return the list of exclusion zones - */ - default List getExclusionZones(Class currentScreenClass) { - return getExclusionZones(currentScreenClass, false); - } - - List getExclusionZones(Class currentScreenClass, boolean sort); - - int getZonesCount(); - - /** - * Register an exclusion zone - * - * @param screenClass the screen - * @param supplier the exclusion zone supplier, returns the list of exclusion zones - */ - void register(Class screenClass, Supplier> supplier); -} diff --git a/api/src/main/java/me/shedaniel/rei/api/LiveDisplayGenerator.java b/api/src/main/java/me/shedaniel/rei/api/LiveDisplayGenerator.java new file mode 100644 index 000000000..ca5098a8c --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/LiveDisplayGenerator.java @@ -0,0 +1,45 @@ +/* + * 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.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.api.registry.display.Display; +import net.minecraft.resources.ResourceLocation; + +import java.util.List; +import java.util.Optional; + +public interface LiveDisplayGenerator { + default Optional> getRecipeFor(EntryStack entry) { + return Optional.empty(); + } + + default Optional> getUsageFor(EntryStack entry) { + return Optional.empty(); + } + + default Optional> getDisplaysGenerated(ClientHelper.ViewSearchBuilder builder) { + return Optional.empty(); + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/LiveRecipeGenerator.java b/api/src/main/java/me/shedaniel/rei/api/LiveRecipeGenerator.java deleted file mode 100644 index 8549b95b7..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/LiveRecipeGenerator.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.registry.display.Display; -import net.minecraft.resources.ResourceLocation; - -import java.util.List; -import java.util.Optional; - -public interface LiveRecipeGenerator { - - /** - * @return the identifier of the category the recipes goes to. - */ - ResourceLocation getCategoryIdentifier(); - - default Optional> getRecipeFor(EntryStack entry) { - return Optional.empty(); - } - - default Optional> getUsageFor(EntryStack entry) { - return Optional.empty(); - } - - default Optional> getDisplaysGenerated(ClientHelper.ViewSearchBuilder builder) { - return Optional.empty(); - } - -} diff --git a/api/src/main/java/me/shedaniel/rei/api/OverlayDecider.java b/api/src/main/java/me/shedaniel/rei/api/OverlayDecider.java deleted file mode 100644 index 84840d523..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/OverlayDecider.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.gui.config.DisplayPanelLocation; -import net.minecraft.world.InteractionResult; - -import static net.minecraft.world.InteractionResult.PASS; - -public interface OverlayDecider { - boolean isHandingScreen(Class screen); - - default InteractionResult shouldScreenBeOverlaid(Class screen) { - return InteractionResult.PASS; - } - - /** - * Gets the priority of the handler, the higher it is, the earlier it is called. - * - * @return the priority in float - */ - default float getPriority() { - return 0f; - } - - /** - * Checks if REI should recalculate the overlay bounds - * - * @param location the location of the display panel - * @param rectangle the current overlay bounds - * @return whether REI should recalculate the overlay bounds - */ - default boolean shouldRecalculateArea(DisplayPanelLocation location, Rectangle rectangle) { - return false; - } - - /** - * Checks if mouse is inside the overlay - * - * @param mouseX mouse's x coordinates - * @param mouseY mouse's y coordinates - * @return whether mouse is inside the overlay - */ - default InteractionResult isInZone(double mouseX, double mouseY) { - return PASS; - } -} diff --git a/api/src/main/java/me/shedaniel/rei/api/REIPlugin.java b/api/src/main/java/me/shedaniel/rei/api/REIPlugin.java deleted file mode 100644 index a7249f647..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/REIPlugin.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 org.jetbrains.annotations.NotNull; - -/** - * Get base class of a REI plugin. - */ -public interface REIPlugin extends Comparable { - /** - * @return the priority of the plugin, the smaller the number, the earlier it is called. - */ - default int getPriority() { - return 0; - } - - default String getPluginName() { - Class self = getClass(); - String simpleName = self.getSimpleName(); - return simpleName == null ? self.getName() : simpleName; - } - - @Override - default int compareTo(@NotNull REIPlugin o) { - return Double.compare(getPriority(), o.getPriority()); - } -} diff --git a/api/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java b/api/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java new file mode 100644 index 000000000..dc9f05c24 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java @@ -0,0 +1,49 @@ +/* + * 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 org.jetbrains.annotations.NotNull; + +/** + * Get base class of a REI plugin. + */ +public interface REIPluginEntry extends Comparable { + /** + * @return the priority of the plugin, the smaller the number, the earlier it is called. + */ + default int getPriority() { + return 0; + } + + default String getPluginName() { + Class self = getClass(); + String simpleName = self.getSimpleName(); + return simpleName == null ? self.getName() : simpleName; + } + + @Override + default int compareTo(@NotNull REIPluginEntry o) { + return Double.compare(getPriority(), o.getPriority()); + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/RecipeRegistry.java b/api/src/main/java/me/shedaniel/rei/api/RecipeRegistry.java deleted file mode 100644 index 50bcd8016..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/RecipeRegistry.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * 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 RecipeRegistry { - - /** - * @return the instance of {@link RecipeRegistry} - */ - @NotNull - static RecipeRegistry getInstance() { - return Internals.getRecipeHelper(); - } - - AutoTransferHandler registerAutoCraftingHandler(AutoTransferHandler handler); - - void registerFocusedStackProvider(FocusedStackProvider provider); - - @Nullable - @ApiStatus.Internal - EntryStack getScreenFocusedStack(Screen screen); - - List getSortedAutoCraftingHandler(); - - /** - * Gets the total recipe count registered - * - * @return the recipe count - */ - int getRecipeCount(); - - /** - * @return a list of sorted recipes - */ - List> getAllSortedRecipes(); - - /** - * 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); - } - - /** - * Registers a recipe display. - * - * @param display the recipe display - */ - void registerDisplay(Display display); - - 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); - - DisplayCategory getCategory(ResourceLocation identifier); - - /** - * Gets the vanilla recipe manager - * - * @return the recipe manager - */ - RecipeManager getRecipeManager(); - - /** - * Gets all registered categories - * - * @return the list of categories - */ - List> getAllCategories(); - - /** - * 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); - } - - /** - * Gets the map of all recipes visible to the player - * - * @return the map of recipes - */ - Map, List> getAllRecipes(); - - Map, List> getAllRecipesNoHandlers(); - - 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(); - - boolean isDisplayNotVisible(Display display); - - /** - * Checks if the display is visible by asking recipe visibility handlers - * - * @param display the display to be checked - * @return whether the display should be visible - */ - boolean isDisplayVisible(Display display); - - /** - * Registers a live recipe generator. - * - * @param liveRecipeGenerator the generator to register - * @apiNote Still work in progress - */ - void registerLiveRecipeGenerator(LiveRecipeGenerator liveRecipeGenerator); - - /** - * 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); - - default > void registerRecipes(ResourceLocation category, Class recipeClass, Function mappingFunction) { - registerRecipes(category, recipe -> recipeClass.isAssignableFrom(recipe.getClass()), mappingFunction); - } - - > void registerRecipes(ResourceLocation category, Predicate> recipeFilter, Function mappingFunction); - - @ApiStatus.Internal - boolean arePluginsLoading(); -} - diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/AbstractRenderer.java b/api/src/main/java/me/shedaniel/rei/api/gui/AbstractRenderer.java new file mode 100644 index 000000000..b4ffb75c5 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/gui/AbstractRenderer.java @@ -0,0 +1,39 @@ +/* + * 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.gui; + +import me.shedaniel.rei.api.gui.Renderer; +import net.minecraft.client.gui.GuiComponent; + +public abstract class AbstractRenderer extends GuiComponent implements Renderer { + @Override + public int getZ() { + return getBlitOffset(); + } + + @Override + public void setZ(int z) { + setBlitOffset(z); + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/DisplayRenderer.java b/api/src/main/java/me/shedaniel/rei/api/gui/DisplayRenderer.java index 281d79a18..1b177e84b 100644 --- a/api/src/main/java/me/shedaniel/rei/api/gui/DisplayRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/gui/DisplayRenderer.java @@ -24,7 +24,6 @@ package me.shedaniel.rei.api.gui; import me.shedaniel.math.Point; -import me.shedaniel.rei.api.ingredient.entry.AbstractRenderer; import me.shedaniel.rei.api.gui.widgets.Tooltip; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widget.java b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widget.java index ab55936a3..abe4454ae 100644 --- a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widget.java +++ b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widget.java @@ -23,7 +23,10 @@ package me.shedaniel.rei.api.gui.widgets; +import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.gui.Renderer; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.components.events.AbstractContainerEventHandler; @@ -33,7 +36,7 @@ import net.minecraft.client.gui.components.events.AbstractContainerEventHandler; * * @see WidgetWithBounds for a widget with bounds */ -public abstract class Widget extends AbstractContainerEventHandler implements net.minecraft.client.gui.components.Widget { +public abstract class Widget extends AbstractContainerEventHandler implements net.minecraft.client.gui.components.Widget, Renderer { /** * The Minecraft Client instance @@ -71,4 +74,8 @@ public abstract class Widget extends AbstractContainerEventHandler implements ne return containsMouse(double_1, double_2); } + @Override + public void render(PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { + render(matrices, mouseX, mouseY, delta); + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widgets.java b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widgets.java index 1bacf4d68..614c5f4ec 100644 --- a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widgets.java +++ b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widgets.java @@ -29,6 +29,7 @@ import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.ConfigObject; import me.shedaniel.rei.api.gui.DrawableConsumer; +import me.shedaniel.rei.api.gui.Renderer; import me.shedaniel.rei.impl.Internals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -52,12 +53,15 @@ public final class Widgets { private Widgets() {} @NotNull - public static Widget createDrawableWidget(@NotNull DrawableConsumer drawable) { + public static Widget createDrawableWidget(DrawableConsumer drawable) { return Internals.getWidgetsProvider().createDrawableWidget(drawable); } @NotNull - public static Widget wrapVanillaWidget(@NotNull GuiEventListener element) { + public static Widget wrapVanillaWidget(GuiEventListener element) { + Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> { + + }); return new VanillaWrappedWidget(element); } @@ -82,6 +86,38 @@ public final class Widgets { } } + @NotNull + public static WidgetWithBounds wrapRenderer(Rectangle bounds, Renderer renderer) { + return new RendererWrappedWidget(renderer); + } + + private static class RendererWrappedWidget extends WidgetWithBounds { + private Renderer renderer; + private Rectangle bounds; + + public RendererWrappedWidget(Renderer renderer) { + this.renderer = Objects.requireNonNull(renderer); + } + + @Override + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { + renderer.render(matrices, getBounds(), mouseX, mouseY, delta); + } + + @Override + public List children() { + if (renderer instanceof GuiEventListener) + return Collections.singletonList((GuiEventListener) renderer); + return Collections.emptyList(); + } + + @NotNull + @Override + public Rectangle getBounds() { + return bounds; + } + } + @NotNull public static Widget createTexturedWidget(@NotNull ResourceLocation identifier, @NotNull Rectangle bounds) { return createTexturedWidget(identifier, bounds, 0, 0); @@ -159,18 +195,20 @@ public final class Widgets { @NotNull public static Panel createRecipeBase(@NotNull Rectangle rectangle) { - return Internals.getWidgetsProvider().createPanelWidget(rectangle).yTextureOffset(ConfigObject.getInstance().getRecipeBorderType().getYOffset()).rendering(Widgets::shouldRecipeBaseRender); - } - - @NotNull - public static Panel createCategoryBase(@NotNull Rectangle rectangle) { - return Internals.getWidgetsProvider().createPanelWidget(rectangle).rendering(Widgets::shouldSlotBaseRender); + return Internals.getWidgetsProvider().createPanelWidget(rectangle) + .yTextureOffset(ConfigObject.getInstance().getRecipeBorderType().getYOffset()) + .rendering(Widgets::shouldRecipeBaseRender); } private static boolean shouldRecipeBaseRender(@NotNull Panel panel) { return ConfigObject.getInstance().getRecipeBorderType().isRendering() && Internals.getWidgetsProvider().isRenderingPanel(panel); } + @NotNull + public static Panel createCategoryBase(@NotNull Rectangle rectangle) { + return Internals.getWidgetsProvider().createPanelWidget(rectangle); + } + @NotNull public static Panel createRecipeBase(@NotNull Rectangle rectangle, int color) { return createRecipeBase(rectangle).color(color); diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/AbstractRenderer.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/AbstractRenderer.java deleted file mode 100644 index 75a52d696..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/AbstractRenderer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.ingredient.entry; - -import me.shedaniel.rei.api.gui.Renderer; -import net.minecraft.client.gui.GuiComponent; - -public abstract class AbstractRenderer extends GuiComponent implements Renderer { - @Override - public int getZ() { - return getBlitOffset(); - } - - @Override - public void setZ(int z) { - setBlitOffset(z); - } -} diff --git a/api/src/main/java/me/shedaniel/rei/api/plugins/REIPlugin.java b/api/src/main/java/me/shedaniel/rei/api/plugins/REIPlugin.java new file mode 100644 index 000000000..1ad633834 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/plugins/REIPlugin.java @@ -0,0 +1,114 @@ +/* + * 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.plugins; + +import me.shedaniel.rei.api.registry.screens.ScreenRegistry; +import me.shedaniel.rei.api.DisplayRegistry; +import me.shedaniel.rei.api.registry.EntryRegistry; +import me.shedaniel.rei.api.ingredient.entry.EntryTypeRegistry; +import me.shedaniel.rei.api.registry.CategoryRegistry; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +@ApiStatus.OverrideOnly +public interface REIPlugin extends Comparable { + /** + * @return the priority of the plugin, the smaller the number, the earlier it is called. + */ + default int getPriority() { + return 0; + } + + default String getPluginName() { + Class self = getClass(); + String simpleName = self.getSimpleName(); + return simpleName == null ? self.getName() : simpleName; + } + + @Override + default int compareTo(@NotNull REIPlugin o) { + return Double.compare(getPriority(), o.getPriority()); + } + + /** + * Registers the types of entries + */ + @ApiStatus.OverrideOnly + default void registerEntryTypes(EntryTypeRegistry registry) { + + } + + /** + * Registers entries on the entry panel. + * + * @param registry the entry registry + */ + @ApiStatus.OverrideOnly + default void registerEntries(EntryRegistry registry) { + } + + /** + * Registers categories + * + * @param registry the category registry + */ + @ApiStatus.OverrideOnly + default void registerCategories(CategoryRegistry registry) { + } + + /** + * Registers displays for categories + * + * @param registry the helper class + */ + @ApiStatus.OverrideOnly + default void registerDisplays(DisplayRegistry registry) { + } + + /** + * Registers bounds handlers + * + * @param registry the helper class + */ + @ApiStatus.OverrideOnly + default void registerScreens(ScreenRegistry registry) { + } + + /** + * Register other stuff + * + * @param registry the helper class + */ + @ApiStatus.OverrideOnly + default void registerOthers(DisplayRegistry registry) { + } + + @ApiStatus.OverrideOnly + default void preRegister() { + } + + @ApiStatus.OverrideOnly + default void postRegister() { + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java b/api/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java deleted file mode 100644 index 143490b37..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.plugins; - -import me.shedaniel.rei.api.DisplayBoundsRegistry; -import me.shedaniel.rei.api.EntryRegistry; -import me.shedaniel.rei.api.REIPlugin; -import me.shedaniel.rei.api.RecipeRegistry; -import me.shedaniel.rei.api.ingredient.entry.EntryTypeRegistry; -import me.shedaniel.rei.api.registry.CategoryRegistry; -import org.jetbrains.annotations.ApiStatus; - -@ApiStatus.OverrideOnly -public interface REIPluginV0 extends REIPlugin { - /** - * Registers the types of entries - */ - @ApiStatus.OverrideOnly - default void registerEntryTypes(EntryTypeRegistry registry) { - - } - - /** - * Registers entries on the item panel - * - * @param registry the helper class - */ - @ApiStatus.OverrideOnly - default void registerEntries(EntryRegistry registry) { - } - - /** - * Registers categories - * - * @param registry the helper class - */ - @ApiStatus.OverrideOnly - default void registerCategories(CategoryRegistry registry) { - } - - /** - * Registers displays for categories - * - * @param registry the helper class - */ - @ApiStatus.OverrideOnly - default void registerDisplays(RecipeRegistry registry) { - } - - /** - * Registers bounds handlers - * - * @param registry the helper class - */ - @ApiStatus.OverrideOnly - default void registerBounds(DisplayBoundsRegistry registry) { - } - - /** - * Register other stuff - * - * @param registry the helper class - */ - @ApiStatus.OverrideOnly - default void registerOthers(RecipeRegistry registry) { - } - - @ApiStatus.OverrideOnly - default void preRegister() { - } - - @ApiStatus.OverrideOnly - default void postRegister() { - } - -} diff --git a/api/src/main/java/me/shedaniel/rei/api/registry/CategoryRegistry.java b/api/src/main/java/me/shedaniel/rei/api/registry/CategoryRegistry.java index ac05d327d..aad3c3aab 100644 --- a/api/src/main/java/me/shedaniel/rei/api/registry/CategoryRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/registry/CategoryRegistry.java @@ -1,73 +1,127 @@ package me.shedaniel.rei.api.registry; +import me.shedaniel.rei.api.ButtonAreaSupplier; import me.shedaniel.rei.api.ingredient.EntryIngredient; 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.api.util.CollectionUtils; +import me.shedaniel.rei.api.util.Identifiable; +import me.shedaniel.rei.impl.Internals; import net.minecraft.resources.ResourceLocation; import java.util.List; +import java.util.Optional; import java.util.function.Consumer; -public interface CategoryRegistry extends Reloadable { +public interface CategoryRegistry extends Reloadable, Iterable> { + /** + * @return the instance of {@link CategoryRegistry} + */ static CategoryRegistry getInstance() { - + return Internals.getCategoryRegistry(); } /** - * Registers a category + * Registers a category. * * @param category the category to register */ - void register(DisplayCategory category); + default void register(DisplayCategory category) { + register(category, config -> {}); + } + + /** + * Registers a category. + * + * @param category the category to register + * @param configurator the consumer for configuring the attributes of the category + */ + void register(DisplayCategory category, Consumer> configurator); - default void register(Iterable> categories) { + /** + * Registers the categories supplied. + * + * @param categories the categories to register + */ + default void register(Iterable> categories) { for (DisplayCategory category : categories) { register(category); } } - default void register(DisplayCategory... categories) { + /** + * Registers the categories supplied. + * + * @param categories the categories to register + */ + default void register(DisplayCategory... categories) { for (DisplayCategory category : categories) { register(category); } } - DisplayCategoryConfiguration get(ResourceLocation category); + CategoryConfiguration get(ResourceLocation category); - DisplayCategoryConfiguration get(ResourceLocation category, Class displayClass); + void configure(ResourceLocation category, Consumer> action); - void configure(ResourceLocation category, Consumer> action); + int size(); - void configure(ResourceLocation category, Class displayClass, Consumer> action); + default void addWorkstations(ResourceLocation category, EntryIngredient... stations) { + configure(category, config -> config.addWorkstations(stations)); + } - default void registerWorkingStations(ResourceLocation category, EntryIngredient... stations) { - configure(category, config -> config.registerWorkingStations(stations)); + default void addWorkstations(ResourceLocation category, EntryStack... stations) { + configure(category, config -> config.addWorkstations(stations)); } - default void registerWorkingStations(ResourceLocation category, EntryStack... stations) { - configure(category, config -> config.registerWorkingStations(stations)); + default void removePlusButton(ResourceLocation category) { + configure(category, CategoryConfiguration::removePlusButton); } - interface DisplayCategoryConfiguration { + default void setPlusButtonArea(ResourceLocation category, ButtonAreaSupplier supplier) { + configure(category, config -> config.setPlusButtonArea(supplier)); + } + + interface CategoryConfiguration extends Identifiable