Jump to content

Get String from TextComponent with formatting codes


ConsumerJunk

Recommended Posts

Hi, thanks for taking the time to read my question.


I'm trying to emulate a custom FontRenderer. I say emulate because I don't want to create a custom FontRenderer, I just want to parse text into sections, then render those with the default FontRenderer. Normally that would be no problem, but in my case it's complicated by the fact that a TextComponent includes no way to get style data that I can modify (Or at least that I know of, hopefully the answers will shed some light on this). To simplify my general problem with a single question;

How could I get the string (including style codes) of a TextComponent?

What I'm hoping to achieve is get the string of a TextComponent, say "Player has made the advancement [Hot Stuff]" as "Player has made the advancement [§aHot Stuff]"

I've tried looking at the Style class, the problem here is I can't get the style for a specific part of a string

 

Thanks for reading my question

- ConsumerJunk

Link to comment
Share on other sites

All ITextProperties (which TextComponent extend) holds a method called getString which should do this for you iirc. If that doesn't work, you can always use one of the components that return an optional of the specific IStyledTextAcceptor passed in. However, you should look into using IReordingProcessor in some fashion similarly to FontRenderer for support in different languages. Worst case scenario, you get the JSON conversion of the specific text component and parse from there.

Link to comment
Share on other sites

  • Guest locked and unlocked this topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.