Jade tooltips appear too wide with Caxton
Environment
- Caxton version: 0.9.0-alpha.2+1.21.11-FABRIC
- Minecraft version: 1.21.11
- Mod loader and version: Fabric Loader 0.18.2, Fabric API 0.139.4+1.21.11
- Operating system and CPU architecture: Linux x86_64
- Other mods: Jade 21.1.1+fabric
Summary
When Caxton and Jade are installed and a Caxton font (such as one of the two bundled resource packs) is enabled, then some HUD tooltips appear wider than needed to fit the text.
Steps to reproduce
- Start the game with Jade and Caxton and join a world
- Enable the bundled Inter resource pack
- Place a waxed weathered cut copper stairs block
- 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.
Relevant logs and/or screenshots
Misc
Thanks to Apis035 for reporting this on the CurseForge page comments.
Code analysis:
- Jade’s
TextElementImplcalculates the width of a text according toDisplayHelper.font() - This returns an instance of
JadeFont(code), which is a subclass ofTextRenderer - Constructing a
TextRendererresults in constructing a correspondingTextHandler - When a
TextHandleris constructed, Caxton instantiates a correspondingCaxtonTextHandler(through mixin injection), but at this time, the appropriate font storage accessor is not yet known, so the CTH has a dummy accessor - When the
TextRendereris constructed, Caxton instantiates aCaxtonTextRenderer(again, through mixin injection), which creates the realCaxtonTextHandler(and thereby associates it with the vanillaTextHandlerheld byTextRenderer) - After the
TextRendererconstructor finishes, theJadeFontconstructor sets the handler to a new instance, which is left with a dummy font storage accessor - As a result, when Jade tries to calculate the width of some text, it does so as if no fonts are loaded.
Edited by +merlan #flirora
