Skip to content

[Bug Explanation/Fix] Tooltip Rendering Issue when Adding Layers with (0.11.2+1.20 targeted issue, though may exist in current) #460

@u9g

Description

@u9g

This code will cause hovered tooltips in the containerscreen gui to have no text rendered:

private fun chestCloseButtonInitializer(instance: Layer<ContainerScreen, FlowLayout>.Instance) {
        val closeButton = Components.button(
            net.minecraft.network.chat.Component.literal("Close")
        ) {
            Minecraft.getInstance().setScreen(null)
        }.sizing(Sizing.content(), Sizing.fixed(16))

        // Wrap in a fixed-width container to center it
        val buttonContainer = Containers.horizontalFlow(Sizing.fixed(176), Sizing.content())
            .child(closeButton)
            .horizontalAlignment(HorizontalAlignment. CENTER)

        instance.adapter.rootComponent.child(buttonContainer)

        // Position at x=0 (left edge of GUI), y=-18 (above GUI)
        instance.alignComponentToHandledScreenCoordinates(buttonContainer, 0, -18)
    }

    override fun onInitializeClient() {
        // make the instanceInitializer reference a class method so hot reload works.

        Layers.add(
            Containers::verticalFlow,
            ::chestCloseButtonInitializer,
            ContainerScreen::class.java
        )
}

This mixin fixes that issue:

package dev.u9g.utils.mixin.client;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.ContainerScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ContainerScreen.class)
public class ContainerScreenMixin {

    @Inject(method = "render", at = @At("TAIL"))
    private void flushTooltipBuffer(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick, CallbackInfo ci) {
        // Force the text vertices buffered during renderTooltip to draw NOW
        // before the method returns and the RenderSystem state changes.
        guiGraphics.flush();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions