diff options
Diffstat (limited to 'api')
42 files changed, 981 insertions, 672 deletions
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 00cbb338b..9b1a3e99d 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ClientHelper.java +++ b/api/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -24,12 +24,8 @@ 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.api.view.ViewSearchBuilder; import me.shedaniel.rei.impl.Internals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -41,17 +37,11 @@ import net.minecraft.network.chat.TextComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Collection; import java.util.List; -import java.util.Map; -import java.util.Set; @Environment(EnvType.CLIENT) public interface ClientHelper { - /** * @return the instance of {@link me.shedaniel.rei.api.ClientHelper} */ @@ -60,7 +50,7 @@ public interface ClientHelper { } /** - * Checks if cheating is enabled + * Returns whether cheating is enabled * * @return whether cheating is enabled */ @@ -68,7 +58,7 @@ public interface ClientHelper { /** * Sets current cheating mode - * Should save the config in {@link ConfigManager}. + * Automatically calls {@link ConfigManager#saveConfig()}. * * @param cheating the new cheating mode */ @@ -174,48 +164,4 @@ public interface ClientHelper { boolean openView(ViewSearchBuilder builder); boolean canUseMovePackets(); - - interface ViewSearchBuilder { - static ViewSearchBuilder builder() { - return Internals.createViewSearchBuilder(); - } - - ViewSearchBuilder addCategory(ResourceLocation category); - - ViewSearchBuilder addCategories(Collection<ResourceLocation> categories); - - default ViewSearchBuilder addAllCategories() { - return addCategories(CollectionUtils.map(CategoryRegistry.getInstance(), Identifiable::getIdentifier)); - } - - @NotNull Set<ResourceLocation> getCategories(); - - ViewSearchBuilder addRecipesFor(EntryStack<?> stack); - - @NotNull List<EntryStack<?>> getRecipesFor(); - - ViewSearchBuilder addUsagesFor(EntryStack<?> stack); - - @NotNull List<EntryStack<?>> getUsagesFor(); - - ViewSearchBuilder setPreferredOpenedCategory(@Nullable ResourceLocation category); - - @Nullable - ResourceLocation getPreferredOpenedCategory(); - - ViewSearchBuilder fillPreferredOpenedCategory(); - - ViewSearchBuilder setInputNotice(@Nullable EntryStack<?> stack); - - @Nullable - EntryStack<?> getInputNotice(); - - ViewSearchBuilder setOutputNotice(@Nullable EntryStack<?> stack); - - @Nullable - EntryStack<?> getOutputNotice(); - - @NotNull - Map<DisplayCategory<?>, List<Display>> buildMap(); - } } diff --git a/api/src/main/java/me/shedaniel/rei/api/ConfigManager.java b/api/src/main/java/me/shedaniel/rei/api/ConfigManager.java index 85565a53c..ea09dbd2c 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ConfigManager.java +++ b/api/src/main/java/me/shedaniel/rei/api/ConfigManager.java @@ -23,7 +23,8 @@ package me.shedaniel.rei.api; -import me.shedaniel.rei.impl.Internals; +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; @@ -31,14 +32,13 @@ import net.minecraft.client.gui.screens.Screen; import org.jetbrains.annotations.NotNull; @Environment(EnvType.CLIENT) -public interface ConfigManager { - +public interface ConfigManager extends Reloadable { /** * @return the instance of {@link me.shedaniel.rei.api.ConfigManager} */ @NotNull static ConfigManager getInstance() { - return Internals.getConfigManager(); + return PluginManager.getInstance().get(ConfigManager.class); } /** diff --git a/api/src/main/java/me/shedaniel/rei/api/DisplayRegistry.java b/api/src/main/java/me/shedaniel/rei/api/DisplayRegistry.java deleted file mode 100644 index 59879c891..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/DisplayRegistry.java +++ /dev/null @@ -1,92 +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.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<ResourceLocation, List<Display>> 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 <T extends Recipe<?>> void registerRecipes(ResourceLocation category, Class<T> recipeClass, Function<T, Display> mappingFunction) { - registerRecipes(category, recipe -> recipeClass.isAssignableFrom(recipe.getClass()), mappingFunction); - } - - <T extends Recipe<?>> void registerRecipes(ResourceLocation category, Predicate<? extends T> recipeFilter, Function<T, Display> mappingFunction); -} diff --git a/api/src/main/java/me/shedaniel/rei/api/DisplayRegistryb.java b/api/src/main/java/me/shedaniel/rei/api/DisplayRegistryb.java deleted file mode 100644 index 7485f37c3..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/DisplayRegistryb.java +++ /dev/null @@ -1,214 +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 DisplayRegistryb { - /** - * @return the instance of {@link DisplayRegistry} - */ - @NotNull - static DisplayRegistry getInstance() { - return Internals.getDisplayRegistry(); - } - - AutoTransferHandler registerAutoCraftingHandler(AutoTransferHandler handler); - - void registerFocusedStackProvider(FocusedStackProvider provider); - - @Nullable - @ApiStatus.Internal - EntryStack<?> getScreenFocusedStack(Screen screen); - - List<AutoTransferHandler> getSortedAutoCraftingHandler(); - - /** - * Gets all craftable items from materials. - * - * @param inventoryItems the materials - * @return the list of craftable entries - */ - List<EntryStack<?>> findCraftableEntriesByItems(Iterable<? extends EntryStack<?>> inventoryItems); - - /** - * Gets all craftable items from materials. - * - * @param inventoryItems the materials - * @return the list of craftable entries - */ - default List<EntryStack<?>> findCraftableEntriesByItems(List<? extends EntryStack<?>> inventoryItems) { - return findCraftableEntriesByItems((Iterable<? extends EntryStack<?>>) inventoryItems); - } - - Map<DisplayCategory<?>, List<Display>> 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<DisplayCategory<?>, List<Display>> getRecipesFor(EntryStack<?> stack); - - /** - * Gets a map of usages for an entry - * - * @param stack the stack to be used - * @return the map of recipes - */ - Map<DisplayCategory<?>, List<Display>> 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<ButtonAreaSupplier> getAutoCraftButtonArea(DisplayCategory<?> category); - - /** - * Registers a auto crafting button area - * - * @param category the category of the button area - * @param rectangle the button area - */ - void registerAutoCraftButtonArea(ResourceLocation category, ButtonAreaSupplier rectangle); - - /** - * Removes the auto crafting button - * - * @param category the category of the button - */ - default void removeAutoCraftButton(ResourceLocation category) { - registerAutoCraftButtonArea(category, bounds -> null); - } - - - List<Display> 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<DisplayVisibilityHandler> getDisplayVisibilityHandlers(); - - /** - * Checks if the display is invisible by querying the recipe visibility handlers - * - * @param display the display to be checked - * @return whether the display should be invisible - */ - boolean isDisplayNotVisible(Display display); - - /** - * Checks if the display is visible by querying the recipe visibility handlers - * - * @param display the display to be checked - * @return whether the display should be visible - */ - boolean isDisplayVisible(Display display); - - /** - * Registers a click area for a container screen. - * - * @param rectangle The click area that is offset to the container screen's top left corner. - * @param screenClass The class of the screen. - * @param categories The categories of result. - * @param <T> The screen type to be registered to. - */ - default <T extends AbstractContainerScreen<?>> void registerContainerClickArea(Rectangle rectangle, Class<T> 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 <T> The screen type to be registered to. - */ - <T extends AbstractContainerScreen<?>> void registerContainerClickArea(ScreenClickAreaProvider<T> rectangleSupplier, Class<T> 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 <T> The screen type to be registered to. - */ - <T extends Screen> void registerClickArea(ScreenClickAreaProvider<T> rectangleSupplier, Class<T> 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 <T> The screen type to be registered to. - * @see #registerClickArea(ScreenClickAreaProvider, Class, ResourceLocation...) for a simpler way to handle areas without custom categories. - */ - <T extends Screen> void registerClickArea(Class<T> screenClass, ClickAreaHandler<T> handler); - - @ApiStatus.Internal - boolean arePluginsLoading(); -} - diff --git a/api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java b/api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityPredicate.java index cfea1316d..655342941 100644 --- a/api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java +++ b/api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityPredicate.java @@ -28,7 +28,7 @@ import me.shedaniel.rei.api.registry.display.DisplayCategory; import net.minecraft.world.InteractionResult; import org.jetbrains.annotations.NotNull; -public interface DisplayVisibilityHandler extends Comparable<DisplayVisibilityHandler> { +public interface DisplayVisibilityPredicate extends Comparable<DisplayVisibilityPredicate> { /** * Gets the priority of the handler, the higher the priority, the earlier this is called. @@ -52,7 +52,7 @@ public interface DisplayVisibilityHandler extends Comparable<DisplayVisibilityHa InteractionResult handleDisplay(DisplayCategory<?> category, Display display); @Override - default int compareTo(@NotNull DisplayVisibilityHandler o) { + 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 index bada29cf6..96816d610 100644 --- a/api/src/main/java/me/shedaniel/rei/api/FocusedStackProvider.java +++ b/api/src/main/java/me/shedaniel/rei/api/FocusedStackProvider.java @@ -28,6 +28,7 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.world.InteractionResultHolder; import org.jetbrains.annotations.NotNull; +@FunctionalInterface public interface FocusedStackProvider extends Comparable<FocusedStackProvider> { /** * @return the priority of this handler, higher priorities will be called first. diff --git a/api/src/main/java/me/shedaniel/rei/api/LiveDisplayGenerator.java b/api/src/main/java/me/shedaniel/rei/api/LiveDisplayGenerator.java index ca5098a8c..efaea4eed 100644 --- a/api/src/main/java/me/shedaniel/rei/api/LiveDisplayGenerator.java +++ b/api/src/main/java/me/shedaniel/rei/api/LiveDisplayGenerator.java @@ -25,7 +25,7 @@ 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 me.shedaniel.rei.api.view.ViewSearchBuilder; import java.util.List; import java.util.Optional; @@ -39,7 +39,7 @@ public interface LiveDisplayGenerator<T extends Display> { return Optional.empty(); } - default Optional<List<T>> getDisplaysGenerated(ClientHelper.ViewSearchBuilder builder) { + default Optional<List<T>> generate(ViewSearchBuilder builder) { return Optional.empty(); } } diff --git a/api/src/main/java/me/shedaniel/rei/api/REIHelper.java b/api/src/main/java/me/shedaniel/rei/api/REIHelper.java index bbc08a38b..3a46cf03b 100644 --- a/api/src/main/java/me/shedaniel/rei/api/REIHelper.java +++ b/api/src/main/java/me/shedaniel/rei/api/REIHelper.java @@ -25,6 +25,7 @@ package me.shedaniel.rei.api; import me.shedaniel.rei.api.gui.widgets.TextField; import me.shedaniel.rei.api.gui.widgets.Tooltip; +import me.shedaniel.rei.api.registry.Reloadable; import me.shedaniel.rei.impl.Internals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -37,7 +38,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Optional; @Environment(EnvType.CLIENT) -public interface REIHelper { +public interface REIHelper extends Reloadable { /** * @return the instance of {@link REIHelper} diff --git a/api/src/main/java/me/shedaniel/rei/api/ScreenClickAreaProvider.java b/api/src/main/java/me/shedaniel/rei/api/ScreenClickAreaProvider.java index 3ced900f3..5a5ac101c 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ScreenClickAreaProvider.java +++ b/api/src/main/java/me/shedaniel/rei/api/ScreenClickAreaProvider.java @@ -24,6 +24,7 @@ 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; @@ -36,11 +37,11 @@ public interface ScreenClickAreaProvider<T extends Screen> { @NotNull Rectangle provide(@NotNull T screen); - default ClickAreaHandler<T> toHandler(Supplier<ResourceLocation[]> categories) { + default ClickArea<T> toHandler(Supplier<ResourceLocation[]> categories) { return context -> { return provide(context.getScreen()).contains(context.getMousePosition()) |
