Jump to content

[1.10.2]Weird TextComponentTranslation formatting reset


Recommended Posts

Hello there!


I stumbled across this issue, where messages formatted incorrectly when using TextComponentTranslation with formatting. See this screenshot:




Message "Director block at (-580..." breaks the formatting after an argument gets replaced. The same thing happens to "The director block, that was attached..." label, however it has additional formatting, because the numbers should be colored in dark red. Both of those strings are look like this in en_US.lang:


blockbuster.success.director.play=§aDirector block at (%s, %s, %s) has started playing!
blockbuster.error.director.missing=§cThe director block, that was attached to this device at (§4%s§c, §4%s§c, §4%s§c), was destroyed or moved. Attach this device to another director block!


And they're both sent this way (on the server):


/* Director block at ... */
sender.addChatMessage(new TextComponentTranslation("blockbuster.success.director.play", args[1], args[2], args[3]));

/* The director block, that was attached... */
player.addChatMessage(new TextComponentTranslation("blockbuster.error.director.missing", pos.getX(), pos.getY(), pos.getZ()));


However, you as you can see also on the screenshot, there's another error message that says "Morph by name ..." colors correctly. This one, actually, sent from client side (client side command) this way:


sender.addChatMessage(new TextComponentString(I18n.format("blockbuster.success.morph.enable", args[0])));


And now is the question. Is there a way to avoid formatting reset when specifying arguments to TextComponentTranslation without much hassle like creating ITextComponent for every argument with its own formatting (thus hardcoding color formatting)? I know that I can use the TextComponentString + I18n.format, but will it work on dedicated server?


Thank you for attention! :)

Blockbuster – simple machinimas and cinematics for Minecraft
Link to comment
Share on other sites

I actually come up with another solution. Instead of wrapping every argument into ITextComponent, I create the parent ITextComponent with desired color for arguments, and then reset the color to my original color for the string, and I get what I wanted:


com.example.string=§aGreen label with a dark green %s§a meme!


And initiate the message like that:


String key = "com.example.string";

ITextComponent text = new TextComponentTranslation(key, "dank");


Blockbuster – simple machinimas and cinematics for Minecraft
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.

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.


  • Create New...

Important Information

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