Minecraft:Text component format/Before Java Edition 1.21.5: Difference between revisions
More actions
Removed stray "a" |
Remove broken links to missing pages |
||
| Line 1: | Line 1: | ||
{{about|the text component format before | {{about|the text component format before Java Edition 1.21.5|the current format|Text component format}} | ||
{{outdated|Text component was previously JSON-based, but now | {{outdated|Text component was previously JSON-based, but now SNBT-based on Java Edition 1.21.5.|edition=java}} | ||
Before | Before 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 SNBT and saved as NBT objects. | ||
For example, instead of <code>{text: "Hello World", color: "red"}</code>, you would write <code>{"text": "Hello World", "color": "red"}</code> or <code>'{"text":"Hello World","color":"red"}'</code> depending on the context. | For example, instead of <code>{text: "Hello World", color: "red"}</code>, you would write <code>{"text": "Hello World", "color": "red"}</code> or <code>'{"text":"Hello World","color":"red"}'</code> depending on the context. | ||
| Line 26: | Line 26: | ||
** '''''Formatting''''' | ** '''''Formatting''''' | ||
*** {{nbt|string|color}}: 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. | *** {{nbt|string|color}}: 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. | ||
****<code>"#<i><hex></i>"</code>, where <code><i><hex></i></code> is a | ****<code>"#<i><hex></i>"</code>, where <code><i><hex></i></code> is a 6-digit hexadecimal color, changes the color to #<i><hex></i> | ||
****<code>"black"</code> changes the color to {{color|#000000}} | ****<code>"black"</code> changes the color to {{color|#000000}} | ||
****<code>"dark_blue"</code> changes the color to {{color|#0000AA}} | ****<code>"dark_blue"</code> changes the color to {{color|#0000AA}} | ||
| Line 43: | Line 43: | ||
****<code>"yellow"</code> changes the color to {{color|#FFFF55}} | ****<code>"yellow"</code> changes the color to {{color|#FFFF55}} | ||
****<code>"white"</code> changes the color to {{color|#FFFFFF}} | ****<code>"white"</code> changes the color to {{color|#FFFFFF}} | ||
*** {{nbt|string|font}}: Optional. The resource location of the | *** {{nbt|string|font}}: Optional. The resource location of the font for this component in the resource pack within <code>assets/<namespace>/font</code>. Defaults to <code>"minecraft:default"</code>. | ||
*** {{nbt|boolean|bold}}: Optional. Whether to render the content in bold. | *** {{nbt|boolean|bold}}: Optional. Whether to render the content in bold. | ||
*** {{nbt|boolean|italic}}: 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 <code>false</code>. | *** {{nbt|boolean|italic}}: 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 <code>false</code>. | ||
| Line 52: | Line 52: | ||
** '''''Interactivity''''' | ** '''''Interactivity''''' | ||
*** {{nbt|string|insertion}}: 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. | *** {{nbt|string|insertion}}: 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. | ||
*** {{nbt|compound|clickEvent}}: Optional. Allows for events to occur when the player clicks on text. Only work in chat messages and | *** {{nbt|compound|clickEvent}}: Optional. Allows for events to occur when the player clicks on text. Only work in chat messages and written books, unless specified otherwise. | ||
****{{nbt|string|action}}: The action to perform when clicked. Valid values are: | ****{{nbt|string|action}}: The action to perform when clicked. Valid values are: | ||
***** <code>"open_url"</code>: Opens {{nbt|string|value}} as a URL in the user's default web browser. | ***** <code>"open_url"</code>: Opens {{nbt|string|value}} as a URL in the user's default web browser. | ||
***** <code>"open_file"</code>: Opens the file at {{nbt|string|value}} 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. | ***** <code>"open_file"</code>: Opens the file at {{nbt|string|value}} 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. | ||
***** <code>"run_command"</code>: Works in signs, but ''only'' on the root text component, not on any children. Activated by {{control|using}} the sign. In chat and written books, this has {{nbt|string|value}} 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 {{cmd|say}}, {{cmd|tell}}, and{{cmd|teammsg}}). Since they are being run from chat, commands must be prefixed with the usual "/" slash, and player must have the required permissions. In [[Minecraft:sign]]s, the command is run by the server at the sign's location, with the player who {{control|used}} the sign as the command executor (that is, the entity selected by <code>@s</code>). Since they are run by the server, sign commands have the same permission level as a | ***** <code>"run_command"</code>: Works in signs, but ''only'' on the root text component, not on any children. Activated by {{control|using}} the sign. In chat and written books, this has {{nbt|string|value}} 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 {{cmd|say}}, {{cmd|tell}}, and{{cmd|teammsg}}). Since they are being run from chat, commands must be prefixed with the usual "/" slash, and player must have the required permissions. In [[Minecraft:sign]]s, the command is run by the server at the sign's location, with the player who {{control|used}} the sign as the command executor (that is, the entity selected by <code>@s</code>). Since they are run by the server, sign commands have the same permission level as a 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. | ||
***** <code>"suggest_command"</code>: Opens chat and fills in {{nbt|string|value}}. If a chat message was already being composed, it is overwritten. This does not work in books.<ref>{{bug|MC-70317|||Works as Intended}}</ref> | ***** <code>"suggest_command"</code>: Opens chat and fills in {{nbt|string|value}}. If a chat message was already being composed, it is overwritten. This does not work in books.<ref>{{bug|MC-70317|||Works as Intended}}</ref> | ||
***** <code>"change_page"</code>: Can only be used in written books. Changes to page {{nbt|string|value}} if that page exists. | ***** <code>"change_page"</code>: Can only be used in written books. Changes to page {{nbt|string|value}} if that page exists. | ||
| Line 69: | Line 69: | ||
***** For <code>"show_text"</code>: Another text component. Can be any valid text component type: string, array, or object. Note that {{nbt|compound|clickEvent}} and {{nbt|compound|hoverEvent}} do not function within the tooltip. | ***** For <code>"show_text"</code>: Another text component. Can be any valid text component type: string, array, or object. Note that {{nbt|compound|clickEvent}} and {{nbt|compound|hoverEvent}} do not function within the tooltip. | ||
***** For <code>"show_item"</code>: The item stack whose tooltip that should be displayed. | ***** For <code>"show_item"</code>: The item stack whose tooltip that should be displayed. | ||
****** {{nbt|string|id}}: The item's | ****** {{nbt|string|id}}: The item's resource location. Defaults to {{code|minecraft:air}} if invalid. | ||
****** {{nbt|int|count}}: Optional. Size of the item stack. This typically does not change the content tooltip. | ****** {{nbt|int|count}}: Optional. Size of the item stack. This typically does not change the content tooltip. | ||
****** {{nbt|compound|components}}: Optional. Additional information about the item. See | ****** {{nbt|compound|components}}: Optional. Additional information about the item. See item components. | ||
***** For <code>"show_entity"</code>: The entity whose tooltip should be displayed. | ***** For <code>"show_entity"</code>: The entity whose tooltip should be displayed. | ||
****** {{nbt|compound|name}}: Optional. Hidden if not present. A text that is displayed as the name of the entity. | ****** {{nbt|compound|name}}: Optional. Hidden if not present. A text that is displayed as the name of the entity. | ||
****** {{nbt|string|type}}: A string containing the type of the entity, as a | ****** {{nbt|string|type}}: A string containing the type of the entity, as a resource location. Defaults to {{code|minecraft:pig}} if invalid. | ||
****** {{nbt|string|}}{{nbt|list|id}}: The [[Minecraft:UUID]] of the entity. Either: | ****** {{nbt|string|}}{{nbt|list|id}}: The [[Minecraft:UUID]] of the entity. Either: | ||
******* A string representing the UUID in the hyphenated hexadecimal format. Must be a valid UUID. | ******* A string representing the UUID in the hyphenated hexadecimal format. Must be a valid UUID. | ||
| Line 83: | Line 83: | ||
***** For <code>"show_entity"</code>: A string containing SNBT. The SNBT does not represent the full entity data, but only stores the name, type, and UUID of the entity. | ***** For <code>"show_entity"</code>: A string containing SNBT. The SNBT does not represent the full entity data, but only stores the name, type, and UUID of the entity. | ||
****** {{nbt|string|name}}: 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. | ****** {{nbt|string|name}}: 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. | ||
****** {{nbt|string|type}}: Optional. An NBT string containing the type of the entity, as a | ****** {{nbt|string|type}}: Optional. An NBT string containing the type of the entity, as a resource location. Defaults to {{code|minecraft:pig}} if invalid or missing. | ||
****** {{nbt|string|id}}: An NBT string containing the UUID of the entity in the hyphenated hexadecimal format. Must be a valid UUID. | ****** {{nbt|string|id}}: An NBT string containing the UUID of the entity in the hyphenated hexadecimal format. Must be a valid UUID. | ||
</div> | </div> | ||
| Line 102: | Line 102: | ||
====Translated Text==== | ====Translated Text==== | ||
Displays a translated piece of text from the currently selected | Displays a translated piece of text from the currently selected 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 | Translations are defined in language files in 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 <code>%s</code> (displays the next component in the list), or <code>%3$s</code> (displays the third component in the list; replace <code>3</code> 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 <code>"chat.type.advancement.task": "%s has made the advancement %s",</code>. | 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 <code>%s</code> (displays the next component in the list), or <code>%3$s</code> (displays the third component in the list; replace <code>3</code> 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 <code>"chat.type.advancement.task": "%s has made the advancement %s",</code>. | ||
| Line 118: | Line 118: | ||
====Scoreboard Value==== | ====Scoreboard Value==== | ||
Displays a score from the | Displays a score from the scoreboard. | ||
{| class="wikitable collapsible collapsed" style="text-align:left;margin:0px;max-width:800px;" | {| class="wikitable collapsible collapsed" style="text-align:left;margin:0px;max-width:800px;" | ||
| Line 132: | Line 132: | ||
** {{nbt|string|type}}: Optional. Set to {{code|"score"}}. | ** {{nbt|string|type}}: Optional. Set to {{code|"score"}}. | ||
** {{nbt|compound|score}}: 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. | ** {{nbt|compound|score}}: 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. | ||
*** {{nbt|string|name}}: The name of the score holder whose score should be displayed. This can be a | *** {{nbt|string|name}}: The name of the score holder whose score should be displayed. This can be a 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 <code>limit=1</code>. If the text is <code>"*"</code>, it shows the reader's own score (for example, <code>/tellraw @a {"score":{"name":"*","objective":"obj"}}</code> 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, [[Minecraft:Commands/title|<code>/title</code>s]], and written books. It does not work for bossbar display names or blocks like signs.</ref> | ||
*** {{nbt|string|objective}}: The internal name of the objective to display the player's score in. | *** {{nbt|string|objective}}: The internal name of the objective to display the player's score in. | ||
</div> | </div> | ||
====Entity Names==== | ====Entity Names==== | ||
Displays the name of one or more entities found by a | Displays the name of one or more entities found by a 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. | 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. | ||
| Line 150: | Line 150: | ||
* If the selector finds a single entity, | * If the selector finds a single entity, | ||
** If the entity is a player, the component is resolved into a {{nbt|string|text}} component containing their name. | ** If the entity is a player, the component is resolved into a {{nbt|string|text}} component containing their name. | ||
** If it is an entity with a [[Minecraft:Name Tag|custom name]], it is resolved into the text component of the custom name. In all vanilla survival scenarios ( | ** If it is an entity with a [[Minecraft:Name Tag|custom name]], it is resolved into the text component of the custom name. In all vanilla survival scenarios (name tag, [[Minecraft:anvil]]) this will be a {{nbt|string|text}} component. | ||
** If it is a non-player entity with no custom name, it is resolved into a {{nbt|string|translate}} component containing the translation key for the entity type's name. | ** If it is a non-player entity with no custom name, it is resolved into a {{nbt|string|translate}} component containing the translation key for the entity type's name. | ||
: The resolved component also has an {{nbt|string|insertion}} tag, a {{nbt|compound|hoverEvent}} tag with the <code>show_entity</code> action, and a {{nbt|compound|clickEvent}} tag with the <code>suggest_command</code> action (if the entity is a player) added to it to provide the functionality described above. If any of these tags are already present on the original component being resolved, the tag on the original component will be used. | : The resolved component also has an {{nbt|string|insertion}} tag, a {{nbt|compound|hoverEvent}} tag with the <code>show_entity</code> action, and a {{nbt|compound|clickEvent}} tag with the <code>suggest_command</code> action (if the entity is a player) added to it to provide the functionality described above. If any of these tags are already present on the original component being resolved, the tag on the original component will be used. | ||
| Line 161: | Line 161: | ||
* {{nbt|compound}} The text component. | * {{nbt|compound}} The text component. | ||
** {{nbt|string|type}}: Optional. Set to {{code|"selector"}}. | ** {{nbt|string|type}}: Optional. Set to {{code|"selector"}}. | ||
** {{nbt|string|selector}}: A string containing a | ** {{nbt|string|selector}}: A string containing a selector. | ||
** {{nbt|compound|separator}}: Optional, defaults to <code>{"color": "gray", "text": ", "}</code>. A text component. Used as the separator between different names, if the component selects multiple entities. | ** {{nbt|compound|separator}}: Optional, defaults to <code>{"color": "gray", "text": ", "}</code>. A text component. Used as the separator between different names, if the component selects multiple entities. | ||
</div> | </div> | ||
====Keybind==== | ====Keybind==== | ||
Displays the name of the button that is currently bound to a certain | 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. | ||
<div class="treeview"> | <div class="treeview"> | ||
* {{nbt|compound}} The text component. | * {{nbt|compound}} The text component. | ||
** {{nbt|string|type}}: Optional. Set to {{code|"keybind"}}. | ** {{nbt|string|type}}: Optional. Set to {{code|"keybind"}}. | ||
** {{nbt|string|keybind}}: A | ** {{nbt|string|keybind}}: A keybind identifier, to be displayed as the name of the button that is currently bound to that action. For example, <code>{"keybind": "key.inventory"}</code> displays "e" if the player is using the default control scheme. | ||
</div> | </div> | ||
====NBT Values==== | ====NBT Values==== | ||
Displays | Displays NBT values from entities, [[Minecraft:Block entity|block entities]], or [[Minecraft:Commands/data#Storage|command storage]]. | ||
NBT strings display their contents. Other NBT values are displayed as SNBT, with no spacing between symbols. If {{nbt|boolean|interpret}} 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 {{nbt|boolean|interpret}} 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". | NBT strings display their contents. Other NBT values are displayed as SNBT, with no spacing between symbols. If {{nbt|boolean|interpret}} 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 {{nbt|boolean|interpret}} 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". | ||
| Line 196: | Line 196: | ||
** {{nbt|string|type}}: Optional. Set to {{code|"nbt"}}. | ** {{nbt|string|type}}: Optional. Set to {{code|"nbt"}}. | ||
** {{nbt|string|source}}: Optional. Allowed values are {{code|"block"}}, {{code|"entity"}}, and {{code|"storage"}}, corresponding to the source of the NBT data. | ** {{nbt|string|source}}: Optional. Allowed values are {{code|"block"}}, {{code|"entity"}}, and {{code|"storage"}}, corresponding to the source of the NBT data. | ||
** {{nbt|string|nbt}}: The | ** {{nbt|string|nbt}}: The NBT path used for looking up NBT values from an entity, block entity, or storage. Requires one of {{nbt|string|block}}, {{nbt|string|entity}}, or {{nbt|string|storage}}. Having more than one is allowed, but only one is used.<ref group=note>If {{nbt|string|source}} is left unspecified, NBT sources are checked in the order {{nbt|string|entity}}, {{nbt|string|block}}, {{nbt|string|storage}}. If multiple are present, whichever one comes first in that list is used.</ref> | ||
** {{nbt|boolean|interpret}}: Optional, defaults to false. If true, the game attempts to parse the text of each NBT value as a text component. Ignored if {{nbt|string|nbt}} is not present. | ** {{nbt|boolean|interpret}}: Optional, defaults to false. If true, the game attempts to parse the text of each NBT value as a text component. Ignored if {{nbt|string|nbt}} is not present. | ||
** {{nbt|compound|separator}}: Optional, defaults to <code>", "</code>. A text component. Used as the separator between different tags, if the component selects multiple tags. | ** {{nbt|compound|separator}}: Optional, defaults to <code>", "</code>. A text component. Used as the separator between different tags, if the component selects multiple tags. | ||
** {{nbt|string|block}}: A string specifying the coordinates of the block entity from which the NBT value is obtained. The coordinates can be absolute, [[Minecraft:Commands#Tilde and caret notation|relative]], or local. Ignored if {{nbt|string|nbt}} is not present. | ** {{nbt|string|block}}: A string specifying the coordinates of the block entity from which the NBT value is obtained. The coordinates can be absolute, [[Minecraft:Commands#Tilde and caret notation|relative]], or local. Ignored if {{nbt|string|nbt}} is not present. | ||
** {{nbt|string|entity}}: A string specifying the | ** {{nbt|string|entity}}: A string specifying the target selector for the entity or entities from which the NBT value is obtained. Ignored if {{nbt|string|nbt}} is not present. | ||
** {{nbt|string|storage}}: A string specifying the | ** {{nbt|string|storage}}: A string specifying the resource location of the command storage from which the NBT value is obtained. Ignored if {{nbt|string|nbt}} is not present. | ||
</div> | </div> | ||
=== Component resolution === | === Component resolution === | ||
Certain text content types ({{nbt|compound|score}}, {{nbt|string|selector}}, and {{nbt|string|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 | Certain text content types ({{nbt|compound|score}}, {{nbt|string|selector}}, and {{nbt|string|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 signs, by written books when they are first opened, by boss bar names, by text displays, and by commands such as [[Minecraft:Commands/tellraw|<code>/tellraw</code>]] and [[Minecraft:Commands/title|<code>/title</code>]]. It can also be done by the item modifers '''set_name''' and '''set_lore''', but only if their {{nbt|string|entity}} tag is set. Custom item names, custom entity names and 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. | 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. | ||
| Line 215: | Line 215: | ||
* [[Minecraft:JSON]] | * [[Minecraft:JSON]] | ||
* [[Minecraft:Commands]] | * [[Minecraft:Commands]] | ||
* | * Formatting code | ||
== External links == | == External links == | ||
| Line 232: | Line 232: | ||
{{Navbox Bedrock Edition}} | {{Navbox Bedrock Edition}} | ||
de:JSON-Text | |||
Latest revision as of 16:07, 9 April 2026
|
For the {{{Description}}} of the same name, see [[{{{Destination}}}]]. |
Before 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 SNBT and saved as 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 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 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 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 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 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 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 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 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 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 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 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 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 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 resource location of the 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 signs, by written books when they are first opened, by boss bar names, by 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 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
- Minecraft:JSON
- Minecraft:Commands
- Formatting code
External links
Notes
References
Template:Navbox Java Edition technical Template:Navbox Bedrock Edition
de:JSON-Text