Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix book text tooltip covered by rendered parts (forge-1.16) #719

Open
wants to merge 1 commit into
base: 1.16-forge
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/vazkii/patchouli/client/book/gui/GuiBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -180,6 +181,18 @@ public <T extends Widget> 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);
}

Expand Down Expand Up @@ -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<ITextComponent> tooltip = this.getTooltipFromItem(tooltipStack);
Expand Down