Jump to content

Recommended Posts

Posted

This is the first mod I've worked on in a few years now, last time I made a mod the current version of MC was 1.12.

I've been trying to get this send message to all players to work for about 2 days now, I've looked at sources for inspiration on why my message sends json instead of formatted text, to no avail.

  Reveal hidden contents

 

2021-05-09_00.51.21.png

Posted
  On 5/9/2021 at 8:19 AM, diesieben07 said:

You cannot use toString on an ITextComponent, it will just give you a representation of its data (not JSON, by the way).

Instead of trying to replace in a string you should simply use text interpolation, which translation components support by defaut:

// in your language file:
"mymod.chatmessage": "%1$s went to bed. Sweet dreams!"

// in your code:
message = new TranslationTextComponent("mymod.chatmessage", player.getDisplayName());

 

Expand  

Thank you for that.

Is it this part that is causing the representation, because I don't see any other spot where I use toString? "sleepingPlayer.getDisplayName().toString()"

  • joelstoner changed the title to [Solved]Send message to player sending json [1.16.5]

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.