Minecraft:Text component format/Before Java Edition 1.21.5
More actions
|
For the {{{Description}}} of the same name, see [[{{{Destination}}}]]. |
Before Minecraft:Java Edition 1.21.5, the text component format was very different. The biggest difference is that text components were represented exclusively in Minecraft:JSON and saved as strings containing Minecraft:JSON, rather than being represented as Minecraft:SNBT and saved as Minecraft:NBT objects.
For example, instead of {text: "Hello World", color: "red"}, you would write {"text": "Hello World", "color": "red"} or '{"text":"Hello World","color":"red"}' depending on the context.
The biggest reason why this was the case is that NBT did not support heterogenous lists whereas JSON did, but in 1.21.5 this was changed so text components no longer needed to be saved as JSON.<ref>https://minecraft.wiki/w/NBT_format#History</ref>
Format
The format is made up of text components. There is a single root component, which can have child components, which can have their own children and so on. Components can also have formatting and interactivity added to them, which is inherited by their children.
A component can be a Template:Nbt string, Template:Nbt array or a Template:Nbt object. Strings and arrays are both shorthand for longer object structures, as described below.
- Template:Nbt A string containing plain text to display directly. This is the same as an object that only has a Template:Nbt tag. For example,
"A"and{"text": "A"}are equivalent. - Template:Nbt A list of components. Same as having all components after the first one appended to the first's Template:Nbt array. For example,
["A", "B", "C"]is equivalent to{"text": "A", "extra": ["B", "C"]}. Note that because the later components are actually children of the first one, any formatting applied to the first component is inherited by the later ones. For example,[{"text": "A", "color": "red"}, "B", "C"]will display all three letters with red text. - Template:Nbt A text component object. All non-content tags are optional.
- Content
- Template:Nbt: Optional. Specifies the content type. One of Template:Code, Template:Code, Template:Code, Template:Code, Template:Code, or Template:Code.
- If Template:Nbt is not present, has an invalid value, or if the required tags for the specified type are not present, the type is determined automatically by checking the object for the following tags: [[#Plain Text|Template:Nbt]], [[#Translated Text|Template:Nbt]], [[#Scoreboard Value|Template:Nbt]], [[#Entity Names|Template:Nbt]], [[#Keybind|Template:Nbt]], and finally [[#NBT Values|Template:Nbt]]. If multiple are present, whichever one comes first in that list is used.
- Values specific to each content type are described below.
- Children
- Template:Nbt: A list of additional components to be displayed after this one.
- A child text component. Child text components inherit all formatting and interactivity from the parent component, unless they explicitly override them.
- Template:Nbt: A list of additional components to be displayed after this one.
- Formatting
- Template:Nbt: Optional. Changes the color to render the content in the text component object and its child objects. If not present, the parent color will be used instead. The color is specified as a color code or as a color name.
"#<hex>", where<hex>is a 6-digit hexadecimal color, changes the color to #<hex>"black"changes the color to Template:Color"dark_blue"changes the color to Template:Color"dark_green"changes the color to Template:Color"dark_aqua"changes the color to Template:Color"dark_red"changes the color to Template:Color"dark_purple"changes the color to Template:Color"gold"changes the color to Template:Color"gray"changes the color to Template:Color"dark_gray"changes the color to Template:Color"blue"changes the color to Template:Color"green"changes the color to Template:Color"aqua"changes the color to Template:Color"red"changes the color to Template:Color"light_purple"changes the color to Template:Color"yellow"changes the color to Template:Color"white"changes the color to Template:Color
- Template:Nbt: Optional. The resource location of the font for this component in the resource pack within
assets/<namespace>/font. Defaults to"minecraft:default". - Template:Nbt: Optional. Whether to render the content in bold.
- Template:Nbt: Optional. Whether to render the content in italics. Note that text that is italicized by default, such as custom item names, can be unitalicized by setting this to
false. - Template:Nbt: Optional. Whether to underline the content.
- Template:Nbt: Optional. Whether to strikethrough the content.
- Template:Nbt: Optional. Whether to render the content obfuscated.
- Template:NbtTemplate:Nbt: Optional. Sets the color of the text shadow. The decimal value is calculated with (alpha << 24) + (red << 16) + (green << 8 ) + blue, where each component is between 0 and 255. In list format it expects 4 float values between 0 and 1 for alpha, red, green, blue.
- Template:Nbt: Optional. Changes the color to render the content in the text component object and its child objects. If not present, the parent color will be used instead. The color is specified as a color code or as a color name.
- Interactivity
- Template:Nbt: Optional. When the text is shift-clicked by a player, this string is inserted in their chat input. It does not overwrite any existing text the player was writing. This only works in chat messages.
- Template:Nbt: Optional. Allows for events to occur when the player clicks on text. Only work in chat messages and Minecraft:written books, unless specified otherwise.
- Template:Nbt: The action to perform when clicked. Valid values are:
"open_url": Opens Template:Nbt as a URL in the user's default web browser."open_file": Opens the file at Template:Nbt on the user's computer. This is used in messages automatically generated by the game (e.g., on taking a screenshot) and cannot be used by players for security reasons."run_command": Works in signs, but only on the root text component, not on any children. Activated by Template:Control the sign. In chat and written books, this has Template:Nbt entered in chat as though the player typed it themselves and pressed enter. However, this can only be used to run commands that do not send chat messages directly (like Template:Cmd, Template:Cmd, andTemplate:Cmd). Since they are being run from chat, commands must be prefixed with the usual "/" slash, and player must have the required permissions. In Minecraft:signs, the command is run by the server at the sign's location, with the player who Template:Control the sign as the command executor (that is, the entity selected by@s). Since they are run by the server, sign commands have the same permission level as a Minecraft:command block instead of using the player's permission level, are not restricted by chat length limits, and do not need to be prefixed with a "/" slash."suggest_command": Opens chat and fills in Template:Nbt. If a chat message was already being composed, it is overwritten. This does not work in books.<ref>Template:Bug</ref>"change_page": Can only be used in written books. Changes to page Template:Nbt if that page exists."copy_to_clipboard": Copies Template:Nbt to the clipboard.
- Template:Nbt: The URL, file path, chat, command or book page used by the specified action.
- Template:Nbt: The action to perform when clicked. Valid values are:
- Template:Nbt: Optional. Allows for a tooltip to be displayed when the player hovers their mouse over text.
- Template:Nbt: The type of tooltip to show. Valid values are:
"show_text": Shows a text component."show_item": Shows the tooltip of an item as if it was being hovering over it in an inventory."show_entity": Shows an entity's name, type, and UUID. Used by Template:Nbt.
- Template:Nbt: The formatting of this tag varies depending on the action.
- For
"show_text": Another text component. Can be any valid text component type: string, array, or object. Note that Template:Nbt and Template:Nbt do not function within the tooltip. - For
"show_item": The item stack whose tooltip that should be displayed.- Template:Nbt: The item's Minecraft:resource location. Defaults to Template:Code if invalid.
- Template:Nbt: Optional. Size of the item stack. This typically does not change the content tooltip.
- Template:Nbt: Optional. Additional information about the item. See item components.
- For
"show_entity": The entity whose tooltip should be displayed.- Template:Nbt: Optional. Hidden if not present. A text that is displayed as the name of the entity.
- Template:Nbt: A string containing the type of the entity, as a Minecraft:resource location. Defaults to Template:Code if invalid.
- Template:NbtTemplate:Nbt: The Minecraft:UUID of the entity. Either:
- A string representing the UUID in the hyphenated hexadecimal format. Must be a valid UUID.
- A list of four numbers representing the UUID in int-array format. As this is JSON and not SNBT there is no dedicated integer array type, so the int-array format looks like Template:Code rather than Template:Code. Fractional numbers and numbers outside the 32-bit integer range will be truncated. Booleans are also permitted, with Template:Code and Template:Code converting to 1 and 0 respectively.
- For
- Template:NbtTemplate:NbtTemplate:Nbt: Deprecated, use Template:Nbt instead. The formatting and type of this tag varies depending on the action.
- For
"show_text": Another text component. Can be any valid text component type: string, array, or object. Note that Template:Nbt and Template:Nbt do not function within the tooltip. - For
"show_item": A string containing the SNBT for an item stack. See Template:Slink. - For
"show_entity": A string containing SNBT. The SNBT does not represent the full entity data, but only stores the name, type, and UUID of the entity.- Template:Nbt: Optional. Hidden if not present. An NBT string containing some JSON that is parsed as a text component and displayed as the name of the entity.
- Template:Nbt: Optional. An NBT string containing the type of the entity, as a Minecraft:resource location. Defaults to Template:Code if invalid or missing.
- Template:Nbt: An NBT string containing the UUID of the entity in the hyphenated hexadecimal format. Must be a valid UUID.
- For
- Template:Nbt: The type of tooltip to show. Valid values are:
- Content
Due to the Template:Nbt tag, the above format may be recursively nested to produce complex and functional text strings. However, a text component doesn't have to be complicated at all: virtually all properties are optional and may be left out.
Content types
Text components can display several types of content. These tags should be included directly into the text component object.
Plain Text
Displays plain text.
- Template:Nbt The text component.
- Template:Nbt: Optional. Set to Template:Code.
- Template:Nbt: A string containing plain text to display directly.
Translated Text
Displays a translated piece of text from the currently selected Minecraft:language. This uses the client's selected language, so if players with their games set to different languages are logged into the same server, each will see the component in their own language.
Translations are defined in language files in Minecraft:resource packs, including the built-in resource pack.
Translations can contain slots for text that is not known ahead of time, such as player names. When displaying the translated text, slots will be filled from a provided list of text components. The slots are defined in the language file, and generally take the form %s (displays the next component in the list), or %3$s (displays the third component in the list; replace 3 with whichever index is desired).<ref group=note>Selecting the "next" argument ignores slots that specify an index explicitly. So if the translation text "Hello %s, %2$s, and %s." was given the components "John" and "Becky", it would display "Hello John, Becky, and Becky."</ref> For example, the built-in English language file contains the translation "chat.type.advancement.task": "%s has made the advancement %s",.
- Template:Nbt The text component.
- Template:Nbt: Optional. Set to Template:Code.
- Template:Nbt: A translation identifier, corresponding to the identifiers found in loaded language files. Displayed as the corresponding text in the player's selected language. If no corresponding translation can be found, the identifier itself is used as the translated text.
- Template:Nbt: Optional. If no corresponding translation can be found, this is used as the translated text. Ignored if Template:Nbt is not present.
- Template:Nbt: Optional. A list of text components to be inserted into slots in the translation text. Ignored if Template:Nbt is not present.
- A text component. If no component is provided for a slot, the slot is displayed as no text.
Scoreboard Value
Displays a score from the Minecraft:scoreboard.
| Requires component resolution. |
|---|
| This component is resolved into a Template:Nbt component containing the scoreboard value. |
- Template:Nbt The text component.
- Template:Nbt: Optional. Set to Template:Code.
- Template:Nbt: Displays a score holder's current score in an objective. Displays nothing if the given score holder or the given objective do not exist, or if the score holder is not tracked in the objective.
- Template:Nbt: The name of the score holder whose score should be displayed. This can be a Minecraft:selector like @p or an explicit name. If the text is a selector, the selector must be guaranteed to never select more than one entity, possibly by adding
limit=1. If the text is"*", it shows the reader's own score (for example,/tellraw @a {"score":{"name":"*","objective":"obj"}}shows every online player their own score in the "obj" objective).<ref group="note">Showing the reader's own score only works in situations where a message has one singular reader. That is chat messages,/titles, and written books. It does not work for Minecraft:bossbar display names or blocks like signs.</ref> - Template:Nbt: The internal name of the objective to display the player's score in.
- Template:Nbt: The name of the score holder whose score should be displayed. This can be a Minecraft:selector like @p or an explicit name. If the text is a selector, the selector must be guaranteed to never select more than one entity, possibly by adding
Entity Names
Displays the name of one or more entities found by a Minecraft:selector.
If exactly one entity is found, the entity's name is displayed by itself. If more are found, their names are displayed in the form "Name1, Name2, Name3", with gray commas. If none are found, the component is displayed as no text.
Hovering over a name shows a tooltip with the name, type, and Minecraft:UUID of the target. Clicking a player's name suggests a command to whisper to that player. Shift-clicking a player's name inserts that name into chat. Shift-clicking a non-player entity's name inserts its UUID into chat.
| Requires component resolution. |
|---|
|
- Template:Nbt The text component.
- Template:Nbt: Optional. Set to Template:Code.
- Template:Nbt: A string containing a Minecraft:selector.
- Template:Nbt: Optional, defaults to
{"color": "gray", "text": ", "}. A text component. Used as the separator between different names, if the component selects multiple entities.
Keybind
Displays the name of the button that is currently bound to a certain configurable control. This uses the client's own control scheme, so if players with different control schemes are logged into the same server, each will see their own keybind.
- Template:Nbt The text component.
- Template:Nbt: Optional. Set to Template:Code.
- Template:Nbt: A keybind identifier, to be displayed as the name of the button that is currently bound to that action. For example,
{"keybind": "key.inventory"}displays "e" if the player is using the default control scheme.
NBT Values
Displays NBT values from entities, block entities, or command storage.
NBT strings display their contents. Other NBT values are displayed as SNBT, with no spacing between symbols. If Template:Nbt is set to true, the game will instead attempt to parse and display that text as its own text component. That usually only works on strings, since JSON and SNBT are not compatible. If Template:Nbt is true and parsing fails, the component is displayed as no text. If more than one NBT value is found, either by selecting multiple entities or by using a multi-value path, they are displayed in the form "Value1, Value2, Value3, Value4".
| Requires component resolution. |
|---|
|
- Template:Nbt The text component.
- Template:Nbt: Optional. Set to Template:Code.
- Template:Nbt: Optional. Allowed values are Template:Code, Template:Code, and Template:Code, corresponding to the source of the NBT data.
- Template:Nbt: The NBT path used for looking up NBT values from an entity, block entity, or storage. Requires one of Template:Nbt, Template:Nbt, or Template:Nbt. Having more than one is allowed, but only one is used.<ref group=note>If Template:Nbt is left unspecified, NBT sources are checked in the order Template:Nbt, Template:Nbt, Template:Nbt. If multiple are present, whichever one comes first in that list is used.</ref>
- Template:Nbt: Optional, defaults to false. If true, the game attempts to parse the text of each NBT value as a text component. Ignored if Template:Nbt is not present.
- Template:Nbt: Optional, defaults to
", ". A text component. Used as the separator between different tags, if the component selects multiple tags. - Template:Nbt: A string specifying the coordinates of the block entity from which the NBT value is obtained. The coordinates can be absolute, relative, or local. Ignored if Template:Nbt is not present.
- Template:Nbt: A string specifying the target selector for the entity or entities from which the NBT value is obtained. Ignored if Template:Nbt is not present.
- Template:Nbt: A string specifying the Minecraft:resource location of the Minecraft:command storage from which the NBT value is obtained. Ignored if Template:Nbt is not present.
Component resolution
Certain text content types (Template:Nbt, Template:Nbt, and Template:Nbt) do not work in all contexts. These content types need to be resolved, which involves retrieving the appropriate data from the world, rendering it into "simple" text components, and replacing the "advanced" text component with that. This resolution can be done by Minecraft:signs, by Minecraft:written books when they are first opened, by Minecraft:boss bar names, by Minecraft:text displays, and by commands such as /tellraw and /title. It can also be done by the item modifers set_name and set_lore, but only if their Template:Nbt tag is set. Custom item names, custom entity names and Minecraft:scoreboard objective names cannot by themselves resolve these components.
Additionally, resolution fixes a single value in place. Therefore, these content types are not dynamic, and don't update to reflect changes in their environment, while "simple" components usually do.
History
See also
External links
Notes
References
Template:Navbox Java Edition technical Template:Navbox Bedrock Edition