@@ -53,7 +53,6 @@ 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 ;
5756 //TODO: Look into defaulting this to true
5857 protected boolean dynamicSlots ;
5958 protected boolean initialFocusSet ;
@@ -324,11 +323,10 @@ record PreviousElement(int index, GuiElement element, boolean wasFocus) {
324323
325324 @ Override
326325 protected void renderLabels (@ NotNull GuiGraphics guiGraphics , int mouseX , int mouseY ) {
327- //Note: We intentionally don't push the modelViewStack, see notes further down in this method for more details
328- //TODO - 1.20: Figure this out as some transforms and hacks may be unnecessary now
329326 PoseStack pose = guiGraphics .pose ();
330- //TODO - 1.20: Re-evaluate?? this always was against the pose but what is it for
331- pose .translate (0 , 0 , 300 );
327+ pose .pushPose ();
328+ //Shift forward as far as tooltips get shifted so that we don't risk intersecting the rendered items
329+ pose .translate (0 , 0 , 400 );
332330 for (GuiEventListener c : children ()) {
333331 if (c instanceof GuiElement element ) {
334332 element .onDrawBackground (guiGraphics , mouseX , mouseY , MekanismRenderer .getPartialTick ());
@@ -363,50 +361,44 @@ protected void renderLabels(@NotNull GuiGraphics guiGraphics, int mouseX, int mo
363361 }
364362 pose .popPose ();
365363 }
364+ pose .popPose ();
366365 // then render tooltips, translating above max z offset to prevent clashing
366+ // It is IMPORTANT that we do this to ensure any delayed rendering we do the for the tooltip happens above the other things
367+ // and so that we let the translation leak out into the super method so that the carried item renders at the correct z level
368+ pose .translate (0 , 0 , maxZOffset );
369+
370+ pose .pushPose ();
371+ //Note: Because we are doing this from renderLabels instead of as part of a render override,
372+ // we need to unshift back to the position the other methods expect to be called from
373+ pose .translate (-leftPos , -topPos , 0 );
367374 GuiElement tooltipElement = getWindowHovering (mouseX , mouseY );
368375 if (tooltipElement == null ) {
369376 tooltipElement = (GuiElement ) GuiUtils .findChild (children (), mouseX , mouseY , (child , x , y ) -> child instanceof GuiElement && child .isMouseOver (x , y ));
370377 }
371-
372- // translate forwards using RenderSystem. this should never have to happen as we do all the necessary translations with MatrixStacks,
373- // but Minecraft has decided to not fully adopt MatrixStacks for many crucial ContainerScreen render operations. should be re-evaluated
374- // when mc updates related logic on their end (IMPORTANT)
375- //TODO - 1.20: Is this necessary used to occur on the model view stack
376- pose .translate (0 , 0 , maxZOffset );
377-
378- // render tooltips
379- //TODO - 1.20: Can we remove these transforms that are around the tooltip rendering
380- // No, we maybe could remove from the tooltip element portion but definitely not from the stack rendering/parent renderTooltip method
381- pose .translate (-leftPos , -topPos , 0 );
382378 if (tooltipElement != null ) {
383379 tooltipElement .renderToolTip (guiGraphics , mouseX , mouseY );
384380 }
385381 renderTooltip (guiGraphics , mouseX , mouseY );
386- pose .translate (leftPos , topPos , 0 );
387-
388- // IMPORTANT: additional hacky translation so held items render okay. re-evaluate as discussed above
389- // Note: It is important that we don't wrap our adjustments to the modelViewStack in so that we can
390- // have the adjustments to the z-value persist into the vanilla methods
391- //TODO - 1.20: Is this necessary (used to happen to the model view stack)
392- pose .translate (0 , 0 , 200 );
382+ pose .popPose ();
393383 }
394384
395385 /**
396386 * @implNote Copy of super, but adjusts the z value for tooltip rendering
397387 */
398388 @ Override
399389 public final void renderWithTooltip (@ NotNull GuiGraphics graphics , int mouseX , int mouseY , float partialTick ) {
390+ //Note: We wrap super with a push and pop, so that when we intentionally don't pop our changes in renderLabels
391+ // then we make sure to clean them up here
392+ PoseStack pose = graphics .pose ();
393+ pose .pushPose ();
400394 render (graphics , mouseX , mouseY , partialTick );
401395 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 );
396+ //Note: render has a pop at the end of it in vanilla, so we have to apply the deferred tooltip rendering again
397+ pose .translate (0 , 0 , maxZOffset );
406398 graphics .renderTooltip (font , deferredTooltipRendering .tooltip (), deferredTooltipRendering .positioner (), mouseX , mouseY );
407399 clearTooltipForNextRenderPass ();
408- pose .popPose ();
409400 }
401+ pose .popPose ();
410402 }
411403
412404 protected void drawForegroundText (@ NotNull GuiGraphics guiGraphics , int mouseX , int mouseY ) {
@@ -690,19 +682,6 @@ public Font getFont() {
690682 return font == null ? minecraft .font : font ;
691683 }
692684
693- //TODO - 1.20: Test this and everything else relating to the switch to guigraphics
694- // My guess is we may be able to remove the model view stack hacks??
695- @ Override
696- public void render (@ NotNull GuiGraphics guiGraphics , int mouseX , int mouseY , float partialTicks ) {
697- PoseStack pose = guiGraphics .pose ();
698- pose .pushPose ();
699- // shift back a whole lot so we can stack more windows
700- //TODO - 1.20: Validate this, used to translate the modelViewStack
701- pose .translate (0 , 0 , EXTRA_Z_OFFSET );
702- super .render (guiGraphics , mouseX , mouseY , partialTicks );
703- pose .popPose ();
704- }
705-
706685 @ Override
707686 public boolean currentlyQuickCrafting () {
708687 return isQuickCrafting && !quickCraftSlots .isEmpty ();
0 commit comments