From 542eb5154ebce387312ca3691f743b89e4aef99e Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 27 Feb 2021 17:14:08 +0800 Subject: Remove depending on Cloth API, switching to architectury Signed-off-by: shedaniel --- .../me/shedaniel/rei/api/AutoTransferHandler.java | 293 -------------------- .../me/shedaniel/rei/api/ClickAreaHandler.java | 68 ----- .../java/me/shedaniel/rei/api/ClientHelper.java | 60 +---- .../java/me/shedaniel/rei/api/ConfigManager.java | 8 +- .../java/me/shedaniel/rei/api/DisplayRegistry.java | 92 ------- .../me/shedaniel/rei/api/DisplayRegistryb.java | 214 --------------- .../rei/api/DisplayVisibilityHandler.java | 58 ---- .../rei/api/DisplayVisibilityPredicate.java | 58 ++++ .../me/shedaniel/rei/api/FocusedStackProvider.java | 1 + .../me/shedaniel/rei/api/LiveDisplayGenerator.java | 4 +- .../main/java/me/shedaniel/rei/api/REIHelper.java | 3 +- .../java/me/shedaniel/rei/api/REIPluginEntry.java | 49 ---- .../shedaniel/rei/api/ScreenClickAreaProvider.java | 7 +- .../rei/api/favorites/FavoriteEntryType.java | 23 +- .../rei/api/fluid/FluidSupportProvider.java | 20 +- .../rei/api/gui/SimpleDisplayRenderer.java | 2 +- .../shedaniel/rei/api/gui/widgets/TextField.java | 23 ++ .../rei/api/ingredient/EntryIngredient.java | 27 +- .../rei/api/ingredient/entry/EntryDefinition.java | 12 +- .../api/ingredient/entry/EntryTypeRegistry.java | 45 +++- .../rei/api/ingredient/util/EntryIngredients.java | 41 +++ .../shedaniel/rei/api/plugins/BuiltinPlugin.java | 6 +- .../shedaniel/rei/api/plugins/PluginManager.java | 38 +++ .../me/shedaniel/rei/api/plugins/REIPlugin.java | 74 +++-- .../rei/api/registry/CategoryRegistry.java | 128 --------- .../shedaniel/rei/api/registry/DisplayerQuery.java | 23 ++ .../shedaniel/rei/api/registry/EntryRegistry.java | 150 ----------- .../rei/api/registry/ParentReloadable.java | 36 ++- .../shedaniel/rei/api/registry/PluginHandler.java | 10 - .../rei/api/registry/RecipeManagerContext.java | 23 ++ .../me/shedaniel/rei/api/registry/Reloadable.java | 46 +++- .../api/registry/category/CategoryRegistry.java | 158 +++++++++++ .../rei/api/registry/display/DisplayRegistry.java | 145 ++++++++++ .../rei/api/registry/entry/EntryRegistry.java | 156 +++++++++++ .../rei/api/registry/screen/ClickArea.java | 68 +++++ .../api/registry/screen/DisplayBoundsProvider.java | 47 ++++ .../rei/api/registry/screen/ExclusionZones.java | 56 ++++ .../rei/api/registry/screen/OverlayDecider.java | 76 ++++++ .../rei/api/registry/screen/ScreenRegistry.java | 135 ++++++++++ .../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 ----- .../rei/api/registry/transfer/TransferHandler.java | 297 +++++++++++++++++++++ .../registry/transfer/TransferHandlerRegistry.java | 35 +++ .../shedaniel/rei/api/subsets/SubsetsRegistry.java | 25 +- .../me/shedaniel/rei/api/util/CollectionUtils.java | 60 ++--- .../me/shedaniel/rei/api/util/Identifiable.java | 23 ++ .../shedaniel/rei/api/view/ViewSearchBuilder.java | 84 ++++++ .../main/java/me/shedaniel/rei/api/view/Views.java | 73 +++++ .../main/java/me/shedaniel/rei/impl/Internals.java | 84 ++---- 51 files changed, 1849 insertions(+), 1540 deletions(-) delete mode 100644 api/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ClickAreaHandler.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/DisplayRegistry.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/DisplayRegistryb.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityPredicate.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/plugins/PluginManager.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/CategoryRegistry.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/EntryRegistry.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/PluginHandler.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/category/CategoryRegistry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/display/DisplayRegistry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/entry/EntryRegistry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/screen/ClickArea.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/screen/DisplayBoundsProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/screen/ExclusionZones.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/screen/OverlayDecider.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/screen/ScreenRegistry.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/screens/DisplayBoundsProvider.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/screens/ExclusionZones.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/screens/OverlayDecider.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/screens/ScreenRegistry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/transfer/TransferHandler.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/registry/transfer/TransferHandlerRegistry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/view/ViewSearchBuilder.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/view/Views.java (limited to 'api/src/main') diff --git a/api/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java b/api/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java deleted file mode 100644 index ff137ad51..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java +++ /dev/null @@ -1,293 +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 it.unimi.dsi.fastutil.ints.IntArrayList; -import it.unimi.dsi.fastutil.ints.IntList; -import me.shedaniel.rei.api.registry.display.Display; -import me.shedaniel.rei.api.registry.display.TransferDisplayCategory; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; -import net.minecraft.world.inventory.AbstractContainerMenu; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.function.Supplier; - -@Environment(EnvType.CLIENT) -public interface AutoTransferHandler extends Comparable { - - /** - * @return the priority of this handler, higher priorities will be called first. - */ - default double getPriority() { - return 0d; - } - - @NotNull - Result handle(@NotNull Context context); - - @Override - default int compareTo(@NotNull AutoTransferHandler o) { - return Double.compare(getPriority(), o.getPriority()); - } - - @ApiStatus.NonExtendable - interface Result { - /** - * Creates a successful result, no further handlers will be called. - */ - static Result createSuccessful() { - return new ResultImpl(); - } - - /** - * Creates a passing result, further handlers will be called. - * This will also mark the handler as not applicable. - */ - static Result createNotApplicable() { - return new ResultImpl(false); - } - - /** - * Creates a passing result, further handlers will be called. - * - * @param errorKey The error itself - */ - static Result createFailed(String errorKey) { - return new ResultImpl(errorKey, new IntArrayList(), 1744764928); - } - - /** - * Creates a passing result, further handlers will be called. - * The special color will be applied if this is the last handler. - * - * @param errorKey The error itself - * @param color A special color for the button - */ - static Result createFailedCustomButtonColor(String errorKey, int color) { - return new ResultImpl(errorKey, new IntArrayList(), color); - } - - /** - * Creates a passing result, further handlers will be called. - * - * @param errorKey The error itself - * @param redSlots A list of slots to be marked as red. Will be passed to {@link TransferDisplayCategory}. - */ - static Result createFailed(String errorKey, IntList redSlots) { - return new ResultImpl(errorKey, redSlots, 1744764928); - } - - /** - * Creates a passing result, further handlers will be called. - * The special color will be applied if this is the last handler. - * - * @param errorKey The error itself - * @param color A special color for the button - * @param redSlots A list of slots to be marked as red. Will be passed to {@link TransferDisplayCategory}. - */ - static Result createFailedCustomButtonColor(String errorKey, IntList redSlots, int color) { - return new ResultImpl(errorKey, redSlots, color); - } - - /** - * Forces this handler to be the last handler, no further handlers will be called. - */ - default Result blocksFurtherHandling() { - return blocksFurtherHandling(true); - } - - /** - * Forces this handler to be the last handler, no further handlers will be called. - */ - Result blocksFurtherHandling(boolean returnsToScreen); - - /** - * @return the color in which the button should be displayed in. - */ - int getColor(); - - /** - * @return whether this handler has successfully handled the transfer. - */ - boolean isSuccessful(); - - /** - * @return whether this handler should be the last handler. - */ - boolean isBlocking(); - - /** - * Applicable if {@link #isSuccessful()} is true. - * - * @return whether to return to the previous screen rather than staying open - */ - boolean isReturningToScreen(); - - /** - * @return whether the handler is applicable. - */ - boolean isApplicable(); - - /** - * Applicable if {@link #isSuccessful()} is false. - * - * @return the error message - */ - String getErrorKey(); - - /** - * @return a list of slots to be marked as red. Will be passed to {@link TransferDisplayCategory}. - */ - IntList getIntegers(); - } - - @ApiStatus.NonExtendable - interface Context { - static Context create(boolean actuallyCrafting, AbstractContainerScreen containerScreen, Display display) { - return new ContextImpl(actuallyCrafting, containerScreen, () -> display); - } - - default Minecraft getMinecraft() { - return Minecraft.getInstance(); - } - - boolean isActuallyCrafting(); - - @Nullable - AbstractContainerScreen getContainerScreen(); - - Display getRecipe(); - - @Nullable - default AbstractContainerMenu getContainer() { - return getContainerScreen() == null ? null : getContainerScreen().getMenu(); - } - } - - @ApiStatus.Internal - final class ResultImpl implements Result { - private boolean successful, applicable, returningToScreen, blocking; - private String errorKey; - private IntList integers = new IntArrayList(); - private int color; - - private ResultImpl() { - this(true, true); - } - - public ResultImpl(boolean applicable) { - this(false, applicable); - } - - public ResultImpl(boolean successful, boolean applicable) { - this.successful = successful; - this.applicable = applicable; - } - - public ResultImpl(String errorKey, IntList integers, int color) { - this.successful = false; - this.applicable = true; - this.errorKey = errorKey; - if (integers != null) - this.integers = integers; - this.color = color; - } - - @Override - public Result blocksFurtherHandling(boolean returningToScreen) { - this.blocking = true; - this.returningToScreen = returningToScreen; - return this; - } - - @Override - public int getColor() { - return color; - } - - @Override - public boolean isSuccessful() { - return successful; - } - - @Override - public boolean isBlocking() { - return successful || blocking; - } - - @Override - public boolean isApplicable() { - return applicable; - } - - @Override - public boolean isReturningToScreen() { - return returningToScreen; - } - - @Override - public String getErrorKey() { - return errorKey; - } - - @Override - public IntList getIntegers() { - return integers; - } - } - - @ApiStatus.Internal - final class ContextImpl implements Context { - private boolean actuallyCrafting; - private AbstractContainerScreen containerScreen; - private Supplier recipeDisplaySupplier; - - private ContextImpl(boolean actuallyCrafting, AbstractContainerScreen containerScreen, Supplier recipeDisplaySupplier) { - this.actuallyCrafting = actuallyCrafting; - this.containerScreen = containerScreen; - this.recipeDisplaySupplier = recipeDisplaySupplier; - } - - @Override - public boolean isActuallyCrafting() { - return actuallyCrafting; - } - - @Override - public AbstractContainerScreen getContainerScreen() { - return containerScreen; - } - - @Override - public Display getRecipe() { - return recipeDisplaySupplier.get(); - } - } - -} diff --git a/api/src/main/java/me/shedaniel/rei/api/ClickAreaHandler.java b/api/src/main/java/me/shedaniel/rei/api/ClickAreaHandler.java deleted file mode 100644 index 40a0624b4..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ClickAreaHandler.java +++ /dev/null @@ -1,68 +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.Point; -import me.shedaniel.rei.impl.Internals; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.ApiStatus; - -import java.util.stream.Stream; - -@FunctionalInterface -public interface ClickAreaHandler { - Result handle(ClickAreaContext context); - - @ApiStatus.NonExtendable - interface ClickAreaContext { - T getScreen(); - - Point getMousePosition(); - } - - @ApiStatus.NonExtendable - interface Result { - static Result success() { - return Internals.createClickAreaHandlerResult(true); - } - - static Result fail() { - return Internals.createClickAreaHandlerResult(false); - } - - Result category(ResourceLocation category); - - default Result categories(Iterable categories) { - for (ResourceLocation category : categories) { - category(category); - } - return this; - } - - boolean isSuccessful(); - - Stream getCategories(); - } -} 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 categories); - - default ViewSearchBuilder addAllCategories() { - return addCategories(CollectionUtils.map(CategoryRegistry.getInstance(), Identifiable::getIdentifier)); - } - - @NotNull Set getCategories(); - - ViewSearchBuilder addRecipesFor(EntryStack stack); - - @NotNull List> getRecipesFor(); - - ViewSearchBuilder addUsagesFor(EntryStack stack); - - @NotNull List> 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, List> 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> 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/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 getSortedAutoCraftingHandler(); - - /** - * Gets all craftable items from materials. - * - * @param inventoryItems the materials - * @return the list of craftable entries - */ - List> findCraftableEntriesByItems(Iterable> inventoryItems); - - /** - * Gets all craftable items from materials. - * - * @param inventoryItems the materials - * @return the list of craftable entries - */ - default List> findCraftableEntriesByItems(List> inventoryItems) { - return findCraftableEntriesByItems((Iterable>) inventoryItems); - } - - Map, List> buildMapFor(ClientHelper.ViewSearchBuilder builder); - - /** - * Gets a map of recipes for an entry - * - * @param stack the stack to be crafted - * @return the map of recipes - */ - Map, List> getRecipesFor(EntryStack stack); - - /** - * Gets a map of usages for an entry - * - * @param stack the stack to be used - * @return the map of recipes - */ - Map, List> getUsagesFor(EntryStack stack); - - /** - * Gets the optional of the auto crafting button area from a category - * - * @param category the category of the display - * @return the optional of auto crafting button area - */ - Optional getAutoCraftButtonArea(DisplayCategory category); - - /** - * Registers a auto crafting button area - * - * @param category the category of the button area - * @param rectangle the button area - */ - void registerAutoCraftButtonArea(ResourceLocation category, ButtonAreaSupplier rectangle); - - /** - * Removes the auto crafting button - * - * @param category the category of the button - */ - default void removeAutoCraftButton(ResourceLocation category) { - registerAutoCraftButtonArea(category, bounds -> null); - } - - - List getAllRecipesFromCategory(DisplayCategory category); - - /** - * Registers a recipe visibility handler - * - * @param visibilityHandler the handler to be registered - */ - void registerRecipeVisibilityHandler(DisplayVisibilityHandler visibilityHandler); - - /** - * Unregisters a recipe visibility handler - * - * @param visibilityHandler the handler to be unregistered - */ - void unregisterRecipeVisibilityHandler(DisplayVisibilityHandler visibilityHandler); - - /** - * Gets an unmodifiable list of recipe visibility handlers - * - * @return the unmodifiable list of handlers - */ - List getDisplayVisibilityHandlers(); - - /** - * Checks if the display is invisible by querying the recipe visibility handlers - * - * @param display the display to be checked - * @return whether the display should be invisible - */ - boolean isDisplayNotVisible(Display display); - - /** - * Checks if the display is visible by querying the recipe visibility handlers - * - * @param display the display to be checked - * @return whether the display should be visible - */ - boolean isDisplayVisible(Display display); - - /** - * Registers a click area for a container screen. - * - * @param rectangle The click area that is offset to the container screen's top left corner. - * @param screenClass The class of the screen. - * @param categories The categories of result. - * @param The screen type to be registered to. - */ - default > void registerContainerClickArea(Rectangle rectangle, Class screenClass, ResourceLocation... categories) { - registerContainerClickArea(screen -> rectangle, screenClass, categories); - } - - /** - * Registers a click area for a container screen. - * - * @param rectangleSupplier The click area supplier that is offset to the container screen's top left corner. - * @param screenClass The class of the screen. - * @param categories The categories of result. - * @param The screen type to be registered to. - */ - > void registerContainerClickArea(ScreenClickAreaProvider rectangleSupplier, Class screenClass, ResourceLocation... categories); - - /** - * Registers a click area for a screen. - * - * @param rectangleSupplier The click area supplier that is offset to the window's top left corner. - * @param screenClass The class of the screen. - * @param categories The categories of result. - * @param The screen type to be registered to. - */ - void registerClickArea(ScreenClickAreaProvider rectangleSupplier, Class screenClass, ResourceLocation... categories); - - /** - * Registers a click area handler for a screen. A handler allows more specific implementation of click areas. - * - * @param screenClass The class of the screen. - * @param handler The click area handler that is offset to the window's top left corner. - * @param The screen type to be registered to. - * @see #registerClickArea(ScreenClickAreaProvider, Class, ResourceLocation...) for a simpler way to handle areas without custom categories. - */ - void registerClickArea(Class screenClass, ClickAreaHandler handler); - - @ApiStatus.Internal - boolean arePluginsLoading(); -} - diff --git a/api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java b/api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java deleted file mode 100644 index cfea1316d..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.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 DisplayVisibilityHandler 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 DisplayVisibilityHandler o) { - return Double.compare(getPriority(), o.getPriority()); - } -} diff --git a/api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityPredicate.java b/api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityPredicate.java new file mode 100644 index 000000000..655342941 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/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; + +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 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 { /** * @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 { return Optional.empty(); } - default Optional> getDisplaysGenerated(ClientHelper.ViewSearchBuilder builder) { + default Optional> 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/REIPluginEntry.java b/api/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java deleted file mode 100644 index dc9f05c24..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/REIPluginEntry.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 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/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 { @NotNull Rectangle provide(@NotNull T screen); - default ClickAreaHandler toHandler(Supplier categories) { + default ClickArea toHandler(Supplier categories) { return context -> { return provide(context.getScreen()).contains(context.getMousePosition()) - ? ClickAreaHandler.Result.success().categories(Arrays.asList(categories.get())) - : ClickAreaHandler.Result.fail(); + ? ClickArea.Result.success().categories(Arrays.asList(categories.get())) + : ClickArea.Result.fail(); }; } } diff --git a/api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteEntryType.java b/api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteEntryType.java index 2df0332fc..13f5aa7ad 100644 --- a/api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteEntryType.java +++ b/api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteEntryType.java @@ -24,7 +24,8 @@ package me.shedaniel.rei.api.favorites; import com.google.gson.JsonObject; -import me.shedaniel.rei.impl.Internals; +import me.shedaniel.rei.api.plugins.PluginManager; +import me.shedaniel.rei.api.registry.Reloadable; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; @@ -34,24 +35,24 @@ import org.jetbrains.annotations.Nullable; import java.util.List; public interface FavoriteEntryType { + /** + * A builtin type of favorites, wrapping a {@link me.shedaniel.rei.api.ingredient.EntryStack}. + */ ResourceLocation ENTRY_STACK = new ResourceLocation("roughlyenoughitems", "entry_stack"); @NotNull static Registry registry() { - return Internals.getFavoriteEntryTypeRegistry(); + return PluginManager.getInstance().get(FavoriteEntryType.Registry.class); } - @NotNull - T fromJson(@NotNull JsonObject object); + T fromJson(JsonObject object); - @NotNull T fromArgs(Object... args); - @NotNull - JsonObject toJson(@NotNull T entry, @NotNull JsonObject object); + JsonObject toJson(T entry, JsonObject object); @ApiStatus.NonExtendable - interface Registry { + interface Registry extends Reloadable { void register(ResourceLocation id, FavoriteEntryType type); @Nullable FavoriteEntryType get(ResourceLocation id); @@ -59,21 +60,17 @@ public interface FavoriteEntryType { @Nullable ResourceLocation getId(FavoriteEntryType type); - @NotNull Section getOrCrateSection(Component text); - @NotNull Iterable
sections(); } @ApiStatus.NonExtendable interface Section { - void add(@NotNull FavoriteEntry... entries); + void add(FavoriteEntry... entries); - @NotNull Component getText(); - @NotNull List getEntries(); } } diff --git a/api/src/main/java/me/shedaniel/rei/api/fluid/FluidSupportProvider.java b/api/src/main/java/me/shedaniel/rei/api/fluid/FluidSupportProvider.java index 9052174ac..23fbeda4c 100644 --- a/api/src/main/java/me/shedaniel/rei/api/fluid/FluidSupportProvider.java +++ b/api/src/main/java/me/shedaniel/rei/api/fluid/FluidSupportProvider.java @@ -25,36 +25,32 @@ package me.shedaniel.rei.api.fluid; import me.shedaniel.architectury.fluid.FluidStack; import me.shedaniel.rei.api.ingredient.EntryStack; -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.world.InteractionResultHolder; import net.minecraft.world.item.ItemStack; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Optional; import java.util.stream.Stream; /** - * Experimental library, scheduled to change if needed. + * A registry to provide support for getting fluids from items. */ -@ApiStatus.Experimental @Environment(EnvType.CLIENT) -public interface FluidSupportProvider { +public interface FluidSupportProvider extends Reloadable { static FluidSupportProvider getInstance() { - return Internals.getFluidSupportProvider(); + return PluginManager.getInstance().get(FluidSupportProvider.class); } - void registerProvider(@NotNull Provider provider); + void register(Provider provider); - @NotNull - Optional>> itemToFluids(@NotNull EntryStack itemStack); + Optional>> itemToFluids(EntryStack itemStack); @FunctionalInterface interface Provider { - @NotNull - InteractionResultHolder<@Nullable Stream<@NotNull EntryStack>> itemToFluid(@NotNull EntryStack itemStack); + InteractionResultHolder<@Nullable Stream>> itemToFluid(EntryStack itemStack); } } diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/SimpleDisplayRenderer.java b/api/src/main/java/me/shedaniel/rei/api/gui/SimpleDisplayRenderer.java index 3f42e72b2..8bf538ad0 100644 --- a/api/src/main/java/me/shedaniel/rei/api/gui/SimpleDisplayRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/gui/SimpleDisplayRenderer.java @@ -60,7 +60,7 @@ public class SimpleDisplayRenderer extends DisplayRenderer { private SimpleDisplayRenderer(List input, List output) { this.inputWidgets = simplify(input).stream().filter(stacks -> !stacks.isEmpty()).map(stacks -> Widgets.createSlot(new Point(0, 0)).entries(stacks).disableBackground().disableHighlight().disableTooltips()).collect(Collectors.toList()); this.outputWidgets = CollectionUtils.map(simplify(output), outputStacks -> - Widgets.createSlot(new Point(0, 0)).entries(CollectionUtils.filter(outputStacks, stack -> !stack.isEmpty())).disableBackground().disableHighlight().disableTooltips()); + Widgets.createSlot(new Point(0, 0)).entries(CollectionUtils.filterToList(outputStacks, stack -> !stack.isEmpty())).disableBackground().disableHighlight().disableTooltips()); } private static List simplify(List original) { diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/TextField.java b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/TextField.java index 772302d7a..bc76f72ac 100644 --- a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/TextField.java +++ b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/TextField.java @@ -1,3 +1,26 @@ +/* + * 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.widgets; public interface TextField { diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryIngredient.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryIngredient.java index 04ae3b7f4..c19b0f01e 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryIngredient.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryIngredient.java @@ -1,3 +1,26 @@ +/* + * 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; import me.shedaniel.rei.impl.Internals; @@ -21,7 +44,7 @@ public interface EntryIngredient extends List> { return Internals.getEntryIngredientProvider().of(stacks); } - static EntryIngredient of(Iterable> stacks) { - return Internals.getEntryIngredientProvider().of(stacks); + static EntryIngredient of(Iterable> stacks) { + return Internals.getEntryIngredientProvider().of((Iterable>) (Iterable) stacks); } } diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryDefinition.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryDefinition.java index fbd30e0e2..dcb72f0fe 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryDefinition.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryDefinition.java @@ -35,19 +35,14 @@ import java.util.Collection; import java.util.Optional; public interface EntryDefinition { - @NotNull Class getValueType(); - @NotNull EntryType getType(); - @NotNull EntryRenderer getRenderer(); - @NotNull Optional getIdentifier(EntryStack entry, T value); - @NotNull Fraction getAmount(EntryStack entry, T value); void setAmount(EntryStack entry, T value, Fraction amount); @@ -61,20 +56,15 @@ public interface EntryDefinition { boolean equals(T o1, T o2, ComparisonContext context); - @NotNull CompoundTag toTag(EntryStack entry, T value); - @NotNull - T fromTag(@NotNull CompoundTag tag); + T fromTag(CompoundTag tag); - @NotNull Component asFormattedText(EntryStack entry, T value); - @NotNull Collection getTagsFor(EntryStack entry, T value); @ApiStatus.NonExtendable - @NotNull default EntryDefinition cast() { return (EntryDefinition) this; } diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeRegistry.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeRegistry.java index 8d6d3f946..2fd9f0bbb 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeRegistry.java @@ -23,28 +23,59 @@ package me.shedaniel.rei.api.ingredient.entry; +import me.shedaniel.rei.api.plugins.PluginManager; +import me.shedaniel.rei.api.registry.Reloadable; import me.shedaniel.rei.impl.Internals; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public interface EntryTypeRegistry { - @NotNull +public interface EntryTypeRegistry extends Reloadable { static EntryTypeRegistry getInstance() { - return Internals.getEntryTypeRegistry(); + return PluginManager.getInstance().get(EntryTypeRegistry.class); } - default void register(EntryType id, EntryDefinition definition) { - register(id.getId(), definition); + /** + * Registers a entry type, with its entry definition. + * + * @param type the entry type + * @param definition the definition of the entry + * @param the type of the entry + */ + default void register(EntryType type, EntryDefinition definition) { + register(type.getId(), definition); } + /** + * Registers a entry type, with its entry definition. + * + * @param id the identifier of the entry type + * @param definition the definition of the entry + * @param the type of the entry + */ void register(ResourceLocation id, EntryDefinition definition); - void registerBridge(EntryType original, EntryType destination, EntryTypeBridge bridge); + /** + * Returns the entry definition from the entry type. + * + * @param type the entry type + * @return the definition of the entry, may be {@code null} if {@code type} was not registered + */ + @Nullable + default EntryDefinition get(EntryType type) { + return type.getDefinition(); + } + /** + * Returns the entry definition from an identifier of the entry type. + * + * @param id the identifier of the entry type + * @return the definition of the entry, may be {@code null} if {@code id} is an unknown type + */ @Nullable EntryDefinition get(ResourceLocation id); - @NotNull + void registerBridge(EntryType original, EntryType destination, EntryTypeBridge bridge); + Iterable> getBridgesFor(EntryType original, EntryType destination); } \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/util/EntryIngredients.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/util/EntryIngredients.java index af118389c..0407ae215 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/util/EntryIngredients.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/util/EntryIngredients.java @@ -24,11 +24,14 @@ package me.shedaniel.rei.api.ingredient.util; import com.google.common.collect.ImmutableList; +import me.shedaniel.architectury.utils.Fraction; +import me.shedaniel.rei.api.gui.Renderer; import me.shedaniel.rei.api.ingredient.EntryIngredient; import me.shedaniel.rei.api.ingredient.EntryStack; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.material.Fluid; import java.util.ArrayList; import java.util.Collection; @@ -38,6 +41,34 @@ import java.util.List; public final class EntryIngredients { private EntryIngredients() {} + public static EntryIngredient of(ItemLike stack) { + return EntryIngredient.of(EntryStacks.of(stack)); + } + + public static EntryIngredient of(ItemStack stack) { + return EntryIngredient.of(EntryStacks.of(stack)); + } + + public static EntryIngredient of(Fluid fluid) { + return EntryIngredient.of(EntryStacks.of(fluid)); + } + + public static EntryIngredient of(Fluid fluid, int amount) { + return EntryIngredient.of(EntryStacks.of(fluid, amount)); + } + + public static EntryIngredient of(Fluid fluid, double amount) { + return EntryIngredient.of(EntryStacks.of(fluid, amount)); + } + + public static EntryIngredient of(Fluid fluid, Fraction amount) { + return EntryIngredient.of(EntryStacks.of(fluid, amount)); + } + + public static EntryIngredient of(Renderer renderer) { + return EntryIngredient.of(EntryStacks.of(renderer)); + } + public static EntryIngredient ofItems(Collection stacks) { if (stacks.size() == 0) return EntryIngredient.empty(); if (stacks.size() == 1) return EntryIngredient.of(EntryStacks.of(stacks.iterator().next())); @@ -92,4 +123,14 @@ public final class EntryIngredients { } return ImmutableList.copyOf(result); } + + public static boolean testFuzzy(EntryIngredient ingredient, EntryStack stack) { + for (EntryStack ingredientStack : ingredient) { + if (EntryStacks.equalsFuzzy(ingredientStack, stack)) { + return true; + } + } + + return false; + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/plugins/BuiltinPlugin.java b/api/src/main/java/me/shedaniel/rei/api/plugins/BuiltinPlugin.java index 2eb5a