From 67171a5ff24ed77e6c4cc889543e8dfb543e8fe5 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 20 Dec 2020 19:59:49 +0800 Subject: wip more Signed-off-by: shedaniel --- api/build.gradle | 1 + .../me/shedaniel/rei/api/AutoTransferHandler.java | 286 ++++++++++ .../me/shedaniel/rei/api/BaseBoundsHandler.java | 62 ++ .../java/me/shedaniel/rei/api/BuiltinPlugin.java | 70 +++ .../me/shedaniel/rei/api/ButtonAreaSupplier.java | 50 ++ .../me/shedaniel/rei/api/ClickAreaHandler.java | 68 +++ .../java/me/shedaniel/rei/api/ClientHelper.java | 216 +++++++ .../java/me/shedaniel/rei/api/ConfigManager.java | 80 +++ .../java/me/shedaniel/rei/api/ConfigObject.java | 162 ++++++ .../java/me/shedaniel/rei/api/DisplayHelper.java | 100 ++++ .../rei/api/DisplayVisibilityHandler.java | 51 ++ .../me/shedaniel/rei/api/DrawableConsumer.java | 35 ++ .../java/me/shedaniel/rei/api/EntryRegistry.java | 125 ++++ .../main/java/me/shedaniel/rei/api/EntryStack.java | 203 +++++++ .../me/shedaniel/rei/api/FocusedStackProvider.java | 40 ++ .../me/shedaniel/rei/api/LiveRecipeGenerator.java | 50 ++ .../java/me/shedaniel/rei/api/OverlayDecider.java | 69 +++ .../main/java/me/shedaniel/rei/api/REIHelper.java | 64 +++ .../main/java/me/shedaniel/rei/api/REIOverlay.java | 31 + .../java/me/shedaniel/rei/api/REIPluginEntry.java | 44 ++ .../java/me/shedaniel/rei/api/RecipeCategory.java | 131 +++++ .../java/me/shedaniel/rei/api/RecipeDisplay.java | 74 +++ .../java/me/shedaniel/rei/api/RecipeHelper.java | 300 ++++++++++ .../main/java/me/shedaniel/rei/api/Renderer.java | 43 ++ .../shedaniel/rei/api/ScreenClickAreaProvider.java | 46 ++ .../me/shedaniel/rei/api/TextRepresentable.java | 44 ++ .../shedaniel/rei/api/TransferRecipeCategory.java | 37 ++ .../shedaniel/rei/api/TransferRecipeDisplay.java | 44 ++ .../rei/api/entry/AbstractEntryRenderer.java | 29 + .../shedaniel/rei/api/entry/AbstractRenderer.java | 39 ++ .../rei/api/entry/BatchEntryRenderer.java | 61 ++ .../shedaniel/rei/api/entry/BuiltinEntryTypes.java | 37 ++ .../shedaniel/rei/api/entry/ComparisonContext.java | 59 ++ .../shedaniel/rei/api/entry/EntryDefinition.java | 78 +++ .../me/shedaniel/rei/api/entry/EntryRenderer.java | 38 ++ .../me/shedaniel/rei/api/entry/EntryStacks.java | 187 ++++++ .../java/me/shedaniel/rei/api/entry/EntryType.java | 48 ++ .../shedaniel/rei/api/entry/EntryTypeBridge.java | 36 ++ .../shedaniel/rei/api/entry/EntryTypeRegistry.java | 50 ++ .../shedaniel/rei/api/entry/VanillaEntryTypes.java | 35 ++ .../shedaniel/rei/api/favorites/FavoriteEntry.java | 110 ++++ .../rei/api/favorites/FavoriteEntryType.java | 79 +++ .../rei/api/favorites/FavoriteMenuEntry.java | 46 ++ .../shedaniel/rei/api/favorites/package-info.java | 27 + .../rei/api/fluid/FluidSupportProvider.java | 60 ++ .../me/shedaniel/rei/api/plugins/REIPluginV0.java | 96 ++++ .../shedaniel/rei/api/subsets/SubsetsRegistry.java | 68 +++ .../java/me/shedaniel/rei/api/widgets/Arrow.java | 88 +++ .../me/shedaniel/rei/api/widgets/BaseWidget.java | 53 ++ .../me/shedaniel/rei/api/widgets/BurningFire.java | 88 +++ .../java/me/shedaniel/rei/api/widgets/Button.java | 186 ++++++ .../java/me/shedaniel/rei/api/widgets/Label.java | 324 +++++++++++ .../java/me/shedaniel/rei/api/widgets/Panel.java | 78 +++ .../java/me/shedaniel/rei/api/widgets/Slot.java | 159 ++++++ .../java/me/shedaniel/rei/api/widgets/Tooltip.java | 69 +++ .../java/me/shedaniel/rei/api/widgets/Widgets.java | 212 +++++++ .../shedaniel/rei/gui/config/AppearanceTheme.java | 44 ++ .../rei/gui/config/ConfigButtonPosition.java | 44 ++ .../rei/gui/config/DisplayPanelLocation.java | 49 ++ .../rei/gui/config/EntryPanelOrdering.java | 40 ++ .../rei/gui/config/EntryPanelOrderingConfig.java | 64 +++ .../shedaniel/rei/gui/config/ItemCheatingMode.java | 41 ++ .../rei/gui/config/ItemCheatingStyle.java | 44 ++ .../shedaniel/rei/gui/config/RecipeBorderType.java | 62 ++ .../shedaniel/rei/gui/config/RecipeScreenType.java | 44 ++ .../rei/gui/config/SearchFieldLocation.java | 42 ++ .../shedaniel/rei/gui/entries/RecipeRenderer.java | 44 ++ .../rei/gui/entries/SimpleRecipeRenderer.java | 159 ++++++ .../shedaniel/rei/gui/widget/TextFieldWidget.java | 631 +++++++++++++++++++++ .../java/me/shedaniel/rei/gui/widget/Widget.java | 74 +++ .../shedaniel/rei/gui/widget/WidgetWithBounds.java | 39 ++ .../main/java/me/shedaniel/rei/impl/Internals.java | 225 ++++++++ .../java/me/shedaniel/rei/impl/RenderingEntry.java | 115 ++++ .../me/shedaniel/rei/server/ContainerContext.java | 39 ++ .../me/shedaniel/rei/server/ContainerInfo.java | 118 ++++ .../shedaniel/rei/server/ContainerInfoHandler.java | 56 ++ .../java/me/shedaniel/rei/server/DumpHandler.java | 58 ++ .../me/shedaniel/rei/server/GridCleanHandler.java | 50 ++ .../shedaniel/rei/server/GridStacksProvider.java | 31 + .../rei/server/InventoryStackAccessor.java | 52 ++ .../java/me/shedaniel/rei/server/RecipeFinder.java | 341 +++++++++++ .../rei/server/RecipeFinderPopulator.java | 35 ++ .../me/shedaniel/rei/server/RecipeGridAligner.java | 44 ++ .../me/shedaniel/rei/server/SlotStackAccessor.java | 50 ++ .../me/shedaniel/rei/server/StackAccessor.java | 34 ++ .../me/shedaniel/rei/utils/CollectionUtils.java | 315 ++++++++++ .../rei/utils/EntryStackCompoundList.java | 44 ++ .../me/shedaniel/rei/utils/FormattingUtils.java | 48 ++ .../shedaniel/rei/utils/ImmutableLiteralText.java | 98 ++++ api/src/main/resources/fabric.mod.json | 20 + api/src/main/resources/icon.png | Bin 0 -> 27270 bytes 91 files changed, 8160 insertions(+) create mode 100644 api/build.gradle create mode 100644 api/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/BuiltinPlugin.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ButtonAreaSupplier.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ClickAreaHandler.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ClientHelper.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ConfigManager.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ConfigObject.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/DisplayHelper.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/EntryRegistry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/EntryStack.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/FocusedStackProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/LiveRecipeGenerator.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/OverlayDecider.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/REIHelper.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/REIOverlay.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/RecipeCategory.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/RecipeHelper.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/Renderer.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ScreenClickAreaProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/TextRepresentable.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/TransferRecipeCategory.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/TransferRecipeDisplay.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/entry/AbstractEntryRenderer.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/entry/AbstractRenderer.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/entry/BatchEntryRenderer.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/entry/BuiltinEntryTypes.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/entry/ComparisonContext.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/entry/EntryDefinition.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/entry/EntryRenderer.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/entry/EntryStacks.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/entry/EntryType.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/entry/EntryTypeBridge.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/entry/EntryTypeRegistry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/entry/VanillaEntryTypes.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteEntry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteEntryType.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteMenuEntry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/favorites/package-info.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/fluid/FluidSupportProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/subsets/SubsetsRegistry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/widgets/Arrow.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/widgets/BaseWidget.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/widgets/BurningFire.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/widgets/Button.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/widgets/Label.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/widgets/Panel.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/widgets/Slot.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/widgets/Tooltip.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/widgets/Widgets.java create mode 100644 api/src/main/java/me/shedaniel/rei/gui/config/AppearanceTheme.java create mode 100644 api/src/main/java/me/shedaniel/rei/gui/config/ConfigButtonPosition.java create mode 100644 api/src/main/java/me/shedaniel/rei/gui/config/DisplayPanelLocation.java create mode 100644 api/src/main/java/me/shedaniel/rei/gui/config/EntryPanelOrdering.java create mode 100644 api/src/main/java/me/shedaniel/rei/gui/config/EntryPanelOrderingConfig.java create mode 100644 api/src/main/java/me/shedaniel/rei/gui/config/ItemCheatingMode.java create mode 100644 api/src/main/java/me/shedaniel/rei/gui/config/ItemCheatingStyle.java create mode 100644 api/src/main/java/me/shedaniel/rei/gui/config/RecipeBorderType.java create mode 100644 api/src/main/java/me/shedaniel/rei/gui/config/RecipeScreenType.java create mode 100644 api/src/main/java/me/shedaniel/rei/gui/config/SearchFieldLocation.java create mode 100644 api/src/main/java/me/shedaniel/rei/gui/entries/RecipeRenderer.java create mode 100644 api/src/main/java/me/shedaniel/rei/gui/entries/SimpleRecipeRenderer.java create mode 100644 api/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java create mode 100644 api/src/main/java/me/shedaniel/rei/gui/widget/Widget.java create mode 100644 api/src/main/java/me/shedaniel/rei/gui/widget/WidgetWithBounds.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/Internals.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/RenderingEntry.java create mode 100644 api/src/main/java/me/shedaniel/rei/server/ContainerContext.java create mode 100644 api/src/main/java/me/shedaniel/rei/server/ContainerInfo.java create mode 100644 api/src/main/java/me/shedaniel/rei/server/ContainerInfoHandler.java create mode 100644 api/src/main/java/me/shedaniel/rei/server/DumpHandler.java create mode 100644 api/src/main/java/me/shedaniel/rei/server/GridCleanHandler.java create mode 100644 api/src/main/java/me/shedaniel/rei/server/GridStacksProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/server/InventoryStackAccessor.java create mode 100644 api/src/main/java/me/shedaniel/rei/server/RecipeFinder.java create mode 100644 api/src/main/java/me/shedaniel/rei/server/RecipeFinderPopulator.java create mode 100644 api/src/main/java/me/shedaniel/rei/server/RecipeGridAligner.java create mode 100644 api/src/main/java/me/shedaniel/rei/server/SlotStackAccessor.java create mode 100644 api/src/main/java/me/shedaniel/rei/server/StackAccessor.java create mode 100644 api/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java create mode 100644 api/src/main/java/me/shedaniel/rei/utils/EntryStackCompoundList.java create mode 100644 api/src/main/java/me/shedaniel/rei/utils/FormattingUtils.java create mode 100644 api/src/main/java/me/shedaniel/rei/utils/ImmutableLiteralText.java create mode 100644 api/src/main/resources/fabric.mod.json create mode 100644 api/src/main/resources/icon.png (limited to 'api') diff --git a/api/build.gradle b/api/build.gradle new file mode 100644 index 000000000..598a85f5a --- /dev/null +++ b/api/build.gradle @@ -0,0 +1 @@ +archivesBaseName = "api" \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java b/api/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java new file mode 100644 index 000000000..743538410 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java @@ -0,0 +1,286 @@ +/* + * 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 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 { + + /** + * @return the priority of this handler, higher priorities will be called first. + */ + default double getPriority() { + return 0d; + } + + @NotNull + Result handle(@NotNull Context context); + + @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 TransferRecipeCategory}. + */ + 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 TransferRecipeCategory}. + */ + 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 TransferRecipeCategory}. + */ + IntList getIntegers(); + } + + @ApiStatus.NonExtendable + interface Context { + static Context create(boolean actuallyCrafting, AbstractContainerScreen containerScreen, RecipeDisplay recipeDisplay) { + return new ContextImpl(actuallyCrafting, containerScreen, () -> recipeDisplay); + } + + default Minecraft getMinecraft() { + return Minecraft.getInstance(); + } + + boolean isActuallyCrafting(); + + @Nullable + AbstractContainerScreen getContainerScreen(); + + RecipeDisplay 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 RecipeDisplay getRecipe() { + return recipeDisplaySupplier.get(); + } + } + +} diff --git a/api/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java b/api/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java new file mode 100644 index 000000000..0448bc297 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java @@ -0,0 +1,62 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api; + +import me.shedaniel.math.Rectangle; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + +import java.util.List; +import java.util.function.Supplier; + +@Environment(EnvType.CLIENT) +public interface BaseBoundsHandler extends OverlayDecider { + + static BaseBoundsHandler getInstance() { + return DisplayHelper.getInstance().getBaseBoundsHandler(); + } + + /** + * Gets the exclusion zones by the screen class + * + * @param currentScreenClass the current screen class + * @return the list of exclusion zones + */ + default List getExclusionZones(Class currentScreenClass) { + return getExclusionZones(currentScreenClass, false); + } + + List getExclusionZones(Class currentScreenClass, boolean sort); + + int supplierSize(); + + /** + * Register an exclusion zone + * + * @param screenClass the screen + * @param supplier the exclusion zone supplier, returns the list of exclusion zones + */ + void registerExclusionZones(Class screenClass, Supplier> supplier); + +} diff --git a/api/src/main/java/me/shedaniel/rei/api/BuiltinPlugin.java b/api/src/main/java/me/shedaniel/rei/api/BuiltinPlugin.java new file mode 100644 index 000000000..f0d3b112a --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/BuiltinPlugin.java @@ -0,0 +1,70 @@ +/* + * 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.impl.Internals; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; + +import java.util.Collections; +import java.util.List; +import java.util.function.UnaryOperator; + +public interface BuiltinPlugin { + ResourceLocation CRAFTING = new ResourceLocation("minecraft", "plugins/crafting"); + ResourceLocation SMELTING = new ResourceLocation("minecraft", "plugins/smelting"); + ResourceLocation SMOKING = new ResourceLocation("minecraft", "plugins/smoking"); + ResourceLocation BLASTING = new ResourceLocation("minecraft", "plugins/blasting"); + ResourceLocation CAMPFIRE = new ResourceLocation("minecraft", "plugins/campfire"); + ResourceLocation STONE_CUTTING = new ResourceLocation("minecraft", "plugins/stone_cutting"); + ResourceLocation STRIPPING = new ResourceLocation("minecraft", "plugins/stripping"); + ResourceLocation BREWING = new ResourceLocation("minecraft", "plugins/brewing"); + ResourceLocation PLUGIN = new ResourceLocation("roughlyenoughitems", "default_plugin"); + ResourceLocation COMPOSTING = new ResourceLocation("minecraft", "plugins/composting"); + ResourceLocation FUEL = new ResourceLocation("minecraft", "plugins/fuel"); + ResourceLocation SMITHING = new ResourceLocation("minecraft", "plugins/smithing"); + ResourceLocation BEACON = new ResourceLocation("minecraft", "plugins/beacon"); + ResourceLocation BEACON_PAYMENT = new ResourceLocation("minecraft", "plugins/beacon_payment"); + ResourceLocation TILLING = new ResourceLocation("minecraft", "plugins/tilling"); + ResourceLocation PATHING = new ResourceLocation("minecraft", "plugins/pathing"); + ResourceLocation INFO = new ResourceLocation("roughlyenoughitems", "plugins/information"); + + static BuiltinPlugin getInstance() { + return Internals.getBuiltinPlugin(); + } + + default void registerBrewingRecipe(ItemStack input, Ingredient ingredient, ItemStack output) { + registerBrewingRecipe(Ingredient.of(input), ingredient, output); + } + + void registerBrewingRecipe(Ingredient input, Ingredient ingredient, ItemStack output); + + void registerInformation(List> entryStacks, Component name, UnaryOperator> textBuilder); + + default void registerInformation(EntryStack entryStack, Component name, UnaryOperator> textBuilder) { + registerInformation(Collections.singletonList(entryStack), name, textBuilder); + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/ButtonAreaSupplier.java b/api/src/main/java/me/shedaniel/rei/api/ButtonAreaSupplier.java new file mode 100644 index 000000000..df6214642 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ButtonAreaSupplier.java @@ -0,0 +1,50 @@ +/* + * 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. + */ +public interface ButtonAreaSupplier { + + /** + * 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/ClickAreaHandler.java b/api/src/main/java/me/shedaniel/rei/api/ClickAreaHandler.java new file mode 100644 index 000000000..40a0624b4 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ClickAreaHandler.java @@ -0,0 +1,68 @@ +/* + * 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 new file mode 100644 index 000000000..36b61033a --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -0,0 +1,216 @@ +/* + * 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.impl.Internals; +import me.shedaniel.rei.utils.CollectionUtils; +import me.shedaniel.rei.utils.FormattingUtils; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.chat.NarratorChatListener; +import net.minecraft.core.Registry; +import net.minecraft.network.chat.Component; +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} + */ + static ClientHelper getInstance() { + return Internals.getClientHelper(); + } + + /** + * Checks if cheating is enabled + * + * @return whether cheating is enabled + */ + boolean isCheating(); + + /** + * Sets current cheating mode + * Should save the config in {@link ConfigManager}. + * + * @param cheating the new cheating mode + */ + void setCheating(boolean cheating); + + /** + * Tries to cheat stack using either packets or commands. + * + * @param stack the stack to cheat in + * @return whether it failed + */ + boolean tryCheatingEntry(EntryStack stack); + + /** + * Gets the mod from an item + * + * @param item the item to find + * @return the mod name + */ + default String getModFromItem(Item item) { + if (item.equals(Items.AIR)) + return ""; + return getModFromIdentifier(Registry.ITEM.getKey(item)); + } + + /** + * Tries to delete the player's cursor item + */ + void sendDeletePacket(); + + /** + * Gets the formatted mod from an item + * + * @param item the item to find + * @return the mod name with blue and italic formatting + */ + default Component getFormattedModFromItem(Item item) { + String mod = getModFromItem(item); + if (mod.isEmpty()) + return NarratorChatListener.NO_TITLE; + return new TextComponent(mod).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC); + } + + /** + * Gets the formatted mod from an identifier + * + * @param identifier the identifier to find + * @return the mod name with blue and italic formatting + */ + default Component getFormattedModFromIdentifier(ResourceLocation identifier) { + String mod = getModFromIdentifier(identifier); + if (mod.isEmpty()) + return NarratorChatListener.NO_TITLE; + return new TextComponent(mod).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC); + } + + /** + * Gets the mod from a modid + * + * @param modid the modid of the mod + * @return the mod name with blue and italic formatting + */ + default Component getFormattedModFromModId(String modid) { + String mod = getModFromModId(modid); + if (mod.isEmpty()) + return NarratorChatListener.NO_TITLE; + return new TextComponent(mod).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC); + } + + default List appendModIdToTooltips(List components, String modId) { + final String modName = ClientHelper.getInstance().getModFromModId(modId); + boolean alreadyHasMod = false; + for (Component s : components) + if (FormattingUtils.stripFormatting(s.getString()).equalsIgnoreCase(modName)) { + alreadyHasMod = true; + break; + } + if (!alreadyHasMod) + components.add(ClientHelper.getInstance().getFormattedModFromModId(modId)); + return components; + } + + /** + * Gets the mod from an identifier + * + * @param identifier the identifier to find + * @return the mod name + */ + default String getModFromIdentifier(ResourceLocation identifier) { + if (identifier == null) + return ""; + return getModFromModId(identifier.getNamespace()); + } + + /** + * Gets the mod from a modid + * + * @param modId the modid of the mod + * @return the mod name + */ + String getModFromModId(String modId); + + 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(RecipeHelper.getInstance().getAllCategories(), RecipeCategory::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 new file mode 100644 index 000000000..85565a53c --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/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; + +import me.shedaniel.rei.impl.Internals; +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 { + + /** + * @return the instance of {@link me.shedaniel.rei.api.ConfigManager} + */ + @NotNull + static ConfigManager getInstance() { + return Internals.getConfigManager(); + } + + /** + * 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 new file mode 100644 index 000000000..d8210bbc2 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ConfigObject.java @@ -0,0 +1,162 @@ +/* + * 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.gui.config.*; +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(); +} diff --git a/api/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/api/src/main/java/me/shedaniel/rei/api/DisplayHelper.java new file mode 100644 index 000000000..d63896203 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -0,0 +1,100 @@ +/* + * 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.gui.config.DisplayPanelLocation; +import me.shedaniel.rei.impl.Internals; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +@Environment(EnvType.CLIENT) +public interface DisplayHelper { + + /** + * @return the instance of {@link me.shedaniel.rei.api.DisplayHelper} + */ + @NotNull + static DisplayHelper getInstance() { + return Internals.getDisplayHelper(); + } + + List getSortedOverlayDeciders(Class screenClass); + + /** + * Gets all registered overlay deciders + * + * @return the list of registered overlay deciders + */ + List getAllOverlayDeciders(); + + /** + * Registers a bounds decider + * + * @param decider the decider to register + */ + void registerHandler(OverlayDecider decider); + + default void registerProvider(DisplayBoundsProvider provider) { + registerHandler(provider); + } + + /** + * Gets the left bounds of the overlay + * + * @param screen the current screen + * @return the left bounds + */ + Rectangle getOverlayBounds(DisplayPanelLocation location, T screen); + + @ApiStatus.Experimental + void resetCache(); + + @ApiStatus.Internal + BaseBoundsHandler getBaseBoundsHandler(); + + interface DisplayBoundsProvider extends OverlayDecider { + /** + * @param screen the screen + * @return the boundary of the base container panel. + */ + Rectangle getScreenBounds(T screen); + + /** + * Gets the base supported class for the bounds handler + * + * @return the base class + */ + Class getBaseSupportedClass(); + + @Override + default boolean isHandingScreen(Class screen) { + return getBaseSupportedClass().isAssignableFrom(screen); + } + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java b/api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java new file mode 100644 index 000000000..82d5c901f --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java @@ -0,0 +1,51 @@ +/* + * 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 net.minecraft.world.InteractionResult; + +public interface DisplayVisibilityHandler { + + /** + * 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(RecipeCategory category, RecipeDisplay display); + +} diff --git a/api/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java b/api/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java new file mode 100644 index 000000000..30d65028a --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java @@ -0,0 +1,35 @@ +/* + * 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 com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.gui.GuiComponent; +import org.jetbrains.annotations.NotNull; + +/** + * Consumer of a {@link DrawableHelper} and information of mouse and delta. + */ +public interface DrawableConsumer { + void render(@NotNull GuiComponent helper, @NotNull PoseStack matrices, int mouseX, int mouseY, float delta); +} diff --git a/api/src/main/java/me/shedaniel/rei/api/EntryRegistry.java b/api/src/main/java/me/shedaniel/rei/api/EntryRegistry.java new file mode 100644 index 000000000..d93701e09 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/EntryRegistry.java @@ -0,0 +1,125 @@ +/* + * 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.impl.Internals; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Stream; + +@Environment(EnvType.CLIENT) +public interface EntryRegistry { + + /** + * @return the instance of {@link me.shedaniel.rei.api.EntryRegistry} + */ + @NotNull + static EntryRegistry getInstance() { + return Internals.getEntryRegistry(); + } + + @NotNull + Stream> getEntryStacks(); + + @NotNull + List> getPreFilteredList(); + + @ApiStatus.Experimental + void refilter(); + + @NotNull + List appendStacksForItem(@NotNull Item item); + + /** + * Gets all possible stacks from an item + * + * @param item the item to find + * @return the array of possible stacks + */ + @NotNull + ItemStack[] getAllStacksFromItem(@NotNull Item item); + + default void registerEntry(@NotNull EntryStack stack) { + registerEntryAfter(null, stack); + } + + /** + * Registers an new stack to the entry list + * + * @param afterEntry the stack to put after + * @param stack the stack to register + */ + void registerEntryAfter(@Nullable EntryStack afterEntry, @NotNull EntryStack stack); + + /** + * Registers multiple stacks to the item list + * + * @param afterStack the stack to put after + * @param stacks the stacks to register + */ + default void registerEntriesAfter(@Nullable EntryStack afterStack, @NotNull EntryStack... stacks) { + registerEntriesAfter(afterStack, Arrays.asList(stacks)); + } + + /** + * Registers multiple stacks to the item list + * + * @param afterStack the stack to put after + * @param stacks the stacks to register + */ + void registerEntriesAfter(@Nullable EntryStack afterStack, @NotNull Collection<@NotNull ? extends EntryStack> stacks); + + /** + * Registers multiple stacks to the item list + * + * @param stacks the stacks to register + */ + default void registerEntries(@NotNull EntryStack... stacks) { + registerEntriesAfter(null, stacks); + } + + /** + * Checks if a stack is already registered + * + * @param stack the stack to check + * @return whether the stack has been registered + */ + boolean alreadyContain(EntryStack stack); + + @ApiStatus.Experimental + void removeEntry(EntryStack stack); + + @ApiStatus.Experimental + void removeEntryIf(Predicate> stackPredicate); +} diff --git a/api/src/main/java/me/shedaniel/rei/api/EntryStack.java b/api/src/main/java/me/shedaniel/rei/api/EntryStack.java new file mode 100644 index 000000000..19204804f --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/EntryStack.java @@ -0,0 +1,203 @@ +/* + * 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 com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.mojang.serialization.Dynamic; +import com.mojang.serialization.JsonOps