aboutsummaryrefslogtreecommitdiff
path: root/api/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'api/src/main')
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java8
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRendererProvider.java54
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRendererRegistry.java67
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/ForwardingEntryRenderer.java50
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/plugins/REIClientPlugin.java11
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java45
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReason.java44
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReasons.java91
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java3
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginView.java13
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java27
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java15
12 files changed, 417 insertions, 11 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java
index 3943a76eb..43819351a 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java
@@ -40,9 +40,10 @@ import org.jetbrains.annotations.Nullable;
*
* @param <T> the entry type
* @see BatchedEntryRenderer
+ * @see EntryRendererRegistry
*/
@Environment(EnvType.CLIENT)
-public interface EntryRenderer<T> {
+public interface EntryRenderer<T> extends EntryRendererProvider<T> {
static <T> EntryRenderer<T> empty() {
return ClientInternals.getEmptyEntryRenderer();
}
@@ -58,4 +59,9 @@ public interface EntryRenderer<T> {
default <O> EntryRenderer<O> cast() {
return (EntryRenderer<O>) this;
}
+
+ @Override
+ default EntryRenderer<T> provide(EntryStack<T> entry, EntryRenderer<T> last) {
+ return this;
+ }
} \ No newline at end of file
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRendererProvider.java b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRendererProvider.java
new file mode 100644
index 000000000..659df5cff
--- /dev/null
+++ b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRendererProvider.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.entry.renderer;
+
+import me.shedaniel.rei.api.common.entry.EntryStack;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
+
+/**
+ * A functional interface to provide {@link EntryRenderer} for {@link EntryStack}.
+ *
+ * @param <T> the entry type
+ * @see EntryRenderer
+ */
+@FunctionalInterface
+@Environment(EnvType.CLIENT)
+public interface EntryRendererProvider<T> {
+ static <T> EntryRendererProvider<T> empty() {
+ return EntryRenderer.empty();
+ }
+
+ /**
+ * Returns a new {@link EntryRenderer} for a specific {@link EntryStack},
+ * a previous {@link EntryRenderer} will be provided, this may be an empty renderer.
+ * {@code null} is not an accepted value, return the previous renderer if this provider
+ * does not modify the renderer.
+ *
+ * @param entry the entry stack to render for, do not store or cache this
+ * @param last the previous entry renderer
+ * @return the new entry renderer, {@code null} is not accepted here
+ */
+ EntryRenderer<T> provide(EntryStack<T> entry, EntryRenderer<T> last);
+}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRendererRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRendererRegistry.java
new file mode 100644
index 000000000..95b8981b3
--- /dev/null
+++ b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRendererRegistry.java
@@ -0,0 +1,67 @@
+/*
+ * 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.entry.renderer;
+
+import me.shedaniel.math.Point;
+import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
+import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
+import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.entry.type.EntryType;
+import me.shedaniel.rei.api.common.plugins.PluginManager;
+import me.shedaniel.rei.api.common.registry.Reloadable;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Registry to transform {@link EntryRenderer} for stacks at a global level.
+ * For specific stacks, you can use {@link me.shedaniel.rei.api.client.util.ClientEntryStacks#setRenderer}
+ */
+@ApiStatus.Experimental
+public interface EntryRendererRegistry extends Reloadable<REIClientPlugin> {
+ static EntryRendererRegistry getInstance() {
+ return PluginManager.getClientInstance().get(EntryRendererRegistry.class);
+ }
+
+ <T> void register(EntryType<T> type, EntryRendererProvider<T> provider);
+
+ default <T> void transformTooltip(EntryType<T> type, TooltipTransformer<T> transformer) {
+ register(type, (entry, last) -> {
+ return new ForwardingEntryRenderer<T>(last) {
+ @Override
+ @Nullable
+ public Tooltip getTooltip(EntryStack<T> entry, Point mouse) {
+ return transformer.transform(entry, mouse, super.getTooltip(entry, mouse));
+ }
+ };
+ });
+ }
+
+ <T> EntryRenderer<T> get(EntryStack<T> stack);
+
+ @FunctionalInterface
+ interface TooltipTransformer<T> {
+ @Nullable
+ Tooltip transform(EntryStack<T> entry, Point mouse, @Nullable Tooltip tooltip);
+ }
+}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/ForwardingEntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/ForwardingEntryRenderer.java
new file mode 100644
index 000000000..2c56d5176
--- /dev/null
+++ b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/ForwardingEntryRenderer.java
@@ -0,0 +1,50 @@
+/*
+ * 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.entry.renderer;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import me.shedaniel.math.Point;
+import me.shedaniel.math.Rectangle;
+import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
+import me.shedaniel.rei.api.common.entry.EntryStack;
+import org.jetbrains.annotations.Nullable;
+
+public abstract class ForwardingEntryRenderer<T> implements EntryRenderer<T> {
+ protected EntryRenderer<T> next;
+
+ public ForwardingEntryRenderer(EntryRenderer<T> next) {
+ this.next = next;
+ }
+
+ @Override
+ public void render(EntryStack<T> entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) {
+ this.next.render(entry, matrices, bounds, mouseX, mouseY, delta);
+ }
+
+ @Override
+ @Nullable
+ public Tooltip getTooltip(EntryStack<T> entry, Point mouse) {
+ return this.next.getTooltip(entry, mouse);
+ }
+}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/plugins/REIClientPlugin.java b/api/src/main/java/me/shedaniel/rei/api/client/plugins/REIClientPlugin.java
index e65ccc4e1..a6be0beeb 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/plugins/REIClientPlugin.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/plugins/REIClientPlugin.java
@@ -23,6 +23,7 @@
package me.shedaniel.rei.api.client.plugins;
+import me.shedaniel.rei.api.client.entry.renderer.EntryRendererRegistry;
import me.shedaniel.rei.api.client.favorites.FavoriteEntryType;
import me.shedaniel.rei.api.client.registry.category.CategoryRegistry;
import me.shedaniel.rei.api.client.registry.display.DisplayRegistry;
@@ -39,6 +40,16 @@ import org.jetbrains.annotations.ApiStatus;
@Environment(EnvType.CLIENT)
public interface REIClientPlugin extends REIPlugin<REIClientPlugin> {
/**
+ * Registers new entry renderers
+ *
+ * @param registry the entry renderer registry
+ */
+ @ApiStatus.OverrideOnly
+ @ApiStatus.Experimental
+ default void registerEntryRenderers(EntryRendererRegistry registry) {
+ }
+
+ /**
* Registers new categories
*
* @param registry the category registry
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 2ecb40967..ad3a2aa18 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
@@ -25,6 +25,8 @@ package me.shedaniel.rei.api.client.registry.display;
import com.google.common.base.Predicates;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
+import me.shedaniel.rei.api.client.registry.display.reason.DisplayAdditionReason;
+import me.shedaniel.rei.api.client.registry.display.reason.DisplayAdditionReasons;
import me.shedaniel.rei.api.client.registry.display.visibility.DisplayVisibilityPredicate;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.display.Display;
@@ -34,9 +36,11 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeType;
+import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import java.util.*;
+import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Predicate;
@@ -100,10 +104,20 @@ public interface DisplayRegistry extends RecipeManagerContext<REIClientPlugin> {
* @param object the object to be filled
*/
default void add(Object object) {
+ addWithReason(object, DisplayAdditionReason.NONE);
+ }
+
+ /**
+ * Registers a display by the object provided, to be filled during {@link #tryFillDisplay(Object)}.
+ *
+ * @param object the object to be filled
+ */
+ @ApiStatus.Experimental
+ default void addWithReason(Object object, DisplayAdditionReason... reasons) {
if (object instanceof Display) {
add((Display) object, null);
} else {
- for (Display display : tryFillDisplay(object)) {
+ for (Display display : tryFillDisplay(object, reasons)) {
add(display, object);
}
}
@@ -275,6 +289,21 @@ public interface DisplayRegistry extends RecipeManagerContext<REIClientPlugin> {
* Vanilla {@link Recipe} are by default filled, display filters
* can be used to automatically generate displaies for vanilla {@link Recipe}.
*
+ * @param typeClass the type of {@code T}
+ * @param predicate the predicate of {@code T} and reason
+ * @param filler the filler, taking a {@code T} and returning a {@code D}
+ * @param <T> the type of object
+ * @param <D> the type of display
+ */
+ @ApiStatus.Experimental
+ <T, D extends Display> void registerFiller(Class<T> typeClass, BiPredicate<? extends T, DisplayAdditionReasons> predicate, Function<? extends T, D> filler);
+
+ /**
+ * Registers a display filler, to be filled during {@link #tryFillDisplay(Object)}.
+ * <p>
+ * Vanilla {@link Recipe} are by default filled, display filters
+ * can be used to automatically generate displaies for vanilla {@link Recipe}.
+ *
* @param predicate the predicate of the object
* @param filler the filler, taking an object and returning a {@code D}
* @param <D> the type of display
@@ -288,7 +317,19 @@ public interface DisplayRegistry extends RecipeManagerContext<REIClientPlugin> {
* @param <T> the type of object
* @return the collection of displays
*/
- <T> Collection<Display> tryFillDisplay(T value);
+ default <T> Collection<Display> tryFillDisplay(T value) {
+ return tryFillDisplay(value, DisplayAdditionReason.NONE);
+ }
+
+ /**
+ * Tries to fill displays from {@code T}.
+ *
+ * @param value the object
+ * @param <T> the type of object
+ * @return the collection of displays
+ */
+ @ApiStatus.Experimental
+ <T> Collection<Display> tryFillDisplay(T value, DisplayAdditionReason... reasons);
@Nullable
Object getDisplayOrigin(Display display);
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReason.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReason.java
new file mode 100644
index 000000000..bea120008
--- /dev/null
+++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReason.java
@@ -0,0 +1,44 @@
+/*
+ * 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.reason;
+
+import org.jetbrains.annotations.ApiStatus;
+
+/**
+ * Reason for adding a display, used for {@link me.shedaniel.rei.api.client.registry.display.DisplayRegistry#tryFillDisplay(Object, DisplayAdditionReason...)}
+ * Plugins may filter their filler with reasons, this class can be implemented to provide additional context to fillers.
+ */
+@ApiStatus.Experimental
+public interface DisplayAdditionReason {
+ DisplayAdditionReason[] NONE = new DisplayAdditionReason[0];
+ /**
+ * Denotes that the display is added automatically by REI's RecipeManager,
+ * fillers which do not wish to be added with this should filter with this.
+ */
+ DisplayAdditionReason RECIPE_MANAGER = simple();
+
+ static DisplayAdditionReason simple() {
+ return new DisplayAdditionReason() {};
+ }
+}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReasons.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReasons.java
new file mode 100644
index 000000000..8c8ada33f
--- /dev/null
+++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/reason/DisplayAdditionReasons.java
@@ -0,0 +1,91 @@
+/*
+ * 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.reason;
+
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Objects;
+
+@ApiStatus.Experimental
+public interface DisplayAdditionReasons {
+ @Nullable <T extends DisplayAdditionReason> T get(Class<? extends T> c);
+
+ @Nullable <T extends DisplayAdditionReason> T get(T c);
+
+ <T extends DisplayAdditionReason> boolean has(Class<? extends T> c);
+
+ <T extends DisplayAdditionReason> boolean has(T c);
+
+ @ApiStatus.Internal
+ class Impl implements DisplayAdditionReasons {
+ public static final Impl EMPTY = new Impl(DisplayAdditionReason.NONE);
+ private final DisplayAdditionReason[] reasons;
+
+ public Impl(DisplayAdditionReason[] reasons) {
+ this.reasons = reasons;
+ }
+
+ @Override
+ @Nullable
+ public <T extends DisplayAdditionReason> T get(Class<? extends T> c) {
+ for (DisplayAdditionReason reason : reasons) {
+ if (Objects.equals(reason.getClass(), c)) {
+ return (T) reason;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public <T extends DisplayAdditionReason> @Nullable T get(T c) {
+ for (DisplayAdditionReason reason : reasons) {
+ if (Objects.equals(reason, c)) {
+ return (T) reason;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public <T extends DisplayAdditionReason> boolean has(Class<? extends T> c) {
+ for (DisplayAdditionReason reason : reasons) {
+ if (Objects.equals(reason.getClass(), c)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public <T extends DisplayAdditionReason> boolean has(T c) {
+ for (DisplayAdditionReason reason : reasons) {
+ if (Objects.equals(reason, c)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+}
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java
index 76ff50f98..74529de5c 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java
@@ -28,6 +28,7 @@ import dev.architectury.utils.EnvExecutor;
import me.shedaniel.math.Point;
import me.shedaniel.rei.api.client.config.ConfigObject;
import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer;
+import me.shedaniel.rei.api.client.entry.renderer.EntryRendererRegistry;
import me.shedaniel.rei.api.client.gui.Renderer;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
import me.shedaniel.rei.api.common.entry.type.EntryDefinition;
@@ -182,7 +183,7 @@ public interface EntryStack<T> extends TextRepresentable, Renderer {
static {
EnvExecutor.runInEnv(Env.CLIENT, () -> () -> {
- RENDERER = new Settings<>(stack -> stack.getDefinition().getRenderer());
+ RENDERER = new Settings<>(stack -> EntryRendererRegistry.getInstance().get(stack));
TOOLTIP_PROCESSOR = new Settings<>((stack, tooltip) -> tooltip);
TOOLTIP_APPEND_EXTRA = new Settings<>(stack -> Collections.emptyList());
FLUID_RENDER_RATIO = new Settings<>(1.0F);
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginView.java b/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginView.java
index ddd74a367..be1d3ab26 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginView.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginView.java
@@ -24,6 +24,7 @@
package me.shedaniel.rei.api.common.plugins;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
+import me.shedaniel.rei.api.common.registry.ReloadStage;
import me.shedaniel.rei.impl.ClientInternals;
import me.shedaniel.rei.impl.Internals;
import net.fabricmc.api.EnvType;
@@ -61,18 +62,18 @@ public interface PluginView<P extends REIPlugin<?>> {
}
@Override
- public void pre() {
- PluginView.this.pre();
+ public void pre(ReloadStage stage) {
+ PluginView.this.pre(stage);
}
@Override
- public void post() {
- PluginView.this.post();
+ public void post(ReloadStage stage) {
+ PluginView.this.post(stage);
}
};
}
- void pre();
+ void pre(ReloadStage stage);
- void post();
+ void post(ReloadStage stage);
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java b/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java
index 724dc0fed..ef4444661 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java
@@ -29,10 +29,13 @@ import me.shedaniel.rei.api.common.entry.comparison.FluidComparatorRegistry;
import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry;
import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry;
import me.shedaniel.rei.api.common.fluid.FluidSupportProvider;
+import me.shedaniel.rei.api.common.registry.ReloadStage;
+import me.shedaniel.rei.api.common.registry.Reloadable;
import org.jetbrains.annotations.ApiStatus;
import java.util.Collection;
import java.util.Collections;
+import java.util.Objects;
/**
* Base interface for a REI plugin.
@@ -96,15 +99,39 @@ public interface REIPlugin<P extends REIPlugin<?>> extends Comparable<REIPlugin<
}
@ApiStatus.OverrideOnly
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
default void preRegister() {
}
@ApiStatus.OverrideOnly
+ default void preStage(PluginManager<P> manager, ReloadStage stage) {
+ if (stage == ReloadStage.START && Objects.equals(manager, PluginManager.getInstance())) {
+ preRegister();
+ }
+ }
+
+ @ApiStatus.OverrideOnly
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
default void postRegister() {
}
+ @ApiStatus.OverrideOnly
+ default void postStage(PluginManager<P> manager, ReloadStage stage) {
+ if (stage == ReloadStage.END && (this instanceof REIServerPlugin ? Objects.equals(manager, PluginManager.getServerInstance()) : !Objects.equals(manager, PluginManager.getInstance()))) {
+ preRegister();
+ }
+ }
+
@Override
default Collection<P> provide() {
return Collections.singletonList((P) this);
}
+
+ @ApiStatus.Internal
+ @ApiStatus.Experimental
+ default boolean shouldBeForcefullyDoneOnMainThread(Reloadable<?> reloadable) {
+ return false;
+ }
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java
index 97934437d..09511ac6f 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java
@@ -306,7 +306,20 @@ public class CollectionUtils {
@Override
public List<T> next() {
int cursor = i++ * size;
- return list.subList(cursor, cursor + Math.min(list.size() - cursor, size));
+ int realSize = Math.min(list.size() - cursor, size);
+ return new AbstractList<T>() {
+ @Override
+ public T get(int index) {
+ if (index < 0 || index >= realSize)
+ throw new IndexOutOfBoundsException(String.format("Index %s out of bounds for length %s", index, realSize));
+ return list.get(cursor + index);
+ }
+
+ @Override
+ public int size() {
+ return realSize;
+ }
+ };
}
};
}