From 4e26c83691cf4ce0a19dc2244e31bd73e551865e Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 18 Mar 2021 01:49:30 +0800 Subject: Relocate api classes Signed-off-by: shedaniel --- .../me/shedaniel/rei/api/ButtonAreaSupplier.java | 53 ------- .../java/me/shedaniel/rei/api/ClientHelper.java | 1 + .../java/me/shedaniel/rei/api/ConfigManager.java | 80 ---------- .../java/me/shedaniel/rei/api/ConfigObject.java | 165 --------------------- .../rei/api/DisplayVisibilityPredicate.java | 58 -------- .../me/shedaniel/rei/api/FocusedStackProvider.java | 47 ------ .../me/shedaniel/rei/api/LiveDisplayGenerator.java | 45 ------ .../main/java/me/shedaniel/rei/api/REIOverlay.java | 1 - .../shedaniel/rei/api/ScreenClickAreaProvider.java | 47 ------ .../me/shedaniel/rei/api/config/ConfigManager.java | 80 ++++++++++ .../me/shedaniel/rei/api/config/ConfigObject.java | 165 +++++++++++++++++++++ .../me/shedaniel/rei/api/gui/widgets/Widgets.java | 2 +- .../rei/api/registry/category/ButtonArea.java | 53 +++++++ .../api/registry/category/CategoryRegistry.java | 11 +- .../rei/api/registry/display/DisplayRegistry.java | 3 +- .../api/registry/display/LiveDisplayGenerator.java | 45 ++++++ .../visibility/DisplayVisibilityPredicate.java | 58 ++++++++ .../api/registry/screen/FocusedStackProvider.java | 47 ++++++ .../rei/api/registry/screen/ScreenRegistry.java | 16 +- .../rei/api/registry/screen/SimpleClickArea.java | 46 ++++++ 20 files changed, 509 insertions(+), 514 deletions(-) delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ButtonAreaSupplier.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ConfigManager.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ConfigObject.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityPredicate.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/FocusedStackProvider.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/LiveDisplayGenerator.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ScreenClickAreaProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/config/ConfigManager.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/config/ConfigObject.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/category/ButtonArea.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/display/LiveDisplayGenerator.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/display/visibility/DisplayVisibilityPredicate.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/screen/FocusedStackProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/screen/SimpleClickArea.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 deleted file mode 100644 index 323b8d810..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ButtonAreaSupplier.java +++ /dev/null @@ -1,53 +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; - -/** - * The supplier for the + button area. - */ -@FunctionalInterface -public interface ButtonAreaSupplier { - static ButtonAreaSupplier defaultArea() { - return bounds -> new Rectangle(bounds.getMaxX() + 2, bounds.getMaxY() - 16, 10, 10); - } - - /** - * Declares the button bounds - * - * @param bounds the bounds of the recipe display - * @return the bounds of the button - */ - Rectangle get(Rectangle bounds); - - /** - * Declares the button text - * - * @return the text of the button - */ - default String getButtonText() { - return "+"; - } -} 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 9b1a3e99d..1250d381a 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ClientHelper.java +++ b/api/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.api; +import me.shedaniel.rei.api.config.ConfigManager; import me.shedaniel.rei.api.ingredient.EntryStack; import me.shedaniel.rei.api.util.FormattingUtils; import me.shedaniel.rei.api.view.ViewSearchBuilder; diff --git a/api/src/main/java/me/shedaniel/rei/api/ConfigManager.java b/api/src/main/java/me/shedaniel/rei/api/ConfigManager.java deleted file mode 100644 index ea09dbd2c..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ConfigManager.java +++ /dev/null @@ -1,80 +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.plugins.PluginManager; -import me.shedaniel.rei.api.registry.Reloadable; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; -import org.jetbrains.annotations.NotNull; - -@Environment(EnvType.CLIENT) -public interface ConfigManager extends Reloadable { - /** - * @return the instance of {@link me.shedaniel.rei.api.ConfigManager} - */ - @NotNull - static ConfigManager getInstance() { - return PluginManager.getInstance().get(ConfigManager.class); - } - - /** - * Saves the config. - */ - void saveConfig(); - - /** - * Gets if craftable only filter is enabled - * - * @return whether craftable only filter is enabled - */ - boolean isCraftableOnlyEnabled(); - - /** - * Toggles the craftable only filter - */ - void toggleCraftableOnly(); - - /** - * Opens the config screen - * - * @param parent the screen shown before - */ - default void openConfigScreen(Screen parent) { - Minecraft.getInstance().setScreen(getConfigScreen(parent)); - } - - /** - * Gets the config screen - * - * @param parent the screen shown before - * @return the config screen - */ - Screen getConfigScreen(Screen parent); - - ConfigObject getConfig(); - -} diff --git a/api/src/main/java/me/shedaniel/rei/api/ConfigObject.java b/api/src/main/java/me/shedaniel/rei/api/ConfigObject.java deleted file mode 100644 index a92300e00..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ConfigObject.java +++ /dev/null @@ -1,165 +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.clothconfig2.api.ModifierKeyCode; -import me.shedaniel.rei.api.favorites.FavoriteEntry; -import me.shedaniel.rei.api.gui.config.*; -import me.shedaniel.rei.api.ingredient.EntryStack; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import org.jetbrains.annotations.ApiStatus; - -import java.util.List; - -@Environment(EnvType.CLIENT) -public interface ConfigObject { - /** - * @return the instance of {@link me.shedaniel.rei.api.ConfigObject} - */ - static ConfigObject getInstance() { - return ConfigManager.getInstance().getConfig(); - } - - boolean isOverlayVisible(); - - void setOverlayVisible(boolean overlayVisible); - - boolean isCheating(); - - void setCheating(boolean cheating); - - EntryPanelOrdering getItemListOrdering(); - - boolean isItemListAscending(); - - boolean isUsingDarkTheme(); - - boolean isGrabbingItems(); - - boolean isReducedMotion(); - - boolean isToastDisplayedOnCopyIdentifier(); - - boolean isEntryListWidgetScrolled(); - - boolean shouldAppendModNames(); - - RecipeScreenType getRecipeScreenType(); - - void setRecipeScreenType(RecipeScreenType recipeScreenType); - - SearchFieldLocation getSearchFieldLocation(); - - default boolean isLeftHandSidePanel() { - return getDisplayPanelLocation() == DisplayPanelLocation.LEFT; - } - - DisplayPanelLocation getDisplayPanelLocation(); - - boolean isCraftableFilterEnabled(); - - String getGamemodeCommand(); - - String getGiveCommand(); - - String getWeatherCommand(); - - int getMaxRecipePerPage(); - - boolean doesShowUtilsButtons(); - - boolean doesDisableRecipeBook(); - - boolean doesFixTabCloseContainer(); - - boolean areClickableRecipeArrowsEnabled(); - - RecipeBorderType getRecipeBorderType(); - - boolean doesVillagerScreenHavePermanentScrollBar(); - - boolean doesRegisterRecipesInAnotherThread(); - - boolean doesSnapToRows(); - - boolean isFavoritesEnabled(); - - boolean doDisplayFavoritesTooltip(); - - boolean doesFastEntryRendering(); - - boolean doDebugRenderTimeRequired(); - - ModifierKeyCode getFavoriteKeyCode(); - - ModifierKeyCode getRecipeKeybind(); - - ModifierKeyCode getUsageKeybind(); - - ModifierKeyCode getHideKeybind(); - - ModifierKeyCode getPreviousPageKeybind(); - - ModifierKeyCode getNextPageKeybind(); - - ModifierKeyCode getFocusSearchFieldKeybind(); - - ModifierKeyCode getCopyRecipeIdentifierKeybind(); - - ModifierKeyCode getExportImageKeybind(); - - double getEntrySize(); - - boolean isUsingCompactTabs(); - - boolean isLowerConfigButton(); - - @ApiStatus.Experimental - List getFavoriteEntries(); - - List> getFilteredStacks(); - - @ApiStatus.Experimental - boolean shouldAsyncSearch(); - - @ApiStatus.Experimental - int getAsyncSearchPartitionSize(); - - @ApiStatus.Experimental - boolean doDebugSearchTimeRequired(); - - boolean isSubsetsEnabled(); - - boolean isInventoryHighlightingAllowed(); - - @ApiStatus.Experimental - double getHorizontalEntriesBoundaries(); - - @ApiStatus.Experimental - double getVerticalEntriesBoundaries(); - - @ApiStatus.Experimental - SyntaxHighlightingMode getSyntaxHighlightingMode(); -} diff --git a/api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityPredicate.java b/api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityPredicate.java deleted file mode 100644 index 655342941..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityPredicate.java +++ /dev/null @@ -1,58 +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.registry.display.Display; -import me.shedaniel.rei.api.registry.display.DisplayCategory; -import net.minecraft.world.InteractionResult; -import org.jetbrains.annotations.NotNull; - -public interface DisplayVisibilityPredicate extends Comparable { - - /** - * Gets the priority of the handler, the higher the priority, the earlier this is called. - * - * @return the priority - */ - default float getPriority() { - return 0f; - } - - /** - * Handles the visibility of the display. - * {@link ActionResult#PASS} to pass the handling to another handler - * {@link ActionResult#SUCCESS} to always display it - * {@link ActionResult#FAIL} to never display it - * - * @param category the category of the display - * @param display the display of the recipe - * @return the visibility - */ - InteractionResult handleDisplay(DisplayCategory category, Display display); - - @Override - default int compareTo(@NotNull DisplayVisibilityPredicate o) { - return Double.compare(getPriority(), o.getPriority()); - } -} diff --git a/api/src/main/java/me/shedaniel/rei/api/FocusedStackProvider.java b/api/src/main/java/me/shedaniel/rei/api/FocusedStackProvider.java deleted file mode 100644 index 96816d610..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/FocusedStackProvider.java +++ /dev/null @@ -1,47 +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 net.minecraft.client.gui.screens.Screen; -import net.minecraft.world.InteractionResultHolder; -import org.jetbrains.annotations.NotNull; - -@FunctionalInterface -public interface FocusedStackProvider extends Comparable { - /** - * @return the priority of this handler, higher priorities will be called first. - */ - default double getPriority() { - return 0d; - } - - @NotNull - InteractionResultHolder> provide(Screen screen); - - @Override - default int compareTo(@NotNull FocusedStackProvider o) { - return Double.compare(getPriority(), o.getPriority()); - } -} diff --git a/api/src/main/java/me/shedaniel/rei/api/LiveDisplayGenerator.java b/api/src/main/java/me/shedaniel/rei/api/LiveDisplayGenerator.java deleted file mode 100644 index efaea4eed..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/LiveDisplayGenerator.java +++ /dev/null @@ -1,45 +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 me.shedaniel.rei.api.view.ViewSearchBuilder; - -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> generate(ViewSearchBuilder builder) { - return Optional.empty(); - } -} diff --git a/api/src/main/java/me/shedaniel/rei/api/REIOverlay.java b/api/src/main/java/me/shedaniel/rei/api/REIOverlay.java index 2b66857d4..fd1f2dbea 100644 --- a/api/src/main/java/me/shedaniel/rei/api/REIOverlay.java +++ b/api/src/main/java/me/shedaniel/rei/api/REIOverlay.java @@ -27,7 +27,6 @@ import me.shedaniel.rei.api.gui.drag.DraggingContext; import me.shedaniel.rei.api.gui.widgets.WidgetWithBounds; import org.jetbrains.annotations.ApiStatus; -@ApiStatus.Experimental public abstract class REIOverlay extends WidgetWithBounds { @ApiStatus.Internal public abstract void closeOverlayMenu(); diff --git a/api/src/main/java/me/shedaniel/rei/api/ScreenClickAreaProvider.java b/api/src/main/java/me/shedaniel/rei/api/ScreenClickAreaProvider.java deleted file mode 100644 index 5a5ac101c..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ScreenClickAreaProvider.java +++ /dev/null @@ -1,47 +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.registry.screen.ClickArea; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.function.Supplier; - -@FunctionalInterface -public interface ScreenClickAreaProvider { - @NotNull - Rectangle provide(@NotNull T screen); - - default ClickArea toHandler(Supplier categories) { - return context -> { - return provide(context.getScreen()).contains(context.getMousePosition()) - ? ClickArea.Result.success().categories(Arrays.asList(categories.get())) - : ClickArea.Result.fail(); - }; - } -} diff --git a/api/src/main/java/me/shedaniel/rei/api/config/ConfigManager.java b/api/src/main/java/me/shedaniel/rei/api/config/ConfigManager.java new file mode 100644 index 000000000..cd5b75dc9 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/config/ConfigManager.java @@ -0,0 +1,80 @@ +/* + * 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.config; + +import me.shedaniel.rei.api.plugins.PluginManager; +import me.shedaniel.rei.api.registry.Reloadable; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; +import org.jetbrains.annotations.NotNull; + +@Environment(EnvType.CLIENT) +public interface ConfigManager extends Reloadable { + /** + * @return the instance of {@link ConfigManager} + */ + @NotNull + static ConfigManager getInstance() { + return PluginManager.getInstance().get(ConfigManager.class); + } + + /** + * Saves the config. + */ + void saveConfig(); + + /** + * Gets if craftable only filter is enabled + * + * @return whether craftable only filter is enabled + */ + boolean isCraftableOnlyEnabled(); + + /** + * Toggles the craftable only filter + */ + void toggleCraftableOnly(); + + /** + * Opens the config screen + * + * @param parent the screen shown before + */ + default void openConfigScreen(Screen parent) { + Minecraft.getInstance().setScreen(getConfigScreen(parent)); + } + + /** + * Gets the config screen + * + * @param parent the screen shown before + * @return the config screen + */ + Screen getConfigScreen(Screen parent); + + ConfigObject getConfig(); + +} diff --git a/api/src/main/java/me/shedaniel/rei/api/config/ConfigObject.java b/api/src/main/java/me/shedaniel/rei/api/config/ConfigObject.java new file mode 100644 index 000000000..bc471d90f --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/config/ConfigObject.java @@ -0,0 +1,165 @@ +/* + * 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.config; + +import me.shedaniel.clothconfig2.api.ModifierKeyCode; +import me.shedaniel.rei.api.favorites.FavoriteEntry; +import me.shedaniel.rei.api.gui.config.*; +import me.shedaniel.rei.api.ingredient.EntryStack; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import org.jetbrains.annotations.ApiStatus; + +import java.util.List; + +@Environment(EnvType.CLIENT) +public interface ConfigObject { + /** + * @return the instance of {@link ConfigObject} + */ + static ConfigObject getInstance() { + return ConfigManager.getInstance().getConfig(); + } + + boolean isOverlayVisible(); + + void setOverlayVisible(boolean overlayVisible); + + boolean isCheating(); + + void setCheating(boolean cheating); + + EntryPanelOrdering getItemListOrdering(); + + boolean isItemListAscending(); + + boolean isUsingDarkTheme(); + + boolean isGrabbingItems(); + + boolean isReducedMotion(); + + boolean isToastDisplayedOnCopyIdentifier(); + + boolean isEntryListWidgetScrolled(); + + boolean shouldAppendModNames(); + + RecipeScreenType getRecipeScreenType(); + + void setRecipeScreenType(RecipeScreenType recipeScreenType); + + SearchFieldLocation getSearchFieldLocation(); + + default boolean isLeftHandSidePanel() { + return getDisplayPanelLocation() == DisplayPanelLocation.LEFT; + } + + DisplayPanelLocation getDisplayPanelLocation(); + + boolean isCraftableFilterEnabled(); + + String getGamemodeCommand(); + + String getGiveCommand(); + + String getWeatherCommand(); + + int getMaxRecipePerPage(); + + boolean doesShowUtilsButtons(); + + boolean doesDisableRecipeBook(); + + boolean doesFixTabCloseContainer(); + + boolean areClickableRecipeArrowsEnabled(); + + RecipeBorderType getRecipeBorderType(); + + boolean doesVillagerScreenHavePermanentScrollBar(); + + boolean doesRegisterRecipesInAnotherThread(); + + boolean doesSnapToRows(); + + boolean isFavoritesEnabled(); + + boolean doDisplayFavoritesTooltip(); + + boolean doesFastEntryRendering(); + + boolean doDebugRenderTimeRequired(); + + ModifierKeyCode getFavoriteKeyCode(); + + ModifierKeyCode getRecipeKeybind(); + + ModifierKeyCode getUsageKeybind(); + + ModifierKeyCode getHideKeybind(); + + ModifierKeyCode getPreviousPageKeybind(); + + ModifierKeyCode getNextPageKeybind(); + + ModifierKeyCode getFocusSearchFieldKeybind(); + + ModifierKeyCode getCopyRecipeIdentifierKeybind(); + + ModifierKeyCode getExportImageKeybind(); + + double getEntrySize(); + + boolean isUsingCompactTabs(); + + boolean isLowerConfigButton(); + + @ApiStatus.Experimental + List getFavoriteEntries(); + + List> getFilteredStacks(); + + @ApiStatus.Experimental + boolean shouldAsyncSearch(); + + @ApiStatus.Experimental + int getAsyncSearchPartitionSize(); + + @ApiStatus.Experimental + boolean doDebugSearchTimeRequired(); + + boolean isSubsetsEnabled(); + + boolean isInventoryHighlightingAllowed(); + + @ApiStatus.Experimental + double getHorizontalEntriesBoundaries(); + + @ApiStatus.Experimental + double getVerticalEntriesBoundaries(); + + @ApiStatus.Experimental + SyntaxHighlightingMode getSyntaxHighlightingMode(); +} 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 c0ef26b7d..ac9423e4d 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 @@ -28,7 +28,7 @@ import com.mojang.math.Matrix4f; import me.shedaniel.math.Dimension; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.ConfigObject; +import me.shedaniel.rei.api.config.ConfigObject; import me.shedaniel.rei.api.gui.DrawableConsumer; import me.shedaniel.rei.api.gui.Renderer; import me.shedaniel.rei.impl.Internals; diff --git a/api/src/main/java/me/shedaniel/rei/api/registry/category/ButtonArea.java b/api/src/main/java/me/shedaniel/rei/api/registry/category/ButtonArea.java new file mode 100644 index 000000000..668214007 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/registry/category/ButtonArea.java @@ -0,0 +1,53 @@ +/* + * 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.registry.category; + +import me.shedaniel.math.Rectangle; + +/** + * The area for the + button. + */ +@FunctionalInterface +public interface ButtonArea { + static ButtonArea defaultArea() { + return bounds -> new Rectangle(bounds.getMaxX() + 2, bounds.getMaxY() - 16, 10, 10); + } + + /** + * Declares the button bounds + * + * @param bounds the bounds of the recipe display + * @return the bounds of the button + */ + Rectangle get(Rectangle bounds); + + /** + * Declares the button text + * + * @return the text of the button + */ + default String getButtonText() { + return "+"; + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/registry/category/CategoryRegistry.java b/api/src/main/java/me/shedaniel/rei/api/registry/category/CategoryRegistry.java index 6f0ca0d18..b9e686def 100644 --- a/api/src/main/java/me/shedaniel/rei/api/registry/category/CategoryRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/registry/category/CategoryRegistry.java @@ -23,7 +23,6 @@ package me.shedaniel.rei.api.registry.category; -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.plugins.PluginManager; @@ -109,8 +108,8 @@ public interface CategoryRegistry extends Reloadable, Iterable config.setPlusButtonArea(supplier)); + default void setPlusButtonArea(ResourceLocation category, ButtonArea area) { + configure(category, config -> config.setPlusButtonArea(area)); } interface CategoryConfiguration extends Identifiable { @@ -140,16 +139,16 @@ public interface CategoryRegistry extends Reloadable, Iterable getPlusButtonArea(); + Optional getPlusButtonArea(); List getWorkstations(); diff --git a/api/src/main/java/me/shedaniel/rei/api/registry/display/DisplayRegistry.java b/api/src/main/java/me/shedaniel/rei/api/registry/display/DisplayRegistry.java index 4b970ebd5..978c00319 100644 --- a/api/src/main/java/me/shedaniel/rei/api/registry/display/DisplayRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/registry/display/DisplayRegistry.java @@ -23,8 +23,7 @@ package me.shedaniel.rei.api.registry.display; -import me.shedaniel.rei.api.DisplayVisibilityPredicate; -import me.shedaniel.rei.api.LiveDisplayGenerator; +import me.shedaniel.rei.api.registry.display.visibility.DisplayVisibilityPredicate; import me.shedaniel.rei.api.plugins.PluginManager; import me.shedaniel.rei.api.registry.RecipeManagerContext; import me.shedaniel.rei.api.registry.Reloadable; diff --git a/api/src/main/java/me/shedaniel/rei/api/registry/display/LiveDisplayGenerator.java b/api/src/main/java/me/shedaniel/rei/api/registry/display/LiveDisplayGenerator.java new file mode 100644 index 000000000..263bda029 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/registry/display/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.registry.display; + +import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.api.registry.display.Display; +import me.shedaniel.rei.api.view.ViewSearchBuilder; + +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> generate(ViewSearchBuilder builder) { + return Optional.empty(); + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/registry/display/visibility/DisplayVisibilityPredicate.java b/api/src/main/java/me/shedaniel/rei/api/registry/display/visibility/DisplayVisibilityPredicate.java new file mode 100644 index 000000000..68777fe03 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/registry/display/visibility/DisplayVisibilityPredicate.java @@ -0,0 +1,58 @@ +/* + * 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.registry.display.visibility; + +import me.shedaniel.rei.api.registry.display.Display; +import me.shedaniel.rei.api.registry.display.DisplayCategory; +import net.minecraft.world.InteractionResult; +import org.jetbrains.annotations.NotNull; + +public interface DisplayVisibilityPredicate extends Comparable { + + /** + * Gets the priority of the handler, the higher the priority, the earlier this is called. + * + * @return the priority + */ + default float getPriority() { + return 0f; + } + + /** + * Handles the visibility of the display. + * {@link ActionResult#PASS} to pass the handling to another handler + * {@link ActionResult#SUCCESS} to always display it + * {@link ActionResult#FAIL} to never display it + * + * @param category the category of the display + * @param display the display of the recipe + * @return the visibility + */ + InteractionResult handleDisplay(DisplayCategory category, Display display); + + @Override + default int compareTo(@NotNull DisplayVisibilityPredicate o) { + return Double.compare(getPriority(), o.getPriority()); + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/registry/screen/FocusedStackProvider.java b/api/src/main/java/me/shedaniel/rei/api/registry/screen/FocusedStackProvider.java new file mode 100644 index 000000000..6e0c682fd --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/registry/screen/FocusedStackProvider.java @@ -0,0 +1,47 @@ +/* + * 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.registry.screen; + +import me.shedaniel.rei.api.ingredient.EntryStack; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.world.InteractionResultHolder; +import org.jetbrains.annotations.NotNull; + +@FunctionalInterface +public interface FocusedStackProvider extends Comparable { + /** + * @return the priority of this handler, higher priorities will be called first. + */ + default double getPriority() { + return 0d; + } + + @NotNull + InteractionResultHolder> provide(Screen screen); + + @Override + default int compareTo(@NotNull FocusedStackProvider o) { + return Double.compare(getPriority(), o.getPriority()); + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/registry/screen/ScreenRegistry.java b/api/src/main/java/me/shedaniel/rei/api/registry/screen/ScreenRegistry.java index 7284c01c3..b4d89b033 100644 --- a/api/src/main/java/me/shedaniel/rei/api/registry/screen/ScreenRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/registry/screen/ScreenRegistry.java @@ -24,8 +24,6 @@ package me.shedaniel.rei.api.registry.screen; import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.FocusedStackProvider; -import me.shedaniel.rei.api.ScreenClickAreaProvider; import me.shedaniel.rei.api.gui.config.DisplayPanelLocation; import me.shedaniel.rei.api.ingredient.EntryStack; import me.shedaniel.rei.api.plugins.PluginManager; @@ -102,32 +100,32 @@ public interface ScreenRegistry extends Reloadable { /** * Registers a click area for a container screen. * - * @param provider The click area provider that is offset to the container screen's top left corner. + * @param area 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. */ - > void registerContainerClickArea(ScreenClickAreaProvider provider, Class screenClass, ResourceLocation... categories); + > void registerContainerClickArea(SimpleClickArea area, Class screenClass, ResourceLocation... categories); /** * Registers a click area for a screen. * - * @param provider The click area provider that is offset to the window's top left corner. + * @param area The click area 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. */ - default void registerClickArea(ScreenClickAreaProvider provider, Class screenClass, ResourceLocation... categories) { - registerClickArea(screenClass, provider.toHandler(() -> categories)); + default void registerClickArea(SimpleClickArea area, Class screenClass, ResourceLocation... categories) { + registerClickArea(screenClass, area.toClickArea(() -> 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 area The click area provider that is offset to the window's top left corner. + * @param area The click area 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. + * @see #registerClickArea(SimpleClickArea, Class, ResourceLocation...) for a simpler way to handle areas without custom categories. */ void registerClickArea(Class screenClass, ClickArea area); diff --git a/api/src/main/java/me/shedaniel/rei/api/registry/screen/SimpleClickArea.java b/api/src/main/java/me/shedaniel/rei/api/registry/screen/SimpleClickArea.java new file mode 100644 index 000000000..55ff1fa70 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/registry/screen/SimpleClickArea.java @@ -0,0 +1,46 @@ +/* + * 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.registry.screen; + +import me.shedaniel.math.Rectangle; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.function.Supplier; + +@FunctionalInterface +public interface SimpleClickArea { + @NotNull + Rectangle provide(@NotNull T screen); + + default ClickArea toClickArea(Supplier categories) { + return context -> { + return provide(context.getScreen()).contains(context.getMousePosition()) + ? ClickArea.Result.success().categories(Arrays.asList(categories.get())) + : ClickArea.Result.fail(); + }; + } +} -- cgit