mojira.dev
MC-299874

Selection boxes of plain messages within dialogs don’t render with black backgrounds

The Bug:

Selection boxes of plain messages within dialogs don’t render with black backgrounds.

Throughout the game, when a piece of text is selected, it normally renders with a black background, however, this isn’t the case for plain messages within dialogs.

Steps to Reproduce:

  1. Display a dialog with a plain message by using the command provided below.

    /dialog show @s {"type":"minecraft:notice","title":"MC-299874","body":{"type":"minecraft:plain_message","contents":"Click Me - I don't have a background."}}
  2. Click on the plain message and observe that the selection box doesn’t render with a black background.

Observed Behavior:

Selection boxes don’t render with black backgrounds.

Expected Behavior:

Selection boxes would render with black backgrounds.

Code Analysis:

The following is based on a decompiled version of Minecraft 26.3 Snapshot 4 using Mojang mappings.

A plain message in a dialog is a FocusableTextWidget, text you can click to select. It draws two separate things, the box around the text and the black background behind it, and each has its own setting.

net.minecraft.client.gui.screens.dialog.body.DialogBodyHandlers.java

private static class PlainMessageHandler implements DialogBodyHandler<PlainMessage> {
   public LayoutElement createControls(final DialogScreen<?> parent, final PlainMessage message) {
      return FocusableTextWidget.builder(message.contents(), parent.getFont())
         .maxWidth(message.width())
         .alwaysShowBorder(false)
         .backgroundFill(FocusableTextWidget.BackgroundFill.NEVER)
         .build()
         .setCentered(true)
         .setComponentClickHandler(style -> DialogBodyHandlers.runActionOnParent(parent, style));
   }
}

net.minecraft.client.gui.screens.multiplayer.RestrictionsScreen.java

body.addChild(
   FocusableTextWidget.builder(message, this.font)
      .maxWidth(250)
      .alwaysShowBorder(false)
      .backgroundFill(FocusableTextWidget.BackgroundFill.ON_FOCUS)
      .build()
      .setCentered(true)
);

If we look at the above classes, we can see that both build the same kind of selectable text, and differ in which background setting they ask for. ON_FOCUS fills the background in while the text is selected, NEVER never fills it in. The dialog asks for NEVER, so nothing is filled in, but the box is still drawn once the message is clicked.

Fixed Code:

net.minecraft.client.gui.screens.dialog.body.DialogBodyHandlers.java

private static class PlainMessageHandler implements DialogBodyHandler<PlainMessage> {
   public LayoutElement createControls(final DialogScreen<?> parent, final PlainMessage message) {
      return FocusableTextWidget.builder(message.contents(), parent.getFont())
         .maxWidth(message.width())
         .alwaysShowBorder(false)
         .backgroundFill(FocusableTextWidget.BackgroundFill.ON_FOCUS)
         .build()
         .setCentered(true)
         .setComponentClickHandler(style -> DialogBodyHandlers.runActionOnParent(parent, style));
   }
}

The above fills the background in while the message is selected, as the restrictions screen already does.

ALWAYS is the setting used by default and would also make the background appear. It was not used because it would draw a black background behind every plain message at all times, even when nothing is selected, changing how every dialog looks at rest. ON_FOCUS ties the background to the selection, which is what this report is about.

This change was applied to a modified client and tested against the steps above, and the selection box is now drawn with a black background.

Linked issues

Attachments

Comments 2

Avoma

(Unassigned)

Community Consensus

Platform HC

Normal

Accessibility, UI

1.21.8, 1.21.9, 26.2, 26.3

Retrieved