Skip to content

LabelComponent nullable data type error on hoveredStyle for drawTooltip function causes the game to crash #470

@Jimmy474

Description

@Jimmy474

the minecraft function private void componentHoverEffect(final Font font, final Style hoveredStyle, final int xMouse, final int yMouse) has changed in the version 26.1 . previously the parameter was nullable but in the latest version they made it non nullable.

the LabelComponent however has this draw tooltip function with style function returning nulls

@Override
public void drawTooltip(OwoUIGraphics context, int mouseX, int mouseY, float partialTicks, float delta) {
    super.drawTooltip(context, mouseX, mouseY, partialTicks, delta);
    context.componentHoverEffect(this.textRenderer, this.styleAt(mouseX - this.x, mouseY - this.y), mouseX, mouseY);
}

@Nullable
protected Style styleAt(int mouseX, int mouseY) {
    var clickHandler = new RawLabel.Instance.StyleCollector(this.textRenderer, this.x + mouseX, this.y + mouseY);
    this.drawText((renderX, renderY, text, $, $$) -> clickHandler.accept(renderX, renderY, text));

    return clickHandler.result();
}

this causes the game to crash because of Null error when you hover over label but only if you hover over empty area of the label component.

for example

if the label has width of 100 but text doesn't need that much space, if you hover over text it works fine but if you hover over empty label area you get null error because there is no text to style at the given location.

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