aboutsummaryrefslogtreecommitdiff
path: root/api/src
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-06-25 22:36:21 +0800
committershedaniel <daniel@shedaniel.me>2022-06-25 22:36:21 +0800
commit1b96562eb7d561e49dfd1063b62017620e22cd53 (patch)
tree3cb4e358b10c5d9cf40f59bf8e00b6684100128d /api/src
parenta46750de1a836217b9af2144916d7ab985a6405e (diff)
downloadRoughlyEnoughItems-1b96562eb7d561e49dfd1063b62017620e22cd53.tar.gz
RoughlyEnoughItems-1b96562eb7d561e49dfd1063b62017620e22cd53.tar.bz2
RoughlyEnoughItems-1b96562eb7d561e49dfd1063b62017620e22cd53.zip
Use a method for DelegateWidget and add no-op widget
Diffstat (limited to 'api/src')
-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
5 files changed, 47 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();
}
}