From 8969d3b872cb8a0a2af446aa680068ddb919e619 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sun, 9 Jun 2024 12:55:50 +0200 Subject: [PATCH] fix: tooltip rendering order ModernUI relies on the correct order. --- CHANGELOG.md | 4 ++++ .../platform/common/support/AbstractBaseScreen.java | 11 +++++++++++ .../support/widget/AbstractSideButtonWidget.java | 9 +++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a5258d74..e39f54ef6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed + +- Side button tooltip rendering issue with ModernUI. + ## [2.0.0-milestone.3.8] - 2024-06-08 ### Removed diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseScreen.java index cfc317897..b6950210c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseScreen.java @@ -50,6 +50,9 @@ public abstract class AbstractBaseScreen extend private final List exclusionZones = new ArrayList<>(); private int sideButtonY; + @Nullable + private List deferredTooltip; + protected AbstractBaseScreen(final T menu, final Inventory playerInventory, final Component text) { super(menu, playerInventory, text); this.playerInventory = playerInventory; @@ -189,9 +192,17 @@ protected void renderTooltip(final GuiGraphics graphics, final int x, final int return; } } + if (deferredTooltip != null) { + Platform.INSTANCE.renderTooltip(graphics, deferredTooltip, x, y); + deferredTooltip = null; + } super.renderTooltip(graphics, x, y); } + public void setDeferredTooltip(@Nullable final List deferredTooltip) { + this.deferredTooltip = deferredTooltip; + } + private List getUpgradeTooltip(final ItemStack carried, final UpgradeSlot upgradeSlot) { if (!carried.isEmpty() || upgradeSlot.hasItem()) { return Collections.emptyList(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/AbstractSideButtonWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/AbstractSideButtonWidget.java index 4aa279714..1cbd57728 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/AbstractSideButtonWidget.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/AbstractSideButtonWidget.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support.widget; -import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseScreen; import com.refinedmods.refinedstorage2.platform.common.support.TextureIds; import com.refinedmods.refinedstorage2.platform.common.support.tooltip.HelpClientTooltipComponent; import com.refinedmods.refinedstorage2.platform.common.support.tooltip.SmallTextClientTooltipComponent; @@ -11,8 +11,10 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; @@ -66,7 +68,10 @@ public void renderWidget(final GuiGraphics graphics, final int mouseX, final int graphics.blit(getTextureIdentifier(), getX(), getY(), 238, 54, WIDTH, HEIGHT); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.disableBlend(); - Platform.INSTANCE.renderTooltip(graphics, buildTooltip(), mouseX, mouseY); + final Screen screen = Minecraft.getInstance().screen; + if (screen instanceof AbstractBaseScreen baseScreen) { + baseScreen.setDeferredTooltip(buildTooltip()); + } } if (warning != null) { renderWarning(graphics);