Skip to content

Width of TextElementImpl is miscalculated when Caxton is present #717

@bluebear94

Description

@bluebear94

Mod loader

Fabric

Minecraft version

1.21.11

Mod version

21.1.1

Modloader version

Loader 0.18.2 + API 0.139.4+1.21.11

Modpack info

No response

[IMPORTANT] If bug:

  • I have confirmed this bug is reproducible on a minimal setup, not a modpack with many other mods.

[IMPORTANT] If bug: The latest.log file, not the crash report

https://gist.github.com/bluebear94/dd04c8b9f727c8efb69a783a86da3a85

Issue description

When Caxton 0.9.0-alpha.2+1.21.11-FABRIC is installed alongside Jade, the widths of TextElementImpl objects are miscalculated. This can result in the HUD tooltip appearing too wide:

Image

Issue on Caxton’s repository. I am reporting this both on Caxton’s repository and here because I’m not sure how to best fix this issue.

Steps to reproduce

  1. Start the game with Jade and Caxton and join a world
  2. Enable the bundled Inter resource pack
  3. Place a waxed weathered cut copper stairs block
  4. Look at that block

Expected behavior: The tooltip is just wide enough to fit the name of the block.

Actual behavior: The tooltip is wider than the name of the block.

Code analysis

  • Jade’s TextElementImpl calculates the width of a text according to DisplayHelper.font()
  • This returns an instance of JadeFont (code), which is a subclass of Font
  • Constructing a Font results in constructing a corresponding StringSplitter
  • When a StringSplitter is constructed, Caxton instantiates a corresponding CaxtonTextHandler (through mixin injection), but at this time, the appropriate font set accessor is not yet known, so the CTH has a dummy accessor
    • CaxtonTextHandler needs a font set accessor (a Function<Identifier, FontSet> derived from the font manager) instead of merely a WidthProvider because it requires complex text layout information from Caxton fonts.
  • When the Font is constructed, Caxton instantiates a CaxtonTextRenderer (again, through mixin injection), which creates the real CaxtonTextHandler (and thereby associates it with the vanilla StringSplitter held by Font)
  • After the Font constructor finishes, the JadeFont constructor sets the splitter to a new instance, which is left with a dummy font set accessor
  • As a result, when Jade tries to calculate the width of some text, it does so as if no fonts are loaded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions