It would be nice to have a way to format String and Number in the current JSON tellraw command.
Indeed, if I want to print, for example, my X coordinate position:
/tellraw @s {"entity":"@s", "nbt":"Pos[0]"}
I have this result:

There are many problems in this result:
- Too many digits after decimal point
- The letter 'd' for type at the end
I suggest to add a new JSON tag to format the result according, for example, to the Java String.format function:
/tellraw @s {"entity":"@s", "nbt":"Pos[0]", "format":"%.3f"}
For this command, the result would be

Where the "%.3f" specify "3 digits after decimal point".
Other examples:
- "%04d" on 64 -> "0064" (d for "decimal integer")
- "%08.3f" on 624.798132 -> "0624.798"
- "%+d" on 64 -> "+64"
- "%+d" on -64 -> "-64"
And why not use it on String!
- "|%10s|" on "bar" -> "| bar|" (right align)
- "|%-10s|" on "bar" -> "|bar |" (left align)
- "|%10d|" on 5 -> "| 5|"
Other cool features (not supported by String.format):
- center align
- format int as a double, for example "%.1d" on 512 has for result "51.2"
The usage of this new JSON tag "format" remove automatically the type indicator ('d', 'f'...), if we just want to remove the letter without applying a specific format, we can juste use:
/tellraw @s {"entity":"@s", "nbt":"Pos[0]", "format":"%f"}
The String formatter syntax is maybe a bit complicated for a game like Minecraft, but is just an example to illustrate the functionnality :)
Please sign in to leave a comment.
0 Comments