From ba446965dad004cb38679f0f0e1a526151d84213 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 29 Jul 2020 12:25:47 +0800 Subject: 5.x - 20w30a Signed-off-by: shedaniel --- .../me/shedaniel/rei/api/AutoTransferHandler.java | 304 ++++++++++ .../me/shedaniel/rei/api/BaseBoundsHandler.java | 62 ++ .../me/shedaniel/rei/api/ButtonAreaSupplier.java | 50 ++ .../java/me/shedaniel/rei/api/ClientHelper.java | 249 ++++++++ .../java/me/shedaniel/rei/api/ConfigManager.java | 80 +++ .../java/me/shedaniel/rei/api/ConfigObject.java | 167 ++++++ .../java/me/shedaniel/rei/api/DisplayHelper.java | 221 +++++++ .../rei/api/DisplayVisibilityHandler.java | 51 ++ .../me/shedaniel/rei/api/DrawableConsumer.java | 35 ++ .../java/me/shedaniel/rei/api/EntryRegistry.java | 158 +++++ .../main/java/me/shedaniel/rei/api/EntryStack.java | 372 ++++++++++++ .../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 | 69 +++ .../main/java/me/shedaniel/rei/api/REIOverlay.java | 31 + .../java/me/shedaniel/rei/api/REIPluginEntry.java | 58 ++ .../java/me/shedaniel/rei/api/RecipeCategory.java | 125 ++++ .../java/me/shedaniel/rei/api/RecipeDisplay.java | 69 +++ .../java/me/shedaniel/rei/api/RecipeHelper.java | 274 +++++++++ .../me/shedaniel/rei/api/TextRepresentable.java | 51 ++ .../main/java/me/shedaniel/rei/api/TextTest.java | 39 ++ .../shedaniel/rei/api/TransferRecipeCategory.java | 37 ++ .../shedaniel/rei/api/TransferRecipeDisplay.java | 45 ++ .../rei/api/fluid/FluidSupportProvider.java | 82 +++ .../me/shedaniel/rei/api/fractions/Fraction.java | 186 ++++++ .../me/shedaniel/rei/api/plugins/REIPluginV0.java | 88 +++ .../shedaniel/rei/api/subsets/SubsetsRegistry.java | 102 ++++ .../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 | 325 +++++++++++ .../java/me/shedaniel/rei/api/widgets/Panel.java | 102 ++++ .../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 | 213 +++++++ .../shedaniel/rei/gui/config/AppearanceTheme.java | 43 ++ .../rei/gui/config/ConfigButtonPosition.java | 43 ++ .../rei/gui/config/DisplayPanelLocation.java | 48 ++ .../rei/gui/config/EntryPanelOrdering.java | 41 ++ .../rei/gui/config/EntryPanelOrderingConfig.java | 64 +++ .../shedaniel/rei/gui/config/ItemCheatingMode.java | 41 ++ .../rei/gui/config/ItemCheatingStyle.java | 43 ++ .../shedaniel/rei/gui/config/RecipeBorderType.java | 62 ++ .../shedaniel/rei/gui/config/RecipeScreenType.java | 44 ++ .../rei/gui/config/SearchFieldLocation.java | 42 ++ .../me/shedaniel/rei/gui/entries/RecipeEntry.java | 36 ++ .../rei/gui/entries/SimpleRecipeEntry.java | 150 +++++ .../shedaniel/rei/gui/widget/TextFieldWidget.java | 634 +++++++++++++++++++++ .../java/me/shedaniel/rei/gui/widget/Widget.java | 75 +++ .../shedaniel/rei/gui/widget/WidgetWithBounds.java | 39 ++ .../main/java/me/shedaniel/rei/impl/Internals.java | 161 ++++++ .../java/me/shedaniel/rei/impl/RenderingEntry.java | 140 +++++ .../me/shedaniel/rei/server/ContainerInfo.java | 40 ++ .../shedaniel/rei/server/ContainerInfoHandler.java | 66 +++ .../java/me/shedaniel/rei/server/RecipeFinder.java | 347 +++++++++++ .../me/shedaniel/rei/server/RecipeGridAligner.java | 78 +++ .../me/shedaniel/rei/utils/CollectionUtils.java | 285 +++++++++ 59 files changed, 6969 insertions(+) create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ButtonAreaSupplier.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ClientHelper.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigManager.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/DisplayHelper.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryRegistry.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/FocusedStackProvider.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/LiveRecipeGenerator.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/OverlayDecider.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/REIHelper.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/REIOverlay.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/RecipeCategory.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/RecipeHelper.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/TextRepresentable.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/TextTest.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/TransferRecipeCategory.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/TransferRecipeDisplay.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/fluid/FluidSupportProvider.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/fractions/Fraction.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/subsets/SubsetsRegistry.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/widgets/Arrow.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/widgets/BaseWidget.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/widgets/BurningFire.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/widgets/Button.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/widgets/Label.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/widgets/Panel.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/widgets/Slot.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/widgets/Tooltip.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/widgets/Widgets.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/config/AppearanceTheme.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/config/ConfigButtonPosition.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/config/DisplayPanelLocation.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/config/EntryPanelOrdering.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/config/EntryPanelOrderingConfig.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/config/ItemCheatingMode.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/config/ItemCheatingStyle.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/config/RecipeBorderType.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/config/RecipeScreenType.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/config/SearchFieldLocation.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/entries/RecipeEntry.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/entries/SimpleRecipeEntry.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/widget/Widget.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/widget/WidgetWithBounds.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/impl/Internals.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/impl/RenderingEntry.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/ContainerInfo.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/ContainerInfoHandler.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/RecipeFinder.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/server/RecipeGridAligner.java create mode 100644 RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java (limited to 'RoughlyEnoughItems-api/src/main/java') diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java new file mode 100644 index 000000000..45341c88e --- /dev/null +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java @@ -0,0 +1,304 @@ +/* + * 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.MinecraftClient; +import net.minecraft.client.gui.screen.ingame.ContainerScreen; +import net.minecraft.container.Container; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +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); + + interface Result { + /** + * Creates a successful result, no further handlers will be called. + */ + static Result createSuccessful() { + return new ResultImpl(); + } + + /** + * Creates a successful result, no further handlers will be called. + * Will return to the previous screen rather than staying open. + * + * @deprecated use {@link #blocksFurtherHandling(boolean)} + */ + @Deprecated + static Result createSuccessfulReturningToScreen() { + return createSuccessful().blocksFurtherHandling(true); + } + + /** + * 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(); + } + + interface Context { + static Context create(boolean actuallyCrafting, ContainerScreen containerScreen, RecipeDisplay recipeDisplay) { + return new ContextImpl(actuallyCrafting, containerScreen, () -> recipeDisplay); + } + + default MinecraftClient getMinecraft() { + return MinecraftClient.getInstance(); + } + + boolean isActuallyCrafting(); + + ContainerScreen getContainerScreen(); + + @Deprecated + @ApiStatus.ScheduledForRemoval + default ContainerScreen getHandledScreen() { + return getContainerScreen(); + } + + RecipeDisplay getRecipe(); + + @Deprecated + @ApiStatus.ScheduledForRemoval + default Container getScreenHandler() { + return getContainer(); + } + + default Container getContainer() { + return getHandledScreen().getContainer(); + } + } + + @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 ContainerScreen containerScreen; + private Supplier recipeDisplaySupplier; + + private ContextImpl(boolean actuallyCrafting, ContainerScreen containerScreen, Supplier recipeDisplaySupplier) { + this.actuallyCrafting = actuallyCrafting; + this.containerScreen = containerScreen; + this.recipeDisplaySupplier = recipeDisplaySupplier; + } + + @Override + public boolean isActuallyCrafting() { + return actuallyCrafting; + } + + @Override + public ContainerScreen getContainerScreen() { + return containerScreen; + } + + @Override + public RecipeDisplay getRecipe() { + return recipeDisplaySupplier.get(); + } + } + +} diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java new file mode 100644 index 000000000..0448bc297 --- /dev/null +++ b/RoughlyEnoughItems-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/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ButtonAreaSupplier.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ButtonAreaSupplier.java new file mode 100644 index 000000000..df6214642 --- /dev/null +++ b/RoughlyEnoughItems-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/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ClientHelper.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ClientHelper.java new file mode 100644 index 000000000..2cfcf3ff7 --- /dev/null +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -0,0 +1,249 @@ +/* + * 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 net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.ApiStatus; +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); + + List getInventoryItemsTypes(); + + /** + * Opens a recipe viewing screen: + * Opens {@link me.shedaniel.rei.gui.PreRecipeViewingScreen} if not set + * Opens {@link me.shedaniel.rei.gui.RecipeViewingScreen} if set to default + * Opens {@link me.shedaniel.rei.gui.VillagerRecipeViewingScreen} if set to villager + * + * @param map the map of recipes + */ + @ApiStatus.ScheduledForRemoval + @Deprecated + void openRecipeViewingScreen(Map, List> map); + + /** + * Tries to cheat stack using either packets or commands. + * + * @param stack the stack to cheat in + * @return whether it failed + */ + boolean tryCheatingEntry(EntryStack stack); + + default boolean tryCheatingStack(ItemStack stack) { + return tryCheatingEntry(EntryStack.create(stack)); + } + + /** + * Finds recipe for the stack and opens the recipe screen. + * + * @param stack the stack to find recipe for + * @return whether the stack has any recipes to show + */ + @Deprecated + @ApiStatus.ScheduledForRemoval + default boolean executeRecipeKeyBind(EntryStack stack) { + return openView(ViewSearchBuilder.builder().addRecipesFor(stack).setOutputNotice(stack).fillPreferredOpenedCategory()); + } + + @Deprecated + @ApiStatus.ScheduledForRemoval + default boolean executeRecipeKeyBind(ItemStack stack) { + return executeRecipeKeyBind(EntryStack.create(stack)); + } + + /** + * Finds usage for the stack and opens the recipe screen. + * + * @param stack the stack to find usage for + * @return whether the stack has any usages to show + */ + @Deprecated + @ApiStatus.ScheduledForRemoval + default boolean executeUsageKeyBind(EntryStack stack) { + return openView(ViewSearchBuilder.builder().addUsagesFor(stack).setInputNotice(stack).fillPreferredOpenedCategory()); + } + + @Deprecated + @ApiStatus.ScheduledForRemoval + default boolean executeUsageKeyBind(ItemStack stack) { + return executeUsageKeyBind(EntryStack.create(stack)); + } + + /** + * Gets the mod from an item + * + * @param item the item to find + * @return the mod name + */ + String getModFromItem(Item 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 + */ + Text getFormattedModFromItem(Item item); + + /** + * Gets the formatted mod from an identifier + * + * @param identifier the identifier to find + * @return the mod name with blue and italic formatting + */ + Text getFormattedModFromIdentifier(Identifier identifier); + + /** + * Gets the mod from an identifier + * + * @param identifier the identifier to find + * @return the mod name + */ + default String getModFromIdentifier(Identifier 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); + + /** + * Finds all recipes and open them in a recipe screen. + * + * @return whether there are any recipes to show + */ + @Deprecated + @ApiStatus.ScheduledForRemoval + default boolean executeViewAllRecipesKeyBind() { + return openView(ViewSearchBuilder.builder().addAllCategories().fillPreferredOpenedCategory()); + } + + @Deprecated + @ApiStatus.ScheduledForRemoval + default boolean executeViewAllRecipesFromCategory(Identifier category) { + return openView(ViewSearchBuilder.builder().addCategory(category).fillPreferredOpenedCategory()); + } + + @Deprecated + @ApiStatus.ScheduledForRemoval + default boolean executeViewAllRecipesFromCategories(List categories) { + return openView(ViewSearchBuilder.builder().addCategories(categories).fillPreferredOpenedCategory()); + } + + boolean openView(ViewSearchBuilder builder); + + boolean canUseMovePackets(); + + interface ViewSearchBuilder { + static ViewSearchBuilder builder() { + return Internals.createViewSearchBuilder(); + } + + ViewSearchBuilder addCategory(Identifier 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 Identifier category); + + @Nullable + Identifier 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/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigManager.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigManager.java new file mode 100644 index 000000000..011b53a12 --- /dev/null +++ b/RoughlyEnoughItems-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.MinecraftClient; +import net.minecraft.client.gui.screen.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) { + MinecraftClient.getInstance().openScreen(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/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java new file mode 100644 index 000000000..4073d626d --- /dev/null +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java @@ -0,0 +1,167 @@ +/* + * 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.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 isToastDisplayedOnCopyIdentifier(); + + boolean doesRenderEntryEnchantmentGlint(); + + boolean isEntryListWidgetScrolled(); + + boolean shouldAppendModNames(); + + RecipeScreenType getRecipeScreenType(); + + void setRecipeScreenType(RecipeScreenType recipeScreenType); + + @Deprecated + @ApiStatus.ScheduledForRemoval + boolean isLoadingDefaultPlugin(); + + 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(); + + @Deprecated + @ApiStatus.ScheduledForRemoval + default boolean doDisplayFavoritesOnTheLeft() { + return true; + } + + boolean doesFastEntryRendering(); + + boolean doDebugRenderTimeRequired(); + + boolean doSearchFavorites(); + + ModifierKeyCode getFavoriteKeyCode(); + + ModifierKeyCode getRecipeKeybind(); + + ModifierKeyCode getUsageKeybind(); + + ModifierKeyCode getHideKeybind(); + + ModifierKeyCode getPreviousPageKeybind(); + + ModifierKeyCode getNextPageKeybind(); + + ModifierKeyCode getFocusSearchFieldKeybind(); + + ModifierKeyCode getCopyRecipeIdentifierKeybind(); + + ModifierKeyCode getExportImageKeybind(); + + double getEntrySize(); + + boolean isUsingCompactTabs(); + + boolean isLowerConfigButton(); + + List getFavorites(); + + List getFilteredStacks(); + + @ApiStatus.Experimental + boolean shouldAsyncSearch(); + + @ApiStatus.Experimental + int getNumberAsyncSearch(); + + @ApiStatus.Experimental + boolean doDebugSearchTimeRequired(); + + @ApiStatus.Experimental + boolean isSubsetsEnabled(); + + boolean shouldResizeDynamically(); +} diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/DisplayHelper.java new file mode 100644 index 000000000..94d3cf9d6 --- /dev/null +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -0,0 +1,221 @@ +/* + * 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.gui.config.SearchFieldLocation; +import me.shedaniel.rei.impl.Internals; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.util.ActionResult; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.function.Supplier; + +import static net.minecraft.util.ActionResult.PASS; + +@Environment(EnvType.CLIENT) +public interface DisplayHelper { + + /** + * @return the instance of {@link me.shedaniel.rei.api.DisplayHelper} + */ + @NotNull + static DisplayHelper getInstance() { + return Internals.getDisplayHelper(); + } + + /** + * Gets the sorted version of all responsible bounds handlers + * + * @param screenClass the class for checking responsible bounds handlers + * @return the sorted list of responsible bounds handlers + * @see DisplayHelper#getResponsibleBoundsHandler(Class) for the unsorted version + */ + @Deprecated + @ApiStatus.ScheduledForRemoval + List> getSortedBoundsHandlers(Class screenClass); + + List getSortedOverlayDeciders(Class screenClass); + + /** + * Gets all registered overlay deciders + * + * @return the list of registered overlay deciders + */ + List getAllOverlayDeciders(); + + /** + * Gets the responsible bounds handlers + * + * @param screenClass the class for checking responsible bounds handlers + * @return the the list of responsible bounds handlers + * @see DisplayHelper#getSortedBoundsHandlers(Class) for the sorted version + */ + @Deprecated + @ApiStatus.ScheduledForRemoval + DisplayBoundsHandler getResponsibleBoundsHandler(Class screenClass); + + /** + * 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); + } + } + + @Deprecated + @ApiStatus.ScheduledForRemoval + interface DisplayBoundsHandler extends OverlayDecider { + /** + * 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); + } + + /** + * Gets the left bounds of the overlay + * + * @param screen the current screen + * @return the left bounds + */ + Rectangle getLeftBounds(T screen); + + /** + * Gets the right bounds of the overlay + * + * @param screen the current screen + * @return the right bounds + */ + Rectangle getRightBounds(T screen); + + /** + * Checks if item slot can fit the screen + * + * @param left the left x coordinates of the stack + * @param top the top y coordinates for the stack + * @param screen the current screen + * @param fullBounds the current bounds + * @return whether the item slot can fit + * @see BaseBoundsHandler#registerExclusionZones(Class, Supplier) for easier api + */ + default ActionResult canItemSlotWidgetFit(int left, int top, T screen, Rectangle fullBounds) { + ActionResult fit = isInZone(left, top); + if (fit == ActionResult.FAIL) + return ActionResult.FAIL; + ActionResult fit2 = isInZone(left + 18, top + 18); + if (fit2 == ActionResult.FAIL) + return ActionResult.FAIL; + if (fit == ActionResult.SUCCESS && fit2 == ActionResult.SUCCESS) + return ActionResult.SUCCESS; + return PASS; + } + + @Override + default ActionResult isInZone(double mouseX, double mouseY) { + return OverlayDecider.super.isInZone(mouseX, mouseY); + } + + /** + * Gets the item list bounds by the overlay bounds + * + * @param rectangle the overlay bounds + * @return the item list bounds + */ + default Rectangle getItemListArea(Rectangle rectangle) { + return new Rectangle(rectangle.x + 1, rectangle.y + 2 + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + (ConfigObject.getInstance().isEntryListWidgetScrolled() ? 0 : 22), rectangle.width - 2, rectangle.height - (ConfigObject.getInstance().getSearchFieldLocation() != SearchFieldLocation.CENTER ? 27 + 22 : 27) + (!ConfigObject.getInstance().isEntryListWidgetScrolled() ? 0 : 22)); + } + + default Rectangle getFavoritesListArea(Rectangle rectangle) { + int offset = 31 + (ConfigObject.getInstance().doesShowUtilsButtons() ? 25 : 0); + return new Rectangle(rectangle.x + 1, rectangle.y + 2 + offset, rectangle.width - 2, rectangle.height - 5 - offset); + } + + @Deprecated + @ApiStatus.ScheduledForRemoval + default boolean shouldRecalculateArea(boolean isOnRightSide, Rectangle rectangle) { + return false; + } + + @Override + default boolean shouldRecalculateArea(DisplayPanelLocation location, Rectangle rectangle) { + return shouldRecalculateArea(location == DisplayPanelLocation.RIGHT, rectangle); + } + + /** + * Gets the priority of the handler, the higher it is, the earlier it is called. + * + * @return the priority in float + */ + @Override + float getPriority(); + } + +} diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java new file mode 100644 index 000000000..732e95949 --- /dev/null +++ b/RoughlyEnoughItems-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.util.ActionResult; + +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 + */ + ActionResult handleDisplay(RecipeCategory category, RecipeDisplay display); + +} diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java new file mode 100644 index 000000000..3aaf05ba6 --- /dev/null +++ b/RoughlyEnoughItems-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 net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.util.math.MatrixStack; +import org.jetbrains.annotations.NotNull; + +/** + * Consumer of a {@link DrawableHelper} and information of mouse and delta. + */ +public interface DrawableConsumer { + void render(@NotNull DrawableHelper helper, @NotNull MatrixStack matrices, int mouseX, int mouseY, float delta); +} diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryRegistry.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryRegistry.java new file mode 100644 index 000000000..fd7fac2d8 --- /dev/null +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryRegistry.java @@ -0,0 +1,158 @@ +/* + * 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.item.Item; +import net.minecraft.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.Collectors; +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(); + } + + /** + * Gets the current modifiable stacks list + * + * @return a stacks list + */ + @Deprecated + @ApiStatus.ScheduledForRemoval + @NotNull + default List getStacksList() { + return getEntryStacks().collect(Collectors.toList()); + } + + @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 an new stack to the entry list + * + * @param afterEntry the stack to put after + * @param stack the stack to register + * @param checkAlreadyContains whether the list should check if it is already on the list + * @see #queueRegisterEntryAfter(EntryStack, Collection) for a faster method + */ + @Deprecated + @ApiStatus.ScheduledForRemoval + default void registerEntryAfter(@Nullable EntryStack afterEntry, @NotNull EntryStack stack, boolean checkAlreadyContains) { + registerEntryAfter(afterEntry, stack); + } + + @Deprecated + @ApiStatus.ScheduledForRemoval + default void queueRegisterEntryAfter(@Nullable EntryStack afterEntry, @NotNull Collection<@NotNull ? extends EntryStack> stacks) { + registerEntriesAfter(afterEntry, stacks); + } + + /** + * 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/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java new file mode 100644 index 000000000..716257e13 --- /dev/null +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java @@ -0,0 +1,372 @@ +/* + * 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 me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.fluid.FluidSupportProvider; +import me.shedaniel.rei.api.fractions.Fraction; +import me.shedaniel.rei.api.widgets.Tooltip; +import me.shedaniel.rei.impl.Internals; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.resource.language.I18n; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.fluid.Fluid; +import net.minecraft.item.Item; +import net.minecraft.item.ItemConvertible; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.StringNbtReader; +import net.minecraft.recipe.Ingredient; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +import java.util.*; +import java.util.function.Function; +import java.util.function.Supplier; + +@Environment(EnvType.CLIENT) +public interface EntryStack extends TextRepresentable { + + static EntryStack empty() { + return Internals.getEntryStackProvider().empty(); + } + + static EntryStack create(Fluid fluid) { + return Internals.getEntryStackProvider().fluid(fluid); + } + + static EntryStack create(Fluid fluid, int amount) { + return create(fluid, Fraction.ofWhole(amount)); + } + + static EntryStack create(Fluid fluid, double amount) { + return create(fluid, Fraction.from(amount)); + } + + static EntryStack create(Fluid fluid, Fraction amount) { + return Internals.getEntryStackProvider().fluid(fluid, amount); + } + + static EntryStack create(ItemStack stack) { + return Internals.getEntryStackProvider().item(stack); + } + + static EntryStack create(ItemConvertible item) { + return create(new ItemStack(item)); + } + + static List ofItems(Collection stacks) { + List result = new ArrayList<>(stacks.size()); + for (ItemConvertible stack : stacks) { + result.add(create(stack)); + } + return result; + } + + static List ofItemStacks(Collection stacks) { + List result = new ArrayList<>(stacks.size()); + for (ItemStack stack : stacks) { + result.add(create(stack)); + } + return result; +