Fix newline characters not rendering as line breaks - #840
Conversation
backports 1.8+ newline handling to two rendering paths: - chat messages: splits \n in incoming chat components into separate chat lines with format code carryover across line boundaries - drawString/drawStringWithShadow: splits on \n via the existing listFormattedStringToWidth infrastructure then renders each line with the original renderString, reusing all color/shadow/bidi setup config: fixChatNewlines, fixFontRendererNewlines (both default true)
502a705 to
f9a4fc8
Compare
DarkShadow44
left a comment
There was a problem hiding this comment.
This breaks some functionality:
- Minecraft allows replacing existing text, since you split into multiple parts this doesn't work properly - only one line gets replaces
- Additional info like "hover" or "on click" breaks. Since you create new text components no hover or click event gets carried over.
I made a test patch here: 0001-test.patch
You can test with my patch and /newlinetest, see my screenshots:
- The red line should have been removed
- The pink line isn't interactive - no hover or click works.
Without your changes
With your changes
DarkShadow44
left a comment
There was a problem hiding this comment.
Didn't test it yet, but I assume it works for now. Not really a fan of the self recursion in func_146237_a but it should work. the text splitting I didn't really understand, and I'm not sure copying the style is really enough, seeing how the interface could be implemented by different classes.
I have revamped the idea a bit, it didnt not work on full gtnh client only runClient, so i tried my best to be it clear and simple, it does work as intended |
|
I don't see any further issues - it does look good to me now - but I'm not confident I understand it enough to sign off on it. |
|
I'm fine with the chat gui fix but skeptical towards the FontRenderer change. Previously the caller would assume the draw would only ever occupy one line of y space (12~18px depending on UI style), now it can silently overdraw to next lines as well. this is highly unexpected and can corrupt UI in annoying ways, which is exactly why mojang on 1.8+ need caller to do this. IMO we should fix callers instead of trying to have fontrenderer babysit every drawString call |
Wouldn't this only happen if people added a newline character into the text? In that case it would render as |
Why yes! In fact, there are several places where one could insert user-provided text - text boxes, NBT, and the like. Rendering the symbol as In other words: Rendering a misplaced line break as |


\nin chat text renders invisible text concatenates on one line instead of breaking. the font renderer just iterates characters and treats\nas an empty glyph. mojang never fixed the renderer, in 1.8+ they just made callers split text before rendering.1.7.10 already has the splitting infra (
sizeStringToWidthcase 10,listFormattedStringToWidth), disconnect screen and hover tooltips use it. but the chat system anddrawString/drawStringWithShadowdon't this wires them through the existing splitter.\ninto separate chat lines with format carryoverlistFormattedStringToWidth(text, MAX_VALUE)then renders each line normallyworldedit, serverutilities, personalspace all have manual


split("\n")workarounds for this. with the fix future code doesn't need that.