aboutsummaryrefslogtreecommitdiff
path: root/api/src/main/java/me/shedaniel
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-11-22 21:49:33 +0800
committershedaniel <daniel@shedaniel.me>2021-11-22 21:51:23 +0800
commitf0a20163b47f5ce9e85e5a8d800c9677b053319e (patch)
treef1ac8fd9e2a664699b1bbe2a2025248b34e6860c /api/src/main/java/me/shedaniel
parent24a022b95573e2a61a6a9597f0b685e129fe8da9 (diff)
downloadRoughlyEnoughItems-f0a20163b47f5ce9e85e5a8d800c9677b053319e.tar.gz
RoughlyEnoughItems-f0a20163b47f5ce9e85e5a8d800c9677b053319e.tar.bz2
RoughlyEnoughItems-f0a20163b47f5ce9e85e5a8d800c9677b053319e.zip
Fix #662
Diffstat (limited to 'api/src/main/java/me/shedaniel')
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java9
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/registry/category/extension/CategoryExtensionProvider.java49
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayCategory.java4
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayCategoryView.java54
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java6
5 files changed, 121 insertions, 1 deletions
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<REIClientPlugin>, Iterable<
*/
CategoryIdentifier<?> getCategoryIdentifier();
+ @ApiStatus.Experimental
+ void registerExtension(CategoryExtensionProvider<T> provider);
+
+ @ApiStatus.Experimental
+ DisplayCategoryView<T> 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<T extends Display> {
+ /**
+ * 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<T> provide(T display, DisplayCategory<T> category, DisplayCategoryView<T> 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<T extends Display> extends Identifiable {
+public interface DisplayCategory<T extends Display> extends DisplayCategoryView<T>, Identifiable {
/**
* Returns the renderer of the icon.
*
@@ -66,6 +66,7 @@ public interface DisplayCategory<T extends Display> 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<T extends Display> extends Identifiable {
* @return the list of widgets
*/
@ApiStatus.OverrideOnly
+ @Override
default List<Widget> 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<T extends Display> {
+ /**
+ * 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<Widget> 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<REIClientPlugin> {
@ApiStatus.Experimental
<T> Collection<Display> 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);
}