From bde43572e0a8e6080ba866dbdd68b2b21e23810a Mon Sep 17 00:00:00 2001 From: TsXor Date: Mon, 15 Jan 2024 11:36:59 +0800 Subject: [PATCH] fix book text tooltip covered by rendered parts --- .../patchouli/client/book/gui/GuiBook.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/vazkii/patchouli/client/book/gui/GuiBook.java b/src/main/java/vazkii/patchouli/client/book/gui/GuiBook.java index 96184b65f..4f75c5a99 100644 --- a/src/main/java/vazkii/patchouli/client/book/gui/GuiBook.java +++ b/src/main/java/vazkii/patchouli/client/book/gui/GuiBook.java @@ -17,6 +17,7 @@ import net.minecraft.util.SoundEvent; import net.minecraft.util.Util; import net.minecraft.util.text.*; +import net.minecraft.util.text.event.HoverEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.gui.GuiUtils; @@ -180,6 +181,18 @@ public T addButton(T widget) { @Override // make public public void renderComponentHoverEffect(MatrixStack matrices, @Nullable Style style, int mouseX, int mouseY) { + // super function will render tooltip *immediately*, before render method is called + // thus tooltip will be covered by what is rendered later + // let's check if this style is a tooltip here + if (style != null && style.getHoverEvent() != null) { + HoverEvent hoverevent = style.getHoverEvent(); + ITextComponent itextcomponent = hoverevent.getParameter(HoverEvent.Action.SHOW_TEXT); + if (itextcomponent != null) { + // this style is a tooltip, do not delegate it to super + this.setTooltip(itextcomponent); + return; + } + } super.renderComponentHoverEffect(matrices, style, mouseX, mouseY); } @@ -220,6 +233,10 @@ final void drawBackgroundElements(MatrixStack ms, int mouseX, int mouseY, float void drawForegroundElements(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {} + public boolean haveTooltip() { + return tooltipStack != null || (tooltip != null && !tooltip.isEmpty()); + } + final void drawTooltip(MatrixStack ms, int mouseX, int mouseY) { if (tooltipStack != null) { List tooltip = this.getTooltipFromItem(tooltipStack);