dzwdz / chat_heads

Mozilla Public License 2.0
57 stars 34 forks source link

Compatibility with Caxton #114

Open 70CentsApple opened 3 weeks ago

70CentsApple commented 3 weeks ago

I know it could be difficult, but I still wonder the possibility to work with Caxton.

Caxton is a mod that modifies core shaders and text renderers, to provide smoother fonts.

When using the new default "Before Name" render mode, which modifies text renderers as well, the chat heads will just not render. (But old "Before Line" works fine)

Steps To Reproduce

  1. Install Caxton and launch the game.
  2. Enter a whatever world.
  3. Say something in chat, and yes, you can see the heads rendering quite well.
  4. Go to resource packs screen and enable Open Sans font (for example) provided by Caxton.
  5. Back to the chat screen, now you can see those heads disappeared.
Fourmisain commented 3 weeks ago

Hmm... Had a quick look at the code and I'm not confident if this is possible. Chat Heads relies on characters (by which I mean code points) being drawn one by one, adding an offset at the correct position so it can squeeze in a head to render.

Maybe something like this is doable by mixing into CaxtonTextRenderer's drawShapedRun, as there is a number of glyphs, each with their own advanceX.

The thing I'm not sure about is that while Vanilla renders text code point by code point, Caxton uses a text shaper, which (by my poor understanding) transforms code points into a bunch of glyphs, and it might turn multiple code points into one glyph, e.g. for things like ligatures. That makes it harder to count the number of drawn code points (to find where to put the head) - if this is possible at all, as that information might be lost in the shaping process. It might also end up inside a glyph and depending on how "conjoined" it is, the head can't be put at the "correct" position - though this does sound like a rare issue.

I might give this one a try some later time, I'm currently sick. 🤒

Fourmisain commented 5 days ago

I gave this another shot and had some success, but the implementation is definitely not correct and waiting to break. From what I read, a single character can render as multiple glyphs (so stuff can be "conjoined" and also spread out), which makes this seemingly impossible to get right.

One way I thought of is to split up the text in two parts, rendering them separately and putting a head inbetween, but I'm honestly even less sure if that'll be doable...

Meanwhile I just released a new version which forces Before Line rendering when Caxton (or Modern UI, which apparently has the same issue) is installed. At least there'll be a chat head, even if it's not where it's supposed to be.

Leaving this issue open in the hopes of fixing it proper one day.

70CentsApple commented 5 days ago

It's perfectly fine, I truly appreciate your effort. You've done a great job! ❤️