aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidget.java35
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java4
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayCategory.java28
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java14
-rw-r--r--api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/api/client/gui/widgets/NoOpWidget.java23
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java5
7 files changed, 75 insertions, 36 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidget.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidget.java
index 19c73516e..67ca753f4 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidget.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidget.java
@@ -41,9 +41,13 @@ public class DelegateWidget extends WidgetWithBounds {
this.children = Collections.singletonList(widget);
}
+ public Widget delegate() {
+ return widget;
+ }
+
@Override
public void render(PoseStack poseStack, int i, int j, float f) {
- widget.render(poseStack, i, j, f);
+ delegate().render(poseStack, i, j, f);
}
@Override
@@ -53,37 +57,38 @@ public class DelegateWidget extends WidgetWithBounds {
@Override
public Rectangle getBounds() {
- return widget instanceof WidgetWithBounds ? ((WidgetWithBounds) widget).getBounds() : EMPTY;
+ return delegate() instanceof WidgetWithBounds withBounds ? withBounds.getBounds() : EMPTY;
}
@Override
public void setZ(int z) {
- widget.setZ(z);
+ delegate().setZ(z);
}
@Override
public int getZ() {
- return widget.getZ();
+ return delegate().getZ();
}
@Nullable
@Override
public GuiEventListener getFocused() {
- return widget;
+ return delegate();
}
@Override
public void setFocused(@Nullable GuiEventListener guiEventListener) {
- if (guiEventListener == widget) {
- super.setFocused(widget);
+ Widget delegate = delegate();
+ if (guiEventListener == delegate) {
+ super.setFocused(delegate);
} else {
- widget.setFocused(guiEventListener);
+ delegate.setFocused(guiEventListener);
}
}
@Override
public boolean containsMouse(double mouseX, double mouseY) {
- return widget.containsMouse(mouseX, mouseY);
+ return delegate().containsMouse(mouseX, mouseY);
}
@Override
@@ -93,32 +98,32 @@ public class DelegateWidget extends WidgetWithBounds {
@Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
- return widget.mouseScrolled(mouseX, mouseY, amount);
+ return delegate().mouseScrolled(mouseX, mouseY, amount);
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
- return widget.keyPressed(keyCode, scanCode, modifiers);
+ return delegate().keyPressed(keyCode, scanCode, modifiers);
}
@Override
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
- return widget.keyReleased(keyCode, scanCode, modifiers);
+ return delegate().keyReleased(keyCode, scanCode, modifiers);
}
@Override
public boolean charTyped(char character, int modifiers) {
- return widget.charTyped(character, modifiers);
+ return delegate().charTyped(character, modifiers);
}
@Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
- return widget.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
+ return delegate().mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}
@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
this.setDragging(false);
- return widget.mouseReleased(mouseX, mouseY, button);
+ return delegate().mouseReleased(mouseX, mouseY, button);
}
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java
index 191d276d2..df535cfa3 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java
@@ -303,6 +303,10 @@ public final class Widgets {
return ClientInternals.getWidgetsProvider().concatWidgets(widgets);
}
+ public static Widget noOp() {
+ return ClientInternals.getWidgetsProvider().noOp();
+ }
+
public static <T> Iterable<T> walk(Iterable<? extends GuiEventListener> listeners, Predicate<GuiEventListener> predicate) {
return () -> new AbstractIterator<T>() {
Stack<Iterator<? extends GuiEventListener>> stack;
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 0e376aa9f..c01d1a9f3 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
@@ -46,13 +46,13 @@ import java.util.List;
@Environment(EnvType.CLIENT)
public interface DisplayCategory<T extends Display> extends DisplayCategoryView<T>, Identifiable {
/**
- * Returns the renderer of the icon displayed in the category tab.
- * <p>
- * A simple implementation is the {@link me.shedaniel.rei.api.common.entry.EntryStack}.
+ * Returns the identifier of this {@link DisplayCategory}.
+ * This identifier must be the same one used to register the category
+ * in {@link me.shedaniel.rei.api.client.registry.category.CategoryRegistry}.
*
- * @return the renderer of the icon
+ * @return the identifier of this category
*/
- Renderer getIcon();
+ CategoryIdentifier<? extends T> getCategoryIdentifier();
/**
* Returns the category title for the category.
@@ -62,6 +62,15 @@ public interface DisplayCategory<T extends Display> extends DisplayCategoryView<
Component getTitle();
/**
+ * Returns the renderer of the icon displayed in the category tab.
+ * <p>
+ * A simple implementation is the {@link me.shedaniel.rei.api.common.entry.EntryStack}.
+ *
+ * @return the renderer of the icon
+ */
+ Renderer getIcon();
+
+ /**
* {@inheritDoc}
*/
@ApiStatus.OverrideOnly
@@ -117,15 +126,6 @@ public interface DisplayCategory<T extends Display> extends DisplayCategoryView<
}
/**
- * Returns the identifier of this {@link DisplayCategory}.
- * This identifier must be the same one used to register the category
- * in {@link me.shedaniel.rei.api.client.registry.category.CategoryRegistry}.
- *
- * @return the identifier of this category
- */
- CategoryIdentifier<? extends T> getCategoryIdentifier();
-
- /**
* Returns the display merger for this category.
* <p>
* A display merger is used to determine whether two displays can be merged together.
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 0af581d55..464cbafbb 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
@@ -219,7 +219,7 @@ public interface DisplayRegistry extends RecipeManagerContext<REIClientPlugin> {
* @param <T> the type of object
* @param <D> the type of display
*/
- default <T extends Recipe<?>, D extends Display> void registerRecipeFiller(Class<T> typeClass, RecipeType<? super T> recipeType, Function<? extends T, D> filler) {
+ default <T extends Recipe<?>, D extends Display> void registerRecipeFiller(Class<T> typeClass, RecipeType<? super T> recipeType, Function<? extends T, @Nullable D> filler) {
registerRecipeFiller(typeClass, type -> Objects.equals(recipeType, type), filler);
}
@@ -234,7 +234,7 @@ public interface DisplayRegistry extends RecipeManagerContext<REIClientPlugin> {
* @param <T> the type of object
* @param <D> the type of display
*/
- default <T extends Recipe<?>, D extends Display> void registerRecipeFiller(Class<T> typeClass, Predicate<RecipeType<? super T>> recipeType, Function<? extends T, D> filler) {
+ default <T extends Recipe<?>, D extends Display> void registerRecipeFiller(Class<T> typeClass, Predicate<RecipeType<? super T>> recipeType, Function<? extends T, @Nullable D> filler) {
registerRecipeFiller(typeClass, recipeType, Predicates.alwaysTrue(), filler);
}
@@ -249,7 +249,7 @@ public interface DisplayRegistry extends RecipeManagerContext<REIClientPlugin> {
* @param <T> the type of object
* @param <D> the type of display
*/
- default <T extends Recipe<?>, D extends Display> void registerRecipeFiller(Class<T> typeClass, Predicate<RecipeType<? super T>> recipeType, Predicate<? extends T> predicate, Function<? extends T, D> filler) {
+ default <T extends Recipe<?>, D extends Display> void registerRecipeFiller(Class<T> typeClass, Predicate<RecipeType<? super T>> recipeType, Predicate<? extends T> predicate, Function<? extends T, @Nullable D> filler) {
registerFiller(typeClass, recipe -> recipeType.test((RecipeType<? super T>) recipe.getType()) && ((Predicate<T>) predicate).test(recipe), filler);
}
@@ -264,7 +264,7 @@ public interface DisplayRegistry extends RecipeManagerContext<REIClientPlugin> {
* @param <T> the type of object
* @param <D> the type of display
*/
- default <T, D extends Display> void registerFiller(Class<T> typeClass, Function<? extends T, D> filler) {
+ default <T, D extends Display> void registerFiller(Class<T> typeClass, Function<? extends T, @Nullable D> filler) {
registerFiller(typeClass, Predicates.alwaysTrue(), filler);
}
@@ -280,7 +280,7 @@ public interface DisplayRegistry extends RecipeManagerContext<REIClientPlugin> {
* @param <T> the type of object
* @param <D> the type of display
*/
- <T, D extends Display> void registerFiller(Class<T> typeClass, Predicate<? extends T> predicate, Function<? extends T, D> filler);
+ <T, D extends Display> void registerFiller(Class<T> typeClass, Predicate<? extends T> predicate, Function<? extends T, @Nullable D> filler);
/**
* Registers a display filler, to be filled during {@link #tryFillDisplay(Object)}.
@@ -295,7 +295,7 @@ public interface DisplayRegistry extends RecipeManagerContext<REIClientPlugin> {
* @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);
+ <T, D extends Display> void registerFiller(Class<T> typeClass, BiPredicate<? extends T, DisplayAdditionReasons> predicate, Function<? extends T, @Nullable D> filler);
/**
* Registers a display filler, to be filled during {@link #tryFillDisplay(Object)}.
@@ -307,7 +307,7 @@ public interface DisplayRegistry extends RecipeManagerContext<REIClientPlugin> {
* @param filler the filler, taking an object and returning a {@code D}
* @param <D> the type of display
*/
- <D extends Display> void registerFiller(Predicate<?> predicate, Function<?, D> filler);
+ <D extends Display> void registerFiller(Predicate<?> predicate, Function<?, @Nullable D> filler);
/**
* Tries to fill displays from {@code T}.
diff --git a/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java b/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java
index 382f4873c..cf6e13be6 100644
--- a/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java
+++ b/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java
@@ -201,5 +201,7 @@ public final class ClientInternals {
Widget createShapelessIcon(Point point);
Widget concatWidgets(List<Widget> widgets);
+
+ Widget noOp();
}
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/api/client/gui/widgets/NoOpWidget.java b/runtime/src/main/java/me/shedaniel/rei/api/client/gui/widgets/NoOpWidget.java
new file mode 100644
index 000000000..066c3254d
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/api/client/gui/widgets/NoOpWidget.java
@@ -0,0 +1,23 @@
+package me.shedaniel.rei.api.client.gui.widgets;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import net.minecraft.client.gui.components.events.GuiEventListener;
+
+import java.util.Collections;
+import java.util.List;
+
+public class NoOpWidget extends Widget {
+ public static final NoOpWidget INSTANCE = new NoOpWidget();
+
+ private NoOpWidget() {
+ }
+
+ @Override
+ public void render(PoseStack poses, int mouseX, int mouseY, float delta) {
+ }
+
+ @Override
+ public List<? extends GuiEventListener> children() {
+ return Collections.emptyList();
+ }
+}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java
index e9c62f350..12bb487a0 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java
@@ -266,5 +266,10 @@ public final class InternalWidgets {
public Widget concatWidgets(List<Widget> widgets) {
return InternalWidgets.concatWidgets(widgets);
}
+
+ @Override
+ public Widget noOp() {
+ return NoOpWidget.INSTANCE;
+ }
}
}