Skip to content

Commit e01b6ad

Browse files
committed
Fix deferred tooltip rendering in GUIs not obeying the z offset (#8120)
1 parent 2b5bef0 commit e01b6ad

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/main/java/mekanism/client/gui/GuiMekanism.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public abstract class GuiMekanism<CONTAINER extends AbstractContainerMenu> exten
5353
public static final ResourceLocation BASE_BACKGROUND = MekanismUtils.getResource(ResourceType.GUI, "base.png");
5454
public static final ResourceLocation SHADOW = MekanismUtils.getResource(ResourceType.GUI, "shadow.png");
5555
public static final ResourceLocation BLUR = MekanismUtils.getResource(ResourceType.GUI, "blur.png");
56+
private static final int EXTRA_Z_OFFSET = -500;
5657
//TODO: Look into defaulting this to true
5758
protected boolean dynamicSlots;
5859
protected boolean initialFocusSet;
@@ -323,7 +324,6 @@ record PreviousElement(int index, GuiElement element, boolean wasFocus) {
323324

324325
@Override
325326
protected void renderLabels(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) {
326-
//PoseStack modelViewStack = RenderSystem.getModelViewStack();
327327
//Note: We intentionally don't push the modelViewStack, see notes further down in this method for more details
328328
//TODO - 1.20: Figure this out as some transforms and hacks may be unnecessary now
329329
PoseStack pose = guiGraphics.pose();
@@ -379,14 +379,11 @@ protected void renderLabels(@NotNull GuiGraphics guiGraphics, int mouseX, int mo
379379
//TODO - 1.20: Can we remove these transforms that are around the tooltip rendering
380380
// No, we maybe could remove from the tooltip element portion but definitely not from the stack rendering/parent renderTooltip method
381381
pose.translate(-leftPos, -topPos, 0);
382-
//modelViewStack.translate(-leftPos, -topPos, 0);
383-
//RenderSystem.applyModelViewMatrix();
384382
if (tooltipElement != null) {
385383
tooltipElement.renderToolTip(guiGraphics, mouseX, mouseY);
386384
}
387385
renderTooltip(guiGraphics, mouseX, mouseY);
388386
pose.translate(leftPos, topPos, 0);
389-
//modelViewStack.translate(leftPos, topPos, 0);
390387

391388
// IMPORTANT: additional hacky translation so held items render okay. re-evaluate as discussed above
392389
// Note: It is important that we don't wrap our adjustments to the modelViewStack in so that we can
@@ -395,6 +392,23 @@ protected void renderLabels(@NotNull GuiGraphics guiGraphics, int mouseX, int mo
395392
pose.translate(0, 0, 200);
396393
}
397394

395+
/**
396+
* @implNote Copy of super, but adjusts the z value for tooltip rendering
397+
*/
398+
@Override
399+
public final void renderWithTooltip(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
400+
render(graphics, mouseX, mouseY, partialTick);
401+
if (deferredTooltipRendering != null) {
402+
PoseStack pose = graphics.pose();
403+
pose.pushPose();
404+
//Note: extra z offset comes from the offset we do in render
405+
pose.translate(0, 0, EXTRA_Z_OFFSET + maxZOffset);
406+
graphics.renderTooltip(font, deferredTooltipRendering.tooltip(), deferredTooltipRendering.positioner(), mouseX, mouseY);
407+
clearTooltipForNextRenderPass();
408+
pose.popPose();
409+
}
410+
}
411+
398412
protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) {
399413
}
400414

@@ -684,7 +698,7 @@ public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, flo
684698
pose.pushPose();
685699
// shift back a whole lot so we can stack more windows
686700
//TODO - 1.20: Validate this, used to translate the modelViewStack
687-
pose.translate(0, 0, -500);
701+
pose.translate(0, 0, EXTRA_Z_OFFSET);
688702
super.render(guiGraphics, mouseX, mouseY, partialTicks);
689703
pose.popPose();
690704
}

src/main/java/mekanism/client/gui/element/text/GuiTextField.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
203203

204204
//TODO - 1.21: Figure out why Guis with text fields seem to still have issues with https://github.com/emilyploszaj/emi/issues/480 when other ones don't
205205
// and it doesn't seem related to any of the code inside this draw background block
206+
// There is also an issue if enough gui windows are open, where EMI then renders the tooltip behind the third crafting window, which might be related
206207
@Override
207208
public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
208209
super.drawBackground(guiGraphics, mouseX, mouseY, partialTicks);

src/main/resources/META-INF/accesstransformer.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ protected net.minecraft.client.gui.screens.inventory.AbstractContainerScreen isH
3939
protected net.minecraft.client.gui.screens.inventory.AbstractContainerScreen renderSlot(Lnet/minecraft/client/gui/GuiGraphics;Lnet/minecraft/world/inventory/Slot;)V
4040
protected net.minecraft.client.gui.screens.inventory.AbstractContainerScreen checkHotbarMouseClicked(I)V
4141

42+
# Used to fix the z level of tooltip rendering
43+
public net.minecraft.client.gui.screens.Screen$DeferredTooltipRendering
44+
public net.minecraft.client.gui.screens.Screen deferredTooltipRendering
45+
public-f net.minecraft.client.gui.screens.Screen renderWithTooltip(Lnet/minecraft/client/gui/GuiGraphics;IIF)V
46+
4247
public net.minecraft.client.model.AgeableListModel scaleHead
4348
public net.minecraft.client.model.AgeableListModel babyHeadScale
4449
public net.minecraft.client.model.AgeableListModel babyBodyScale

0 commit comments

Comments
 (0)