Jump to content

How do you add color to a TextComponent in forge 1.17.1?


Parent

Recommended Posts

I was wondering how I could add/format color to a TextComponent in the following code:

event.getPlayer().sendMessage(new TextComponent("Red colored, blue, and this is bold!"),event.getPlayer().getUUID());

I'm new to this version and it's a bit confusing. Any help would be appreciated. Thanks.

Link to comment
Share on other sites

1 minute ago, Parent said:

I was wondering how I could add/format color to a TextComponent in the following code:

event.getPlayer().sendMessage(new TextComponent("Red colored, blue, and this is bold!"),event.getPlayer().getUUID());

I'm new to this version and it's a bit confusing. Any help would be appreciated. Thanks.

Did you try with vanilla color codes? For example, putting &4 in front of the "Red" will make the string red. You can also try using § instead of &.

  • Thanks 1
Link to comment
Share on other sites

2 minutes ago, uSkizzik said:

Did you try with vanilla color codes? For example, putting &4 in front of the "Red" will make the string red. You can also try using § instead of &.

Never thought that would be so simple. Spend a whole hour trying to figure it out. Thanks a lot.

Link to comment
Share on other sites

If you want the more future proof in-code solution that doesn't require an arbitrary hardcoded string interpolation,
 

.withStyle(ChatFormatting.GOLD)

this call on the `TextComponent` will color it. You can use any ChatFormatting enum constant, including ones that are added after the fact, and you don't have to consult some table on the internet to find what you want.

Link to comment
Share on other sites

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.