diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-03-17 00:30:40 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-03-17 00:30:40 +0800 |
| commit | 8af94d0768f57b59b56f019c9d40d95b77382187 (patch) | |
| tree | 7b8c95251db7d54bec4e0ce10331c414c83ebea9 /api/src/main/java/me | |
| parent | 7451a88de892b5f3496eb63c7be44bc339df96b9 (diff) | |
| download | RoughlyEnoughItems-8af94d0768f57b59b56f019c9d40d95b77382187.tar.gz RoughlyEnoughItems-8af94d0768f57b59b56f019c9d40d95b77382187.tar.bz2 RoughlyEnoughItems-8af94d0768f57b59b56f019c9d40d95b77382187.zip | |
Expend DraggableStackProvider and DraggableStackVisitor to work in any widgets, implement renderBackToPosition
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'api/src/main/java/me')
5 files changed, 128 insertions, 8 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/ConfigObject.java b/api/src/main/java/me/shedaniel/rei/api/ConfigObject.java index 9558bdd1e..a92300e00 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ConfigObject.java +++ b/api/src/main/java/me/shedaniel/rei/api/ConfigObject.java @@ -35,7 +35,6 @@ import java.util.List; @Environment(EnvType.CLIENT) public interface ConfigObject { - /** * @return the instance of {@link me.shedaniel.rei.api.ConfigObject} */ diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/drag/DraggingContext.java b/api/src/main/java/me/shedaniel/rei/api/gui/drag/DraggingContext.java index 1b76cbaaf..e96b14ba2 100644 --- a/api/src/main/java/me/shedaniel/rei/api/gui/drag/DraggingContext.java +++ b/api/src/main/java/me/shedaniel/rei/api/gui/drag/DraggingContext.java @@ -65,8 +65,9 @@ public interface DraggingContext { * Renders the draggable stack back to the position {@code position}. * This may be used to animate an unaccepted draggable stack returning to its initial position. * - * @param stack the stack to use for render - * @param position the position supplier of the destination + * @param stack the stack to use for render + * @param initialPosition the initial position of the stack + * @param position the position supplier of the destination */ - void renderBackToPosition(DraggableStack stack, Supplier<Point> position); + void renderBackToPosition(DraggableStack stack, Point initialPosition, Supplier<Point> position); } diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/DelegateWidget.java b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/DelegateWidget.java new file mode 100644 index 000000000..ed4e4a3cc --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/DelegateWidget.java @@ -0,0 +1,62 @@ +package me.shedaniel.rei.api.gui.widgets; + +import com.mojang.blaze3d.vertex.PoseStack; +import me.shedaniel.math.Rectangle; +import net.minecraft.client.gui.components.events.GuiEventListener; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collections; +import java.util.List; + +public class DelegateWidget extends WidgetWithBounds { + private static final Rectangle EMPTY = new Rectangle(); + protected final Widget widget; + private final List<Widget> children; + + public DelegateWidget(Widget widget) { + this.widget = widget; + this.children = Collections.singletonList(widget); + } + + @Override + public void render(PoseStack poseStack, int i, int j, float f) { + widget.render(poseStack, i, j, f); + } + + @Override + public List<? extends GuiEventListener> children() { + return children; + } + + @Override + public @NotNull Rectangle getBounds() { + return widget instanceof WidgetWithBounds ? ((WidgetWithBounds) widget).getBounds() : EMPTY; + } + + @Override + public void setZ(int z) { + widget.setZ(z); + } + + @Override + public int getZ() { + return widget.getZ(); + } + + @Nullable + @Override + public GuiEventListener getFocused() { + return widget; + } + + @Override + public void setFocused(@Nullable GuiEventListener guiEventListener) { + widget.setFocused(guiEventListener); + } + + @Override + public boolean containsMouse(double mouseX, double mouseY) { + return widget.containsMouse(mouseX, mouseY); + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widgets.java b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widgets.java index bd7801533..c0ef26b7d 100644 --- a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widgets.java +++ b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widgets.java @@ -24,6 +24,7 @@ package me.shedaniel.rei.api.gui.widgets; import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Matrix4f; import me.shedaniel.math.Dimension; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; @@ -59,12 +60,35 @@ public final class Widgets { @NotNull public static Widget wrapVanillaWidget(GuiEventListener element) { - Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> { - - }); return new VanillaWrappedWidget(element); } + public static WidgetWithBounds withTranslate(Widget widget, double x, double y, double z) { + return withTranslate(widget, Matrix4f.createTranslateMatrix((float) x, (float) y, (float) z)); + } + + public static WidgetWithBounds withTranslate(Widget widget, Matrix4f translate) { + WidgetWithBounds widgetWithBounds = wrapWidgetWithBounds(widget); + return new WidgetWithBoundsWithTranslate(widgetWithBounds, translate); + } + + private static class WidgetWithBoundsWithTranslate extends DelegateWidget { + private final Matrix4f translate; + + private WidgetWithBoundsWithTranslate(WidgetWithBounds widget, Matrix4f translate) { + super(widget); + this.translate = translate; + } + + @Override + public void render(PoseStack poseStack, int i, int j, float f) { + poseStack.pushPose(); + poseStack.last().pose().multiply(translate); + super.render(poseStack, i, j, f); + poseStack.popPose(); + } + } + private static class VanillaWrappedWidget extends Widget { private GuiEventListener element; @@ -86,11 +110,18 @@ public final class Widgets { } } - @NotNull public static WidgetWithBounds wrapRenderer(Rectangle bounds, Renderer renderer) { + if (renderer instanceof Widget) + return wrapWidgetWithBounds((Widget) renderer); return new RendererWrappedWidget(renderer); } + public static WidgetWithBounds wrapWidgetWithBounds(Widget widget) { + if (widget instanceof WidgetWithBounds) + return (WidgetWithBounds) widget; + return new DelegateWidget(widget); + } + private static class RendererWrappedWidget extends WidgetWithBounds { private Renderer renderer; private Rectangle bounds; @@ -111,6 +142,16 @@ public final class Widgets { return Collections.emptyList(); } + @Override + public void setZ(int z) { + renderer.setZ(z); + } + + @Override + public int getZ() { + return renderer.getZ(); + } + @NotNull @Override public Rectangle getBounds() { diff --git a/api/src/main/java/me/shedaniel/rei/api/plugins/PluginManager.java b/api/src/main/java/me/shedaniel/rei/api/plugins/PluginManager.java index 3942942a8..f9e5a8b3f 100644 --- a/api/src/main/java/me/shedaniel/rei/api/plugins/PluginManager.java +++ b/api/src/main/java/me/shedaniel/rei/api/plugins/PluginManager.java @@ -26,7 +26,13 @@ package me.shedaniel.rei.api.plugins; import me.shedaniel.rei.api.registry.ParentReloadable; import me.shedaniel.rei.api.registry.Reloadable; import me.shedaniel.rei.impl.Internals; +import org.jetbrains.annotations.ApiStatus; +import java.util.List; + +/** + * The plugin manager responsible for reloading and applying plugins. + */ public interface PluginManager extends ParentReloadable { static PluginManager getInstance() { return Internals.getPluginManager(); @@ -35,4 +41,15 @@ public interface PluginManager extends ParentReloadable { boolean arePluginsReloading(); <T extends Reloadable> T get(Class<T> reloadableClass); + + /** + * Registers a REI plugin + * + * @param plugin the plugin instance + * @return the plugin instance + */ + @ApiStatus.Internal + <T extends REIPlugin> T registerPlugin(T plugin); + + List<REIPlugin> getPlugins(); } |
