Header component is incorrectly handling centered string
3TUSK opened this issue ยท 3 comments
Synopsis
In a header component used by a custom template, the field centered
has no effect regardless what value is set; it will always cause a left-aligned header to be rendered.
Reproduction
- Environment is Forge 14.23.5.2772 and Patchouli 1.0-11.55.
- Use this minimal template, and set value for
header_text
in the actual entry json, and then load it in-game.
{
"components": [
{
"type": "header",
"text": "#header_text",
"centered": true,
"x": 10,
"y": 0
}
]
}
- Sample picture of an entry page using the said template
Analysis
Right now two branches of the if-else clause shown above effectively does the same thing. However, according to documentation of header component:
- centered (boolean)
Defaults to true. Set to false to align the text to the left rather than center.
Therefore, the if-else clause should have been:
if(centered)
page.parent.drawCenteredStringNoShadow(text, GuiBook.PAGE_WIDTH / 2, 0, color);
else page.fontRenderer.drawString(text, 0, 0, color);
which is similar to:
https://github.com/Vazkii/Patchouli/blob/83c02b4c23a1f1f2cbf77acde96a57b238922261/src/main/java/vazkii/patchouli/client/book/page/PageText.java#L47-L48
Final words
dunno why this hasn't been noticed. Should be an easy fix; I can PR the fix if that's preferred.
Then centered property would only make sure the text width gets taken into account for its offset, setting x=-1 would do the rest.
My suggestion for a change would to change the previously linked lines to this
if(x == -1 || centered)
x = GuiBook.PAGE_WIDTH / 2;
This is intended behaviour @primetoxinz. You may want to center the header elsewhere other than the actual page center. This is properly documented in the Header Components section of the wiki.