diff options
5 files changed, 77 insertions, 15 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/WidgetWithBounds.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/WidgetWithBounds.java index a303bdd44..d61d58f4d 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/WidgetWithBounds.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/WidgetWithBounds.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.api.client.gui.widgets; +import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Rectangle; public abstract class WidgetWithBounds extends Widget { @@ -32,4 +33,13 @@ public abstract class WidgetWithBounds extends Widget { public boolean containsMouse(double mouseX, double mouseY) { return getBounds().contains(mouseX, mouseY); } + + @Deprecated + @Override + public void render(PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { + Rectangle clone = getBounds().clone(); + getBounds().setBounds(bounds); + render(matrices, mouseX, mouseY, delta); + getBounds().setBounds(clone); + } } 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 0ac417634..52d0cc172 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 @@ -172,12 +172,12 @@ public final class Widgets { ((ContainerEventHandler) element).setFocused(guiEventListener); } } - + @Override public boolean isDragging() { return true; } - + @Override public boolean containsMouse(double mouseX, double mouseY) { return element.isMouseOver(mouseX, mouseY); @@ -186,22 +186,29 @@ public final class Widgets { public static WidgetWithBounds wrapRenderer(Rectangle bounds, Renderer renderer) { if (renderer instanceof Widget) - return wrapWidgetWithBounds((Widget) renderer); - return new RendererWrappedWidget(renderer); + return wrapWidgetWithBounds((Widget) renderer, bounds); + return new RendererWrappedWidget(renderer, bounds); } public static WidgetWithBounds wrapWidgetWithBounds(Widget widget) { + return wrapWidgetWithBounds(widget, null); + } + + public static WidgetWithBounds wrapWidgetWithBounds(Widget widget, Rectangle bounds) { if (widget instanceof WidgetWithBounds) return (WidgetWithBounds) widget; - return new DelegateWidget(widget); + if (bounds == null) + return new DelegateWidget(widget); + return new DelegateWidgetWithBounds(widget, bounds); } private static class RendererWrappedWidget extends WidgetWithBounds { - private Renderer renderer; - private Rectangle bounds; + private final Renderer renderer; + private final Rectangle bounds; - public RendererWrappedWidget(Renderer renderer) { + public RendererWrappedWidget(Renderer renderer, Rectangle bounds) { this.renderer = Objects.requireNonNull(renderer); + this.bounds = Objects.requireNonNull(bounds); } @Override @@ -232,6 +239,19 @@ public final class Widgets { } } + private static class DelegateWidgetWithBounds extends DelegateWidget { + private final Rectangle bounds; + + public DelegateWidgetWithBounds(Widget widget, Rectangle bounds) { + super(widget); + this.bounds = bounds; + } + + @Override + public Rectangle getBounds() { + return bounds; + } + } public static Widget createTexturedWidget(ResourceLocation identifier, Rectangle bounds) { return createTexturedWidget(identifier, bounds, 0, 0); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/util/ClientEntryStacks.java b/api/src/main/java/me/shedaniel/rei/api/client/util/ClientEntryStacks.java index 7409f1150..ab471cf77 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/util/ClientEntryStacks.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/util/ClientEntryStacks.java @@ -44,22 +44,22 @@ public final class ClientEntryStacks { return EntryStack.of(BuiltinClientEntryTypes.RENDERING, renderer); } - public static <T> EntryStack<T> setNotRenderer(EntryStack<T> stack) { + public static <T> EntryStack<T> setNotRenderer(EntryStack<? extends T> stack) { return setRenderer(stack, EntryRenderer.empty()); } - public static <T> EntryStack<T> setRenderer(EntryStack<T> stack, EntryRenderer<T> renderer) { - return stack.setting(EntryStack.Settings.RENDERER, s -> renderer); + public static <T> EntryStack<T> setRenderer(EntryStack<? extends T> stack, EntryRenderer<? extends T> renderer) { + return stack.setting(EntryStack.Settings.RENDERER, s -> renderer).cast(); } @SuppressWarnings("rawtypes") - public static <T> EntryStack<T> setRenderer(EntryStack<T> stack, Function<EntryStack<T>, EntryRenderer<T>> rendererProvider) { - return stack.setting(EntryStack.Settings.RENDERER, (Function) rendererProvider); + public static <T> EntryStack<T> setRenderer(EntryStack<? extends T> stack, Function<EntryStack<T>, EntryRenderer<? extends T>> rendererProvider) { + return stack.setting(EntryStack.Settings.RENDERER, (Function) rendererProvider).cast(); } @SuppressWarnings("rawtypes") - public static <T> EntryStack<T> setTooltipProcessor(EntryStack<T> stack, BiFunction<EntryStack<T>, Tooltip, Tooltip> processor) { - return stack.setting(EntryStack.Settings.TOOLTIP_PROCESSOR, (BiFunction) processor); + public static <T> EntryStack<T> setTooltipProcessor(EntryStack<? extends T> stack, BiFunction<EntryStack<T>, Tooltip, Tooltip> processor) { + return stack.setting(EntryStack.Settings.TOOLTIP_PROCESSOR, (BiFunction) processor).cast(); } public static EntryStack<FluidStack> setFluidRenderRatio(EntryStack<FluidStack> stack, float ratio) { diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoProvider.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoProvider.java index 1e43dbbdc..d6a824843 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoProvider.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoProvider.java @@ -1,3 +1,26 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 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.common.transfer.info; import me.shedaniel.rei.api.common.category.CategoryIdentifier; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java index 1f0247f3a..8e3c91241 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java @@ -471,4 +471,13 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget { } return null; } + + @Override + @Deprecated + public void render(PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { + Rectangle clone = getBounds().clone(); + getBounds().setBounds(bounds.x - 1, bounds.y - 1, bounds.width + 2, bounds.height + 2); + render(matrices, mouseX, mouseY, delta); + getBounds().setBounds(clone); + } } |
