From f0a20163b47f5ce9e85e5a8d800c9677b053319e Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 22 Nov 2021 21:49:33 +0800 Subject: Fix #662 --- .../client/registry/category/CategoryRegistry.java | 9 ++++ .../extension/CategoryExtensionProvider.java | 49 ++++++++++++++++++++ .../client/registry/display/DisplayCategory.java | 4 +- .../registry/display/DisplayCategoryView.java | 54 ++++++++++++++++++++++ .../client/registry/display/DisplayRegistry.java | 6 +++ 5 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 api/src/main/java/me/shedaniel/rei/api/client/registry/category/extension/CategoryExtensionProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayCategoryView.java (limited to 'api/src/main/java/me') diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java index 6e83dfac2..ebe4f1000 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java @@ -24,8 +24,10 @@ package me.shedaniel.rei.api.client.registry.category; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +import me.shedaniel.rei.api.client.registry.category.extension.CategoryExtensionProvider; import me.shedaniel.rei.api.client.registry.category.visibility.CategoryVisibilityPredicate; import me.shedaniel.rei.api.client.registry.display.DisplayCategory; +import me.shedaniel.rei.api.client.registry.display.DisplayCategoryView; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.entry.EntryIngredient; @@ -37,6 +39,7 @@ import me.shedaniel.rei.api.common.util.Identifiable; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.ApiStatus; import java.util.List; import java.util.Optional; @@ -215,6 +218,12 @@ public interface CategoryRegistry extends Reloadable, Iterable< */ CategoryIdentifier getCategoryIdentifier(); + @ApiStatus.Experimental + void registerExtension(CategoryExtensionProvider provider); + + @ApiStatus.Experimental + DisplayCategoryView getView(T display); + @Override default ResourceLocation getIdentifier() { return getCategoryIdentifier().getIdentifier(); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/category/extension/CategoryExtensionProvider.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/category/extension/CategoryExtensionProvider.java new file mode 100644 index 000000000..58fcbb8de --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/category/extension/CategoryExtensionProvider.java @@ -0,0 +1,49 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 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.client.registry.category.extension; + +import me.shedaniel.rei.api.client.registry.display.DisplayCategory; +import me.shedaniel.rei.api.client.registry.display.DisplayCategoryView; +import me.shedaniel.rei.api.common.display.Display; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import org.jetbrains.annotations.ApiStatus; + +@FunctionalInterface +@ApiStatus.Experimental +@Environment(EnvType.CLIENT) +public interface CategoryExtensionProvider { + /** + * Returns a new {@link DisplayCategoryView} for a specific {@link Display}, + * a previous {@link DisplayCategoryView} will be provided, this may be the original category. + * {@code null} is not an accepted value, return the previous view if this provider + * does not modify the view. + * + * @param display the display to display for, do not store or cache this + * @param category the category of the display, do not store or cache this + * @param lastView the previous category view + * @return the new category view, {@code null} is not accepted here + */ + DisplayCategoryView provide(T display, DisplayCategory category, DisplayCategoryView lastView); +} diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayCategory.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayCategory.java index 9202a18ca..0b672e9a6 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayCategory.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayCategory.java @@ -44,7 +44,7 @@ import java.util.Collections; import java.util.List; @Environment(EnvType.CLIENT) -public interface DisplayCategory extends Identifiable { +public interface DisplayCategory extends DisplayCategoryView, Identifiable { /** * Returns the renderer of the icon. * @@ -66,6 +66,7 @@ public interface DisplayCategory extends Identifiable { * @return the display renderer */ @ApiStatus.OverrideOnly + @Override default DisplayRenderer getDisplayRenderer(T display) { return SimpleDisplayRenderer.from(display.getInputEntries(), display.getOutputEntries()); } @@ -78,6 +79,7 @@ public interface DisplayCategory extends Identifiable { * @return the list of widgets */ @ApiStatus.OverrideOnly + @Override default List setupDisplay(T display, Rectangle bounds) { return Collections.singletonList(Widgets.createRecipeBase(bounds)); } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayCategoryView.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayCategoryView.java new file mode 100644 index 000000000..57fb3b3cc --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayCategoryView.java @@ -0,0 +1,54 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 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.client.registry.display; + +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.gui.DisplayRenderer; +import me.shedaniel.rei.api.client.gui.widgets.Widget; +import me.shedaniel.rei.api.common.display.Display; +import org.jetbrains.annotations.ApiStatus; + +import java.util.List; + +@ApiStatus.Experimental +public interface DisplayCategoryView { + /** + * Gets the recipe renderer for the category, used in {@link me.shedaniel.rei.impl.client.gui.CompositeRecipeViewingScreen} for rendering simple recipes + * + * @param display the display to render + * @return the display renderer + */ + @ApiStatus.OverrideOnly + DisplayRenderer getDisplayRenderer(T display); + + /** + * Setup the widgets for displaying the recipe + * + * @param display the recipe + * @param bounds the bounds of the display, configurable with overriding the width, height methods. + * @return the list of widgets + */ + @ApiStatus.OverrideOnly + List setupDisplay(T display, Rectangle bounds); +} diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java index ad3a2aa18..9f895feeb 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java @@ -331,6 +331,12 @@ public interface DisplayRegistry extends RecipeManagerContext { @ApiStatus.Experimental Collection tryFillDisplay(T value, DisplayAdditionReason... reasons); + /** + * Returns the origin of the display, this may be the recipe which the display was created from. + * + * @param display the display + * @return the origin + */ @Nullable Object getDisplayOrigin(Display display); } -- cgit