diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-05-27 18:43:08 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-05-27 18:43:08 +0800 |
| commit | ab0daccf200c923379a2156838af2b5e6611bed5 (patch) | |
| tree | d7031e08a32821392650b4bfdb940efcfb307db0 /api/src | |
| parent | e94257f07be6f9f164754b9a5e75780e190e0f7d (diff) | |
| download | RoughlyEnoughItems-ab0daccf200c923379a2156838af2b5e6611bed5.tar.gz RoughlyEnoughItems-ab0daccf200c923379a2156838af2b5e6611bed5.tar.bz2 RoughlyEnoughItems-ab0daccf200c923379a2156838af2b5e6611bed5.zip | |
Fix #867, Fix #861
Diffstat (limited to 'api/src')
9 files changed, 136 insertions, 7 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 ea79db26a..c51309603 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 @@ -27,6 +27,7 @@ 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.client.gui.widgets.TooltipContext; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.impl.ClientInternals; import net.fabricmc.api.EnvType; @@ -53,7 +54,16 @@ public interface EntryRenderer<T> extends EntryRendererProvider<T> { @Nullable @Environment(EnvType.CLIENT) - Tooltip getTooltip(EntryStack<T> entry, Point mouse); + @Deprecated(forRemoval = true, since = "8.3") + default Tooltip getTooltip(EntryStack<T> entry, Point mouse) { + return null; + } + + @Nullable + @Environment(EnvType.CLIENT) + default Tooltip getTooltip(EntryStack<T> entry, TooltipContext context) { + return getTooltip(entry, context.getPoint()); + } @ApiStatus.NonExtendable default <O> EntryRenderer<O> cast() { 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 index 4becfa174..efb3882d1 100644 --- 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 @@ -25,6 +25,7 @@ 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.gui.widgets.TooltipContext; 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; @@ -50,8 +51,8 @@ public interface EntryRendererRegistry extends Reloadable<REIClientPlugin> { return new ForwardingEntryRenderer<T>(last) { @Override @Nullable - public Tooltip getTooltip(EntryStack<T> entry, Point mouse) { - return transformer.transform(entry, mouse, super.getTooltip(entry, mouse)); + public Tooltip getTooltip(EntryStack<T> entry, TooltipContext context) { + return transformer.transform(entry, context.getPoint(), super.getTooltip(entry, context)); } }; }); 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 index bdd0bf214..229020ad4 100644 --- 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 @@ -27,6 +27,7 @@ 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.client.gui.widgets.TooltipContext; import me.shedaniel.rei.api.common.entry.EntryStack; import org.jetbrains.annotations.Nullable; @@ -45,6 +46,12 @@ public abstract class ForwardingEntryRenderer<T> implements EntryRenderer<T> { @Override @Nullable public Tooltip getTooltip(EntryStack<T> entry, Point mouse) { - return this.next.getTooltip(entry, mouse); + return this.next.getTooltip(entry, TooltipContext.of(mouse)); + } + + @Override + @Nullable + public Tooltip getTooltip(EntryStack<T> entry, TooltipContext context) { + return this.next.getTooltip(entry, context); } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/DisplayRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/DisplayRenderer.java index 8f8f0e0f4..9540c1ef6 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/DisplayRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/DisplayRenderer.java @@ -25,6 +25,7 @@ package me.shedaniel.rei.api.client.gui; import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.api.client.gui.widgets.TooltipContext; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import org.jetbrains.annotations.ApiStatus; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/Renderer.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/Renderer.java index c352d5933..c0a40c0ec 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/Renderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/Renderer.java @@ -27,6 +27,7 @@ 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.client.gui.widgets.TooltipContext; import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -40,10 +41,17 @@ public interface Renderer { @Nullable @Environment(EnvType.CLIENT) + @Deprecated(forRemoval = true) default Tooltip getTooltip(Point mouse) { return null; } + @Nullable + @Environment(EnvType.CLIENT) + default Tooltip getTooltip(TooltipContext context) { + return getTooltip(context.getPoint()); + } + @Environment(EnvType.CLIENT) int getZ(); 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 4e25b06b8..19c73516e 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 @@ -90,4 +90,35 @@ public class DelegateWidget extends WidgetWithBounds { public boolean isDragging() { return true; } + + @Override + public boolean mouseScrolled(double mouseX, double mouseY, double amount) { + return widget.mouseScrolled(mouseX, mouseY, amount); + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + return widget.keyPressed(keyCode, scanCode, modifiers); + } + + @Override + public boolean keyReleased(int keyCode, int scanCode, int modifiers) { + return widget.keyReleased(keyCode, scanCode, modifiers); + } + + @Override + public boolean charTyped(char character, int modifiers) { + return widget.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); + } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { + this.setDragging(false); + return widget.mouseReleased(mouseX, mouseY, button); + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipContext.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipContext.java new file mode 100644 index 000000000..7bc2ecd15 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipContext.java @@ -0,0 +1,53 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.gui.widgets; + +import me.shedaniel.math.Point; +import me.shedaniel.math.impl.PointHelper; +import me.shedaniel.rei.impl.ClientInternals; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.world.item.TooltipFlag; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +@Environment(EnvType.CLIENT) +@ApiStatus.NonExtendable +public interface TooltipContext { + static TooltipContext of(Point point) { + return TooltipContext.of(point, null); + } + + static TooltipContext of(Point point, @Nullable TooltipFlag flag) { + return ClientInternals.createTooltipContext(point, flag); + } + + static TooltipContext ofMouse() { + return TooltipContext.of(PointHelper.ofMouse()); + } + + TooltipFlag getFlag(); + + Point getPoint(); +} 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 3212d097a..1067ff6d3 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 @@ -31,6 +31,7 @@ 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.client.gui.widgets.TooltipContext; import me.shedaniel.rei.api.common.entry.type.EntryDefinition; import me.shedaniel.rei.api.common.entry.type.EntryType; import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry; @@ -97,7 +98,13 @@ public interface EntryStack<T> extends TextRepresentable, Renderer { @Nullable @Environment(EnvType.CLIENT) - Tooltip getTooltip(Point mouse, boolean appendModName); + default Tooltip getTooltip(Point mouse, boolean appendModName) { + return getTooltip(TooltipContext.of(mouse), appendModName); + } + + @Nullable + @Environment(EnvType.CLIENT) + Tooltip getTooltip(TooltipContext context, boolean appendModName); @Override @Nullable @@ -105,6 +112,12 @@ public interface EntryStack<T> extends TextRepresentable, Renderer { return getTooltip(mouse, ConfigObject.getInstance().shouldAppendModNames()); } + @Override + @Nullable + default Tooltip getTooltip(TooltipContext context) { + return getTooltip(context, ConfigObject.getInstance().shouldAppendModNames()); + } + EntryDefinition<T> getDefinition(); default EntryType<T> getType() { @@ -197,8 +210,7 @@ public interface EntryStack<T> extends TextRepresentable, Renderer { <R> R get(Settings<R> settings); - @Nullable - <R> R getNullable(Settings<R> settings); + @Nullable <R> R getNullable(Settings<R> settings); @Environment(EnvType.CLIENT) default EntryStack<T> tooltip(Component... tooltips) { 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 4341771d1..10b29150f 100644 --- a/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java +++ b/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java @@ -46,6 +46,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.tooltip.TooltipComponent; +import net.minecraft.world.item.TooltipFlag; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -69,6 +70,7 @@ public final class ClientInternals { private static Function<Boolean, ClickArea.Result> clickAreaHandlerResult = (result) -> throwNotSetup(); private static BiConsumer<List<ClientTooltipComponent>, TooltipComponent> clientTooltipComponentProvider = (tooltip, result) -> throwNotSetup(); private static BiFunction<@Nullable Point, Collection<Tooltip.Entry>, Tooltip> tooltipProvider = (point, texts) -> throwNotSetup(); + private static BiFunction<Point, @Nullable TooltipFlag, TooltipContext> tooltipContextProvider = (point, texts) -> throwNotSetup(); private static Function<Object, Tooltip.Entry> tooltipEntryProvider = (component) -> throwNotSetup(); private static Supplier<List<String>> jeiCompatMods = ClientInternals::throwNotSetup; private static Supplier<Object> builtinClientPlugin = ClientInternals::throwNotSetup; @@ -130,6 +132,10 @@ public final class ClientInternals { return tooltipProvider.apply(point, texts); } + public static TooltipContext createTooltipContext(Point point, @Nullable TooltipFlag flag) { + return tooltipContextProvider.apply(point, flag); + } + public static Tooltip.Entry createTooltipEntry(Object component) { return tooltipEntryProvider.apply(component); } |
