I finally after many hours have figured out how to center backgrounds with negative spacing

image.png

This revelation comes from when I was looking through the helpchat discord for no reason in particular (not even a joke), when I found this message from LichtHund, an MCCI developer

image.png

this gave me a very important piece of info, if you just count the amount of pixels a background takes up, you can divide those pixels by your gui scale and get the amount to shift it by

image.png

Now obviously, we can’t just directly offset by this value, all that’d do is put the text right at the left side of the UI (70 spacing used for example because my fontset is in groups of 5)

image.png

What we need is to also take the length of the main text element and get the midpoint between those values

image.png

image.png

With this number, simply round to the nearest whole number (or up in my case because 60 is a clean multiple of 5) and you have yourself a centered text item

image.png

image.png

Discrepancy is likely due to rounding

Now with this, you might notice that it isn’t centered about the player’s hotbar

image.png

To fix this, we’ll need to offset the entire thing (text and bg) back by the remaining space on one side

image.png

And there you have it, a perfectly aligned text box