Minecraft:Text component format: Difference between revisions
More actions
Remove broken links to missing pages |
Fix template calls: add MC/ prefix |
||
| Line 1: | Line 1: | ||
{{About|text component format|the item components used {{ | {{About|text component format|the item components used {{MC/In|BE}}|Item components|the item components used {{MC/In|JE}}|Data component format}} | ||
The '''text component format''', historically also known as '''raw JSON text''', is used by ''Minecraft'' to send and display rich-text to players. It can also be sent by players themselves using commands (such as {{ | The '''text component format''', historically also known as '''raw JSON text''', is used by ''Minecraft'' to send and display rich-text to players. It can also be sent by players themselves using commands (such as {{MC/Cmd|tellraw}} and {{MC/Cmd|title}}) and data packs. | ||
== ''Java Edition'' == | == ''Java Edition'' == | ||
{{For|text component format used in versions before Java Edition 1.21.5|Text component format/Before Java Edition 1.21.5}} | {{MC/For|text component format used in versions before Java Edition 1.21.5|Text component format/Before Java Edition 1.21.5}} | ||
Text components are written in SNBT, for example {{cd|{text: "Hello world"<nowiki>}</nowiki>}}. They are used for rich-text formatting in written books, [[Minecraft:sign]]s, custom names and the {{ | Text components are written in SNBT, for example {{cd|{text: "Hello world"<nowiki>}</nowiki>}}. They are used for rich-text formatting in written books, [[Minecraft:sign]]s, custom names and the {{MC/Cmd|tellraw}}, {{MC/Cmd|title}}, {{MC/Cmd|bossbar}}, {{MC/Cmd|scoreboard}} and {{MC/Cmd|team}} commands. | ||
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. | 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 {{ | A component can be a {{MC/Nbt|string}} string, {{MC/Nbt|list}} list or a {{MC/Nbt|compound}} object. Strings and lists are both shorthand for longer object structures, as described below. | ||
<div class="treeview"> | <div class="treeview"> | ||
* {{ | * {{MC/Nbt|string}} A string containing plain text to display directly. This is the same as an object that only has a {{MC/Nbt|string|text}} tag. For example, <code>"A"</code> and <code>{text: "A"}</code> are equivalent. | ||
* {{ | * {{MC/Nbt|list}} A list of components. Same as having all components after the first one appended to the first's {{MC/Nbt|list|extra}} list. For example, <code>["A", "B", "C"]</code> is equivalent to <code>{text: "A", extra: ["B", "C"]}</code>. 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, <code>[{text: "A", color: "red"}, "B", "C"]</code> will display all three letters with red text. | ||
* {{ | * {{MC/Nbt|compound}} A text component object. All non-content tags are optional. | ||
**'''''Content''''' | **'''''Content''''' | ||
*** {{ | *** {{MC/Nbt|string|type}}: Optional. Specifies the content type. One of {{MC/Code|[[#Plain Text|"text"]]}}, {{MC/Code|[[#Translated Text|"translatable"]]}}, {{MC/Code|[[#Scoreboard Value|"score"]]}}, {{MC/Code|[[#Entity Names|"selector"]]}}, {{MC/Code|[[#Keybind|"keybind"]]}}, or {{MC/Code|[[#NBT Values|"nbt"]]}}. | ||
*** If {{ | *** If {{MC/Nbt|string|type}} 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|{{MC/Nbt|string|text}}]], [[#Translated Text|{{MC/Nbt|string|translate}}]], [[#Scoreboard Value|{{MC/Nbt|compound|score}}]], [[#Entity Names|{{MC/Nbt|string|selector}}]], [[#Keybind|{{MC/Nbt|string|keybind}}]], and finally [[#NBT Values|{{MC/Nbt|string|nbt}}]]. If multiple are present, whichever one comes first in that list is used. | ||
*** Values specific to each content type are described [[#Content types|below]]. | *** Values specific to each content type are described [[#Content types|below]]. | ||
** '''''Children''''' | ** '''''Children''''' | ||
*** {{ | *** {{MC/Nbt|list|extra}}: 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. | **** A child text component. Child text components inherit all formatting and interactivity from the parent component, unless they explicitly override them. | ||
** '''''Formatting''''' | ** '''''Formatting''''' | ||
*** {{ | *** {{MC/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 6-digit hexadecimal color, changes the color to #<i><hex></i> | ****<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}} | ||
| Line 42: | Line 42: | ||
****<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}} | ||
*** {{ | *** {{MC/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>. | ||
*** {{ | *** {{MC/Nbt|boolean|bold}}: Optional. Whether to render the content in bold. | ||
*** {{ | *** {{MC/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>. | ||
*** {{ | *** {{MC/Nbt|boolean|underlined}}: Optional. Whether to underline the content. | ||
*** {{ | *** {{MC/Nbt|boolean|strikethrough}}: Optional. Whether to strikethrough the content. | ||
*** {{ | *** {{MC/Nbt|boolean|obfuscated}}: Optional. Whether to render the content obfuscated. | ||
*** {{ | *** {{MC/Nbt|int|shadow_color}}: The color and opacity of the shadow. If omitted, the shadow is 25% the brightness of the text color and 100% the opacity{{MC/Verify}}. Color codes are the ARGB hex code of the color converted to a decimal number, or can be calculated from the opacity, red, green and blue components using this formula:<br>'''Alpha<<24 + <span style="color:red">Red</span><<16 + <span style="color:green">Green</span><<8 + <span style="color:blue">Blue</span>''' | ||
*** {{ | *** {{MC/Nbt|list|shadow_color}}: Another format. A list containing 4 floats corresponding to red, green, blue, and opacity values as a fraction (ranged 0 to 1, inclusive) that is automatically converted to the int format. | ||
** '''''Interactivity''''' | ** '''''Interactivity''''' | ||
*** {{ | *** {{MC/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. | ||
*** {{ | *** {{MC/Nbt|compound|click_event}}: Optional. Allows for events to occur when the player clicks on text. See {{slink||Click events}}. | ||
*** {{ | *** {{MC/Nbt|compound|hover_event}}: Optional. Allows for a tooltip to be displayed when the player hovers their mouse over text. See {{slink||Hover events}}. | ||
</div> | </div> | ||
Due to the {{ | Due to the {{MC/Nbt|list|extra}} 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 === | === Content types === | ||
| Line 65: | Line 65: | ||
<div class="treeview"> | <div class="treeview"> | ||
* {{ | * {{MC/Nbt|compound}} The text component. | ||
** {{ | ** {{MC/Nbt|string|type}}: Optional. Set to {{MC/Code|"text"}}. | ||
** {{ | ** {{MC/Nbt|string|text}}: A string containing plain text to display directly. | ||
</div> | </div> | ||
| Line 78: | Line 78: | ||
<div class="treeview"> | <div class="treeview"> | ||
* {{ | * {{MC/Nbt|compound}} The text component. | ||
** {{ | ** {{MC/Nbt|string|type}}: Optional. Set to {{MC/Code|"translatable"}}. | ||
** {{ | ** {{MC/Nbt|string|translate}}: 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. | ||
** {{ | ** {{MC/Nbt|string|fallback}}: Optional. If no corresponding translation can be found, this is used as the translated text. Ignored if {{MC/Nbt|string|translate}} is not present. | ||
** {{ | ** {{MC/Nbt|list|with}}: Optional. A list of text components to be inserted into slots in the translation text. Ignored if {{MC/Nbt|string|translate}} is not present. | ||
*** A text component. If no component is provided for a slot, the slot is displayed as no text. | *** A text component. If no component is provided for a slot, the slot is displayed as no text. | ||
</div> | </div> | ||
| Line 93: | Line 93: | ||
!Requires [[#Component resolution|component resolution]]. | !Requires [[#Component resolution|component resolution]]. | ||
|- | |- | ||
|This component is resolved into a {{ | |This component is resolved into a {{MC/Nbt|string|text}} component containing the scoreboard value. | ||
|- | |- | ||
|} | |} | ||
<div class="treeview"> | <div class="treeview"> | ||
* {{ | * {{MC/Nbt|compound}} The text component. | ||
** {{ | ** {{MC/Nbt|string|type}}: Optional. Set to {{MC/Code|"score"}}. | ||
** {{ | ** {{MC/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. | ||
*** {{ | *** {{MC/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> | ||
*** {{ | *** {{MC/Nbt|string|objective}}: The internal name of the objective to display the player's score in. | ||
</div> | </div> | ||
| Line 118: | Line 118: | ||
| | | | ||
* 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 {{ | ** If the entity is a player, the component is resolved into a {{MC/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 (name tag, [[Minecraft:anvil]]) this will be a {{ | ** 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 {{MC/Nbt|string|text}} component. | ||
** If it is a non-player entity with no custom name, it is resolved into a {{ | ** If it is a non-player entity with no custom name, it is resolved into a {{MC/Nbt|string|translate}} component containing the translation key for the entity type's name. | ||
: The resolved component also has an {{ | : The resolved component also has an {{MC/Nbt|string|insertion}} tag, a {{MC/Nbt|compound|hover_event}} tag with the <code>show_entity</code> action, and a {{MC/Nbt|compound|click_event}} 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. | ||
* If more than one entity is found by the selector, the component is resolved into an empty {{ | * If more than one entity is found by the selector, the component is resolved into an empty {{MC/Nbt|string|text}} component, with an {{MC/Nbt|list|extra}} list containing the individual entity name components (each resolved as in the single entity case) separated by copies of the {{MC/Nbt|any|separator}} component (or its default, if not present). | ||
* If no entities are found by the selector, the component is resolved into an empty {{ | * If no entities are found by the selector, the component is resolved into an empty {{MC/Nbt|string|text}} component. | ||
|- | |- | ||
|} | |} | ||
<div class="treeview"> | <div class="treeview"> | ||
* {{ | * {{MC/Nbt|compound}} The text component. | ||
** {{ | ** {{MC/Nbt|string|type}}: Optional. Set to {{MC/Code|"selector"}}. | ||
** {{ | ** {{MC/Nbt|string|selector}}: A string containing a selector. | ||
** {{ | ** {{MC/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> | ||
| Line 138: | Line 138: | ||
<div class="treeview"> | <div class="treeview"> | ||
* {{ | * {{MC/Nbt|compound}} The text component. | ||
** {{ | ** {{MC/Nbt|string|type}}: Optional. Set to {{MC/Code|"keybind"}}. | ||
** {{ | ** {{MC/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. As a fallback it displays the translation if it exists. | ||
</div> | </div> | ||
| Line 146: | Line 146: | ||
Displays NBT values from entities, [[Minecraft:Block entity|block entities]], or [[Minecraft:Commands/data#Storage|command storage]]. | 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 strings display their contents. Other NBT values are displayed as SNBT, with no spacing between symbols. If {{MC/Nbt|boolean|interpret}} is set to true, the game will instead attempt to parse and display that text as its own text component. That only works on compounds and lists which contain tags with the proper key names. If {{MC/Nbt|boolean|interpret}} is true and parsing fails, the component is displayed as no text, or if it directs to a string, shows the string itself. If more than one NBT value is found, either by selecting multiple entities or by using a multi-value path, they are displayed in order, with the {{MC/Nbt|any|separator}} value between them. | ||
{| 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 153: | Line 153: | ||
|- | |- | ||
| | | | ||
* If {{ | * If {{MC/Nbt|boolean|interpret}} is false, the component is resolved into a {{MC/Nbt|string|text}} component containing the display text. | ||
** If multiple values are selected, each value is resolved into an individual {{ | ** If multiple values are selected, each value is resolved into an individual {{MC/Nbt|string|text}} component, and all values after the first will be added to the first's {{MC/Nbt|list|extra}} list, separated by copies of the {{MC/Nbt|any|separator}} component. | ||
* If {{ | * If {{MC/Nbt|boolean|interpret}} is true, the component is resolved into the parsed text component. For any non-content tags that are present on both the parsed text component and the component being resolved, the tag on the component being resolved will be used. | ||
** If multiple values are selected, all values after the first will be added to the first's {{ | ** If multiple values are selected, all values after the first will be added to the first's {{MC/Nbt|list|extra}} list, separated by copies of the {{MC/Nbt|any|separator}} component. This means that all values after the first will inherit the first value's formatting tags, if any. | ||
|- | |- | ||
|} | |} | ||
<div class="treeview"> | <div class="treeview"> | ||
* {{ | * {{MC/Nbt|compound}} The text component. | ||
** {{ | ** {{MC/Nbt|string|type}}: Optional. Set to {{MC/Code|"nbt"}}. | ||
** {{ | ** {{MC/Nbt|string|source}}: Optional. Allowed values are {{MC/Code|"block"}}, {{MC/Code|"entity"}}, and {{MC/Code|"storage"}}, corresponding to the source of the NBT data. | ||
** {{ | ** {{MC/Nbt|string|nbt}}: The NBT path used for looking up NBT values from an entity, block entity, or storage. Requires one of {{MC/Nbt|string|block}}, {{MC/Nbt|string|entity}}, or {{MC/Nbt|string|storage}}. Having more than one is allowed, but only one is used.<ref group=note>If {{MC/Nbt|string|source}} is left unspecified, NBT sources are checked in the order {{MC/Nbt|string|entity}}, {{MC/Nbt|string|block}}, {{MC/Nbt|string|storage}}. If multiple are present, whichever one comes first in that list is used.</ref> | ||
** {{ | ** {{MC/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 {{MC/Nbt|string|nbt}} is not present. | ||
** {{ | ** {{MC/Nbt|compound|separator}}: Optional, defaults to <code>{text: ", "}</code>. A text component. Used as the separator between different tags, if the component selects multiple tags. | ||
** {{ | ** {{MC/Nbt|string|entity}}: A string specifying the target selector for the entity or entities from which the NBT value is obtained. Ignored if {{MC/Nbt|string|nbt}} is not present. | ||
** {{ | ** {{MC/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 {{MC/Nbt|string|nbt}} is not present. | ||
** {{ | ** {{MC/Nbt|string|storage}}: A string specifying the resource location of the command storage from which the NBT value is obtained. Ignored if {{MC/Nbt|string|nbt}} is not present. | ||
</div> | </div> | ||
| Line 176: | Line 176: | ||
===== Atlas Object Type ===== | ===== Atlas Object Type ===== | ||
When specifying {{ | When specifying {{MC/Nbt|string|object}} as {{MC/Code|"atlas"}}, it displays a single sprite from a texture atlas as a character. | ||
<div class="treeview"> | <div class="treeview"> | ||
* {{ | * {{MC/Nbt|compound}} The text component. | ||
** {{ | ** {{MC/Nbt|string|type}}: Optional. Defaults to {{MC/Code|"object"}} if object-specific keys are detected. | ||
** {{ | ** {{MC/Nbt|string|object}}: {{MC/Code|"atlas"}} (Optional as it defaults to {{MC/Code|"atlas"}} if not specified) | ||
** {{ | ** {{MC/Nbt|string|atlas}}: Optional. The name of texture atlas. Defaults to {{MC/Code|"minecraft:blocks"}}. | ||
** {{ | ** {{MC/Nbt|string|sprite}}: The sprite name (for example: {{MC/Code|"block/emerald_block"}}). | ||
</div> | </div> | ||
===== Player Object Type ===== | ===== Player Object Type ===== | ||
When specifying {{ | When specifying {{MC/Nbt|string|object}} as {{MC/Code|"player"}} it displays the 2D face sprite of a player profile. | ||
<div class="treeview"> | <div class="treeview"> | ||
* {{ | * {{MC/Nbt|compound}} The text component. | ||
** {{ | ** {{MC/Nbt|string|type}}: Optional. Defaults to {{MC/Code|"object"}} if object-specific keys are detected. | ||
** {{ | ** {{MC/Nbt|string|object}}: {{MC/Code|"player"}} | ||
** {{ | ** {{MC/Nbt|string}}{{MC/Nbt|compound|player}}: The textures and/or player profile used to render the face sprite. Provided with the same format as the {{DCL|profile}} data component. If specified as a string, it corresponds to {{MC/Nbt|string|name}}. | ||
*** {{Nbt inherit/profile}} | *** {{MC/Nbt inherit/profile}} | ||
** {{ | ** {{MC/Nbt|boolean|hat}}: Whether to display the hat layer. (Defaults to {{MC/Code|true}}) | ||
</div> | </div> | ||
| Line 201: | Line 201: | ||
Text component '''resolution''' is the process of converting "advanced" (server-side) text components into "simple" (client-side) text components so that they can be displayed to the user. | Text component '''resolution''' is the process of converting "advanced" (server-side) text components into "simple" (client-side) text components so that they can be displayed to the user. | ||
Certain text component types, such as {{ | Certain text component types, such as {{MC/Cd|text}}, {{MC/Cd|translate}}, {{MC/Cd|keybind}}, and {{MC/Cd|object}}, can be directly displayed by a player client, as the client does not need any additional information to interpret them. Those are known as "client-side" or "simple" text components. | ||
Other types, such as {{ | Other types, such as {{MC/Cd|score}}, {{MC/Cd|selector}}, and {{MC/Cd|nbt}}, require additional work from the ''server'' before they can be displayed by the client. Those are known as "server-side" or "advanced" text components. As the client does not have access to the information that these text components are meant to display, they need to be '''resolved''' by the server, which involves retrieving appropriate data from the world and replacing the server-side text components with client-side ones which the client knows how to render. | ||
If the client receives unresolved server-side text components, {{ | If the client receives unresolved server-side text components, {{MC/Cd|score}} and {{MC/Cd|nbt}} text components display as empty text, but {{MC/Cd|selector}} text components display the selector itself. | ||
Additionally, text component resolution fixes a single value in place based on the appropriate data at the moment of resolution. Therefore, these content types are not dynamic, and don't update to reflect later changes. For example, <code>{score:{name:"@p",objective:"points"}}</code> may resolve to {{ | Additionally, text component resolution fixes a single value in place based on the appropriate data at the moment of resolution. Therefore, these content types are not dynamic, and don't update to reflect later changes. For example, <code>{score:{name:"@p",objective:"points"}}</code> may resolve to {{MC/Cd|"100"}}, and will stay that way even if the player's "{{MC/Cd|points}}" score increases or decreases. | ||
Text component resolution can be done in many ways: | Text component resolution can be done in many ways: | ||
* Displaying text in chat or title slots with commands such as {{ | * Displaying text in chat or title slots with commands such as {{MC/Cmd|tellraw}} and {{MC/Cmd|title}}. | ||
* Writing a text component to any line on a [[Minecraft:sign]]. | * Writing a text component to any line on a [[Minecraft:sign]]. | ||
* Writing a text component to a text display's {{ | * Writing a text component to a text display's {{MC/Cd|text}} tag. | ||
* Using the '''set_name''' and '''set_lore''' item modifers, but only if their {{ | * Using the '''set_name''' and '''set_lore''' item modifers, but only if their {{MC/Nbt|string|entity}} field is set and that entity context exists. | ||
* A text component in a written book will be resolved once first opened by an ''operator'' or, once placed into a lectern. However, if the resulting text component is too large then it will fail to resolve. | * A text component in a written book will be resolved once first opened by an ''operator'' or, once placed into a lectern. However, if the resulting text component is too large then it will fail to resolve. | ||
* Setting a boss bar name using {{ | * Setting a boss bar name using {{MC/Cmd|bossbar set <id> name}} while the command is executing as an entity. | ||
* Setting a [[Minecraft:Commands/scoreboard|scoreboard objective]]'s display name using {{ | * Setting a [[Minecraft:Commands/scoreboard|scoreboard objective]]'s display name using {{MC/Cmd|scoreboard objectives modify <objective> displayname}} while the command is executing as an entity. | ||
* Setting a [[Minecraft:Commands/scoreboard|score holder]]'s display name using {{ | * Setting a [[Minecraft:Commands/scoreboard|score holder]]'s display name using {{MC/Cmd|scoreboard players display name}} while the command is executing as an entity. | ||
* Setting a score holder or scoreboard objective's [[Minecraft:Commands/scoreboard|number format]] to a {{ | * Setting a score holder or scoreboard objective's [[Minecraft:Commands/scoreboard|number format]] to a {{MC/Cd|fixed}} text component using {{MC/Cmd|scoreboard players display numberformat}} or {{MC/Cmd|scoreboard objectives modify <objective> numberformat fixed}} while the command is executing as an entity. | ||
There are several places where text components are '''not''' automatically resolved, such as: | There are several places where text components are '''not''' automatically resolved, such as: | ||
* Writing directly to data components such as {{DCL|custom_name}}, {{DCL|item_name}}, {{DCL|lore}}, and {{DCL|written_book_content}}. The previously mentioned item modifiers can be used to resolve text components when writing to these data components. | * Writing directly to data components such as {{DCL|custom_name}}, {{DCL|item_name}}, {{DCL|lore}}, and {{DCL|written_book_content}}. The previously mentioned item modifiers can be used to resolve text components when writing to these data components. | ||
* Writing directly to entities' {{ | * Writing directly to entities' {{MC/Cd|CustomName}} tag. | ||
* All text in dialogs.<ref>{{bug|MC-297871|||Invalid}}</ref> | * All text in dialogs.<ref>{{bug|MC-297871|||Invalid}}</ref> | ||
* Most JSON files in data packs, such as advancement names, chat types, painting variant authors/titles, etc. | * Most JSON files in data packs, such as advancement names, chat types, painting variant authors/titles, etc. | ||
| Line 235: | Line 235: | ||
* {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | * {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | ||
** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>open_url</code> | ** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>open_url</code> | ||
** {{ | ** {{MC/Nbt|string|url}}: The URL to open. | ||
</div> | </div> | ||
<section end="click_events" /> | <section end="click_events" /> | ||
| Line 244: | Line 244: | ||
* {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | * {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | ||
** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>open_file</code> | ** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>open_file</code> | ||
** {{ | ** {{MC/Nbt|string|path}}: The file to open. | ||
</div> | </div> | ||
<section begin="click_events" /> | <section begin="click_events" /> | ||
====run_command==== | ====run_command==== | ||
Runs the specified command. This runs as if the player typed the specified command in chat and pressed enter. However, this can only be used to run commands that do not send chat messages directly (like {{ | Runs the specified command. This runs as if the player typed the specified command in chat and pressed enter. However, this can only be used to run commands that do not send chat messages directly (like {{MC/Cmd|say}}, {{MC/Cmd|tell}}, and {{MC/Cmd|teammsg}}). Since they are being run from chat, the player must have the required permissions. | ||
{{#ifeq:{{PAGENAME}}|Dialog||On [[Minecraft:sign]]s, the command is run by the server at the sign's location, with the player who {{ | {{#ifeq:{{PAGENAME}}|Dialog||On [[Minecraft:sign]]s, the command is run by the server at the sign's location, with the player who {{MC/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, and are not restricted by chat length limits. | ||
}}<div class=treeview> | }}<div class=treeview> | ||
* {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | * {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | ||
** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>run_command</code> | ** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>run_command</code> | ||
** {{ | ** {{MC/Nbt|string|command}}: The command to run. Does not need to be prefixed with a <code>/</code> slash. | ||
</div> | </div> | ||
| Line 264: | Line 264: | ||
* {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | * {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | ||
** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>suggest_command</code> | ** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>suggest_command</code> | ||
** {{ | ** {{MC/Nbt|string|command}}: The command to fill in chat. Also works with normal texts. | ||
</div> | </div> | ||
| Line 273: | Line 273: | ||
* {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | * {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | ||
** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>change_page</code> | ** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>change_page</code> | ||
** {{ | ** {{MC/Nbt|int|page}}: The page to change to. | ||
</div> | </div> | ||
| Line 282: | Line 282: | ||
* {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | * {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | ||
** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>copy_to_clipboard</code> | ** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>copy_to_clipboard</code> | ||
** {{ | ** {{MC/Nbt|string|value}}: The text to copy. | ||
</div> | </div> | ||
| Line 291: | Line 291: | ||
* {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | * {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | ||
** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>show_dialog</code> | ** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>show_dialog</code> | ||
** {{ | ** {{MC/Nbt|string}}{{MC/Nbt|compound|dialog}}: {{MC/Json ref|dialog|inline=1}} to display. | ||
</div> | </div> | ||
| Line 300: | Line 300: | ||
* {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | * {{nbt|compound|{{#ifeq:{{PAGENAME}}|Dialog|action|click_event}}}} | ||
** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>custom</code> | ** {{nbt|string|{{#ifeq:{{PAGENAME}}|Dialog|type|action}}}}: <code>custom</code> | ||
** {{ | ** {{MC/Nbt|string|id}}: Any ID to identify the event. | ||
** {{ | ** {{MC/Nbt|string|payload}}: Optional payload of the event. | ||
</div><section end="click_events" /> | </div><section end="click_events" /> | ||
| Line 311: | Line 311: | ||
<div class=treeview> | <div class=treeview> | ||
* {{ | * {{MC/Nbt|compound|hover_event}} | ||
** {{ | ** {{MC/Nbt|string|action}}: <code>show_text</code> | ||
** {{ | ** {{MC/Nbt|string}}{{MC/Nbt|list}}{{MC/Nbt|compound|value}}: Another text component. Can be any valid text component type: string, list, or object. Note that {{MC/Nbt|compound|click_event}} and {{MC/Nbt|compound|hover_event}} do not function within the tooltip. | ||
</div> | </div> | ||
| Line 320: | Line 320: | ||
<div class=treeview> | <div class=treeview> | ||
* {{ | * {{MC/Nbt|compound|hover_event}} | ||
** {{ | ** {{MC/Nbt|string|action}}: <code>show_item</code> | ||
** {{ | ** {{MC/Nbt|string|id}}: The item's resource location. Defaults to {{MC/Code|minecraft:air}} if invalid. | ||
** {{ | ** {{MC/Nbt|int|count}}: Optional. Size of the item stack. This typically does not change the content tooltip. | ||
** {{ | ** {{MC/Nbt|compound|components}}: Optional. Additional information about the item. See Data component format. | ||
</div> | </div> | ||
====show_entity==== | ====show_entity==== | ||
Shows an entity's name, type, and UUID. Used by {{ | Shows an entity's name, type, and UUID. Used by {{MC/Nbt|string|selector}}. | ||
<div class=treeview> | <div class=treeview> | ||
* {{ | * {{MC/Nbt|compound|hover_event}} | ||
** {{ | ** {{MC/Nbt|string|action}}: <code>show_entity</code> | ||
** {{ | ** {{MC/Nbt|compound|name}}: Optional. Hidden if not present. A text that is displayed as the name of the entity. | ||
** {{ | ** {{MC/Nbt|string|id}}: A string containing the type of the entity, as a resource location. | ||
** {{ | ** {{MC/Nbt|string|}}{{MC/Nbt|int-array|}}{{MC/Nbt|list|uuid}}: 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. | ||
*** A list of four numbers representing the UUID in int-array or list format. e.g. {{ | *** A list of four numbers representing the UUID in int-array or list format. e.g. {{MC/Code|[I;1,1,1,1]}} or {{MC/Code|[1,1,1,1]}}. | ||
</div> | </div> | ||
| Line 344: | Line 344: | ||
<div class="treeview"> | <div class="treeview"> | ||
* {{ | * {{MC/Nbt|compound}} The root tag. | ||
**{{ | **{{MC/Nbt|list|rawtext}}: A list contains all text object. | ||
***{{ | ***{{MC/Nbt|compound}} To be valid, an object must contain one '''''content''''' tag: {{MC/Nbt|string|text}}, {{MC/Nbt|string|translate}}, {{MC/Nbt|compound|score}}, or {{MC/Nbt|string|selector}}. Having more than one is allowed, but only one is used.<ref group=note>Content tags are checked in the order {{MC/Nbt|string|translate}}, {{MC/Nbt|string|text}}, {{MC/Nbt|string|selector}}, {{MC/Nbt|compound|score}}. If multiple are present, whichever one comes first in that list is used.</ref> | ||
****'''''Content:'' Plain Text''' | ****'''''Content:'' Plain Text''' | ||
**** {{ | **** {{MC/Nbt|string|text}}: A string containing plain text to display directly. | ||
**** '''''Content:'' Translated Text''' | **** '''''Content:'' Translated Text''' | ||
**** {{ | **** {{MC/Nbt|string|translate}}: A translation identifier, to be 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 translation text. This identifier is the same as the identifiers found in lang files from assets or resource packs. | ||
**** {{ | **** {{MC/Nbt|list|with}}: Optional. A list of text component arguments to be inserted into slots in the translation text. Ignored if {{MC/Nbt|string|translate}} is not present. | ||
***** Translations can contain slots for text that is not known ahead of time, such as player names. These slots are defined in the translation text itself, not in the text component, and generally take the form <code>%%1</code> (displays the first argument; replace <code>1</code> with whichever index is desired). If no argument is provided for a slot, the slot is not displayed. | ***** Translations can contain slots for text that is not known ahead of time, such as player names. These slots are defined in the translation text itself, not in the text component, and generally take the form <code>%%1</code> (displays the first argument; replace <code>1</code> with whichever index is desired). If no argument is provided for a slot, the slot is not displayed. | ||
**** '''''Content:'' Scoreboard Value''' ''[[#Component resolution|(requires resolution)]]'' | **** '''''Content:'' Scoreboard Value''' ''[[#Component resolution|(requires resolution)]]'' | ||
**** {{ | **** {{MC/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. | ||
*****{{ | *****{{MC/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 <code>"*"</code>, it shows the reader's own score (for example, <code><nowiki>/tellraw @a { "rawtext" : [ { "score" : { "name" : "*" , "objective" : "obj"} } ] }</nowiki></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, <code>/titleraw</code>s, and written books.{{MC/Verify}} It doesn't work for things like signs that can have more than one "reader".{{MC/Verify}}</ref> | ||
***** {{ | ***** {{MC/Nbt|string|objective}}: The internal name of the objective to display the player's score in. | ||
**** '''''Content:'' Entity Names''' ''[[#Component resolution|(requires resolution)]]'' | **** '''''Content:'' Entity Names''' ''[[#Component resolution|(requires resolution)]]'' | ||
**** {{ | **** {{MC/Nbt|string|selector}}: A string containing a selector. Displayed as the name of the player or entity found by the selector. If more than one player or entity is found by the selector, their names are displayed in either the form "Name1 and Name2" or the form "Name1, Name2, Name3, and Name4". 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. | ||
</div> | </div> | ||
| Line 385: | Line 385: | ||
=== With === | === With === | ||
In the translate example above, it outputs "Opped %s". To have a name or other text show up instead of %s, "with" needs to be specified as well. Note that "with" only works with "translate" and also requires an array {{ | In the translate example above, it outputs "Opped %s". To have a name or other text show up instead of %s, "with" needs to be specified as well. Note that "with" only works with "translate" and also requires an array {{MC/Cd|[]}} instead of curly brackets {{cd|{} }}. | ||
{{cmd|/tellraw @a { "rawtext": [ { "translate" : "commands.op.success", "with": [ "Steve" ] } ] } }} | {{cmd|/tellraw @a { "rawtext": [ { "translate" : "commands.op.success", "with": [ "Steve" ] } ] } }} | ||
| Line 426: | Line 426: | ||
=== ''Java Edition'' === | === ''Java Edition'' === | ||
{{HistoryTable | {{HistoryTable | ||
|{{HistoryLine|java}} | |{{MC/HistoryLine|java}} | ||
|{{HistoryLine||1.7.2|dev=13w37a|Added {{ | |{{HistoryLine||1.7.2|dev=13w37a|Added {{MC/Cmd|tellraw}}, which supports raw JSON text.}} | ||
|{{HistoryLine||1.8|dev=14w02a|Added text component {{ | |{{HistoryLine||1.8|dev=14w02a|Added text component {{MC/Code|insertion}}.}} | ||
|{{HistoryLine|||dev=14w07a|Added text component {{ | |{{HistoryLine|||dev=14w07a|Added text component {{MC/Code|score}}.}} | ||
|{{HistoryLine|||dev=14w20a|Added {{ | |{{HistoryLine|||dev=14w20a|Added {{MC/Cmd|title}}, which supports raw JSON text. | ||
|Added text component {{ | |Added text component {{MC/Code|selector}}.}} | ||
|{{HistoryLine|||dev=14w25a|Now supported by [[Minecraft:sign]]s and written books.}} | |{{MC/HistoryLine|||dev=14w25a|Now supported by [[Minecraft:sign]]s and written books.}} | ||
|{{HistoryLine||1.12|dev=17w16a|Added text component {{ | |{{HistoryLine||1.12|dev=17w16a|Added text component {{MC/Code|keybind}}.}} | ||
|{{HistoryLine||1.13|dev=18w01a|Now supported by custom entity names.}} | |{{MC/HistoryLine||1.13|dev=18w01a|Now supported by custom entity names.}} | ||
|{{HistoryLine|||dev=18w05a|Added {{ | |{{HistoryLine|||dev=18w05a|Added {{MC/Cmd|bossbar}}. The argument {{MC/Code|<name>}} supports raw JSON text.}} | ||
|{{HistoryLine|||dev=pre8|Now supported by scoreboard objective names and team names.}} | |{{MC/HistoryLine|||dev=pre8|Now supported by scoreboard objective names and team names.}} | ||
|{{HistoryLine||1.14|dev=18w43a|Added text component {{ | |{{HistoryLine||1.14|dev=18w43a|Added text component {{MC/Code|nbt}} with {{MC/Code|block}} and {{MC/Code|entity}}. | ||
|Now supported by the item tag {{ | |Now supported by the item tag {{MC/Code|Lore}}.}} | ||
|{{HistoryLine|||dev=18w44a|Added text component {{ | |{{HistoryLine|||dev=18w44a|Added text component {{MC/Code|interpret}}.}} | ||
|{{HistoryLine||1.15|dev=19w39a|Added {{ | |{{HistoryLine||1.15|dev=19w39a|Added {{MC/Code|storage}} for the {{MC/Code|nbt}} text component.}} | ||
|{{HistoryLine|||dev=19w41a|Added the action {{ | |{{HistoryLine|||dev=19w41a|Added the action {{MC/Code|copy_to_clipboard}} for the text component {{MC/Code|clickEvent}}.}} | ||
|{{HistoryLine||1.16|dev=20w17a|Added text component {{ | |{{HistoryLine||1.16|dev=20w17a|Added text component {{MC/Code|font}}. | ||
|Added argument {{ | |Added argument {{MC/Code|contents}} for {{MC/Code|hoverEvent}}, replacing {{MC/Code|value}}, which is now deprecated but still supported. | ||
|The {{ | |The {{MC/Code|color}} component can now contain a hexadecimal RGB value prefixed by {{MC/Code|#}} (Example: <code>"color":"#ff0088"</code>).}} | ||
|{{HistoryLine||1.19.4|dev=23w03a|Added text component {{ | |{{HistoryLine||1.19.4|dev=23w03a|Added text component {{MC/Code|fallback}}.}} | ||
|{{HistoryLine||1.20.3|dev=23w40a|Added text component {{ | |{{HistoryLine||1.20.3|dev=23w40a|Added text component {{MC/Code|type}}. | ||
|{{ | |{{MC/Code|contents.id}} field in {{MC/Code|show_entity}} can represent the UUID as an array of ints. | ||
|Numbers and booleans are no longer auto-converted to strings, and so are invalid for the {{ | |Numbers and booleans are no longer auto-converted to strings, and so are invalid for the {{MC/Code|text}} component. | ||
|Several errors that used to be ignored are now hard errors.}} | |Several errors that used to be ignored are now hard errors.}} | ||
|{{HistoryLine|||dev=23w42a|Changes to chat component serialization: components of type <code>nbt</code> now have <code>source</code> field with allowed values: {{ | |{{HistoryLine|||dev=23w42a|Changes to chat component serialization: components of type <code>nbt</code> now have <code>source</code> field with allowed values: {{MC/Cd|d=and|entity|block|storage}}.}} | ||
|{{HistoryLine||1.21.2|dev=24w33a|Invalid <code>selector</code> patterns in chat components will now cause commands to fail to parse, instead of resolving to an empty string.}} | |{{MC/HistoryLine||1.21.2|dev=24w33a|Invalid <code>selector</code> patterns in chat components will now cause commands to fail to parse, instead of resolving to an empty string.}} | ||
|{{HistoryLine||1.21.4|dev=24w44a|Added optional <code>shadow_color</code> style field to Text Components, which overrides the shadow properties of text.}} | |{{MC/HistoryLine||1.21.4|dev=24w44a|Added optional <code>shadow_color</code> style field to Text Components, which overrides the shadow properties of text.}} | ||
|{{HistoryLine||1.21.5|dev=25w02a|Text components are now stored as NBT and are passed into commands using SNBT. | |{{MC/HistoryLine||1.21.5|dev=25w02a|Text components are now stored as NBT and are passed into commands using SNBT. | ||
|The <code>hoverEvent</code> field has been renamed to <code>hover_event</code>. | |The <code>hoverEvent</code> field has been renamed to <code>hover_event</code>. | ||
* The legacy <code>value</code> field (which was parsed from a rendered text component) is no longer supported. | * The legacy <code>value</code> field (which was parsed from a rendered text component) is no longer supported. | ||
| Line 481: | Line 481: | ||
** The <code>value</code> field has been renamed to <code>page</code>. | ** The <code>value</code> field has been renamed to <code>page</code>. | ||
** The page value now requires a positive integer instead of a string.}} | ** The page value now requires a positive integer instead of a string.}} | ||
|{{HistoryLine|||dev=25w03a|The {{ | |{{HistoryLine|||dev=25w03a|The {{MC/Cd|text}} field in {{MC/Cd|show_text}} action has been renamed to {{MC/Cd|value}}.}} | ||
|{{HistoryLine||1.21.6|dev=25w20a|Click Events: New click action {{ | |{{HistoryLine||1.21.6|dev=25w20a|Click Events: New click action {{MC/Cd|minecraft:custom}} has been added.|Dialog Click Event: New action {{MC/Cd|show_dialog}} has been added.}} | ||
|{{HistoryLine||1.21.9|dev=25w32a|Added new text component with type {{ | |{{HistoryLine||1.21.9|dev=25w32a|Added new text component with type {{MC/Cd|object}}.}} | ||
|{{HistoryLine|||dev=25w34a|Bold and italics styles are ignored when drawing sprites.}} | |{{MC/HistoryLine|||dev=25w34a|Bold and italics styles are ignored when drawing sprites.}} | ||
|{{HistoryLine|||dev=25w35a|Object text component has been updated to support displaying other non-character objects as a part of text.}} | |{{MC/HistoryLine|||dev=25w35a|Object text component has been updated to support displaying other non-character objects as a part of text.}} | ||
|{{HistoryLine||26.1|dev=snap8|{{ | |{{HistoryLine||26.1|dev=snap8|{{MC/Cd|minecraft:nbt}}: Tags resolved with the {{MC/Cd|minecraft:nbt}} text component when the {{MC/Cd|interpret}} field is set to {{MC/Cd|false}} are now pretty-printed instead of being flattened into a single {{MC/Cd|text}} component. Contents of the {{MC/Cd|nbt}} and {{MC/Cd|block}} fields are no longer silently rejected when parsing fails. The field {{MC/Cd|entity}} no longer accepts trailing data after a selector. A new option called {{MC/Cd|plain}} has been added to remove styling from pretty-printed text.|{{MC/Cd|minecraft:selector}}: The field {{MC/Cd|selector}} no longer accepts trailing data after a selector.}} | ||
|{{HistoryLine|||dev=pre1|{{ | |{{HistoryLine|||dev=pre1|{{MC/Cd|minecraft:object}}: Added a new optional field named {{MC/Cd|fallback}}.}} | ||
|{{HistoryLine|||dev=pre2|Components in server status messages (MotD) nested more than 16 times will now be discarded and replaced with an ellipsis.}} | |{{MC/HistoryLine|||dev=pre2|Components in server status messages (MotD) nested more than 16 times will now be discarded and replaced with an ellipsis.}} | ||
}} | }} | ||
=== ''Bedrock Edition'' === | === ''Bedrock Edition'' === | ||
{{HistoryTable | {{HistoryTable | ||
|{{HistoryLine|bedrock}} | |{{MC/HistoryLine|bedrock}} | ||
|{{HistoryLine||1.9.0|dev=beta 1.9.0.0|Added {{ | |{{HistoryLine||1.9.0|dev=beta 1.9.0.0|Added {{MC/Cmd|tellraw}}, the raw JSON text used to support this command.}} | ||
|{{HistoryLine||1.16.100|dev=beta 1.16.100.55|Added text component {{ | |{{HistoryLine||1.16.100|dev=beta 1.16.100.55|Added text component {{MC/Code|score}} and {{MC/Code|selector}}.}} | ||
}} | }} | ||
| Line 506: | Line 506: | ||
== References == | == References == | ||
{{Reflist}} | {{MC/Reflist}} | ||
== External links == | == External links == | ||
Latest revision as of 21:02, 9 April 2026
|
For the {{{Description}}} of the same name, see [[{{{Destination}}}]]. |
The text component format, historically also known as raw JSON text, is used by Minecraft to send and display rich-text to players. It can also be sent by players themselves using commands (such as
- REDIRECT Template:Command
Template:Redr and
- REDIRECT Template:Command
Template:Redr) and data packs.
Java Edition
Text components are written in SNBT, for example Template:Cd. They are used for rich-text formatting in written books, Minecraft:signs, custom names and the
- REDIRECT Template:Command
- REDIRECT Template:Command
- REDIRECT Template:Command
- REDIRECT Template:Command
Template:Redr and
- REDIRECT Template:Command
Template:Redr commands.
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/sprite string, Template:Nbt/sprite list or a Template:Nbt/sprite object. Strings and lists are both shorthand for longer object structures, as described below.
- Template:Nbt/sprite A string containing plain text to display directly. This is the same as an object that only has a Template:Nbt/sprite text tag. For example,
"A"and{text: "A"}are equivalent. - Template:Nbt/sprite A list of components. Same as having all components after the first one appended to the first's Template:Nbt/sprite extra list. 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/sprite A text component object. All non-content tags are optional.
- Content
- Template:Nbt/sprite type: Optional. Specifies the content type. One of
"text","translatable","score","selector","keybind", or"nbt". - If Template:Nbt/sprite type 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/sprite text]], [[#Translated Text|Template:Nbt/sprite translate]], [[#Scoreboard Value|Template:Nbt/sprite score]], [[#Entity Names|Template:Nbt/sprite selector]], [[#Keybind|Template:Nbt/sprite keybind]], and finally [[#NBT Values|Template:Nbt/sprite nbt]]. If multiple are present, whichever one comes first in that list is used.
- Values specific to each content type are described below.
- Template:Nbt/sprite type: Optional. Specifies the content type. One of
- Children
- Template:Nbt/sprite extra: 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/sprite extra: A list of additional components to be displayed after this one.
- Formatting
- Template:Nbt/sprite 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.
"#<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/sprite font: Optional. The resource location of the font for this component in the resource pack within
assets/<namespace>/font. Defaults to"minecraft:default". - Template:Nbt/sprite bold: Optional. Whether to render the content in bold.
- Template:Nbt/sprite 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
false. - Template:Nbt/sprite underlined: Optional. Whether to underline the content.
- Template:Nbt/sprite strikethrough: Optional. Whether to strikethrough the content.
- Template:Nbt/sprite obfuscated: Optional. Whether to render the content obfuscated.
- Template:Nbt/sprite shadow_color: The color and opacity of the shadow. If omitted, the shadow is 25% the brightness of the text color and 100% the opacity{{
- Template:Nbt/sprite 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.
- Content
#vardefine: verifyedition |
}}<verify for {{#var:verifyedition}}></verify for {{#var:verifyedition}}>{{
#vardefine: verifyedition |
}}. Color codes are the ARGB hex code of the color converted to a decimal number, or can be calculated from the opacity, red, green and blue components using this formula:
Alpha<<24 + Red<<16 + Green<<8 + Blue
- Template:Nbt/sprite shadow_color: Another format. A list containing 4 floats corresponding to red, green, blue, and opacity values as a fraction (ranged 0 to 1, inclusive) that is automatically converted to the int format.
- Interactivity
- Template:Nbt/sprite 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.
- Template:Nbt/sprite click_event: Optional. Allows for events to occur when the player clicks on text. See Template:Slink.
- Template:Nbt/sprite hover_event: Optional. Allows for a tooltip to be displayed when the player hovers their mouse over text. See Template:Slink.
Due to the Template:Nbt/sprite extra 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/sprite The text component.
- Template:Nbt/sprite type: Optional. Set to
"text". - Template:Nbt/sprite text: A string containing plain text to display directly.
- Template:Nbt/sprite type: Optional. Set to
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, the translate key, the fallback key 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/sprite The text component.
- Template:Nbt/sprite type: Optional. Set to
"translatable". - Template:Nbt/sprite translate: 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/sprite fallback: Optional. If no corresponding translation can be found, this is used as the translated text. Ignored if Template:Nbt/sprite translate is not present.
- Template:Nbt/sprite with: Optional. A list of text components to be inserted into slots in the translation text. Ignored if Template:Nbt/sprite translate is not present.
- A text component. If no component is provided for a slot, the slot is displayed as no text.
- Template:Nbt/sprite type: Optional. Set to
Scoreboard Value
Displays a score from the scoreboard.
| Requires component resolution. |
|---|
| This component is resolved into a Template:Nbt/sprite text component containing the scoreboard value. |
- Template:Nbt/sprite The text component.
- Template:Nbt/sprite type: Optional. Set to
"score". - Template:Nbt/sprite 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.
- Template:Nbt/sprite 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
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/sprite objective: The internal name of the objective to display the player's score in.
- Template:Nbt/sprite 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
- Template:Nbt/sprite type: Optional. Set to
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/sprite The text component.
- Template:Nbt/sprite type: Optional. Set to
"selector". - Template:Nbt/sprite selector: A string containing a selector.
- Template:Nbt/sprite separator: Optional, defaults to
{color: "gray", text: ", "}. A text component. Used as the separator between different names, if the component selects multiple entities.
- Template:Nbt/sprite type: Optional. Set to
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/sprite The text component.
- Template:Nbt/sprite type: Optional. Set to
"keybind". - Template:Nbt/sprite keybind: 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. As a fallback it displays the translation if it exists.
- Template:Nbt/sprite type: Optional. Set to
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/sprite interpret is set to true, the game will instead attempt to parse and display that text as its own text component. That only works on compounds and lists which contain tags with the proper key names. If Template:Nbt/sprite interpret is true and parsing fails, the component is displayed as no text, or if it directs to a string, shows the string itself. If more than one NBT value is found, either by selecting multiple entities or by using a multi-value path, they are displayed in order, with the Template:Nbt/sprite separator value between them.
| Requires component resolution. |
|---|
|
- Template:Nbt/sprite The text component.
- Template:Nbt/sprite type: Optional. Set to
"nbt". - Template:Nbt/sprite source: Optional. Allowed values are
"block","entity", and"storage", corresponding to the source of the NBT data. - Template:Nbt/sprite nbt: The NBT path used for looking up NBT values from an entity, block entity, or storage. Requires one of Template:Nbt/sprite block, Template:Nbt/sprite entity, or Template:Nbt/sprite storage. Having more than one is allowed, but only one is used.<ref group=note>If Template:Nbt/sprite source is left unspecified, NBT sources are checked in the order Template:Nbt/sprite entity, Template:Nbt/sprite block, Template:Nbt/sprite storage. If multiple are present, whichever one comes first in that list is used.</ref>
- Template:Nbt/sprite interpret: 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/sprite nbt is not present.
- Template:Nbt/sprite separator: Optional, defaults to
{text: ", "}. A text component. Used as the separator between different tags, if the component selects multiple tags. - Template:Nbt/sprite entity: A string specifying the target selector for the entity or entities from which the NBT value is obtained. Ignored if Template:Nbt/sprite nbt is not present.
- Template:Nbt/sprite block: 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/sprite nbt is not present.
- Template:Nbt/sprite storage: A string specifying the resource location of the command storage from which the NBT value is obtained. Ignored if Template:Nbt/sprite nbt is not present.
- Template:Nbt/sprite type: Optional. Set to
Object
Displays objects as single sprites in component messages. Sprites are rendered as 8x8 pixels squares. This will ignore bold and italic styles!
Atlas Object Type
When specifying Template:Nbt/sprite object as "atlas", it displays a single sprite from a texture atlas as a character.
- Template:Nbt/sprite The text component.
- Template:Nbt/sprite type: Optional. Defaults to
"object"if object-specific keys are detected. - Template:Nbt/sprite object:
"atlas"(Optional as it defaults to"atlas"if not specified) - Template:Nbt/sprite atlas: Optional. The name of texture atlas. Defaults to
"minecraft:blocks". - Template:Nbt/sprite sprite: The sprite name (for example:
"block/emerald_block").
- Template:Nbt/sprite type: Optional. Defaults to
Player Object Type
When specifying Template:Nbt/sprite object as "player" it displays the 2D face sprite of a player profile.
- Template:Nbt/sprite The text component.
- Template:Nbt/sprite type: Optional. Defaults to
"object"if object-specific keys are detected. - Template:Nbt/sprite object:
"player" - Template:Nbt/spriteTemplate:Nbt/sprite player: The textures and/or player profile used to render the face sprite. Provided with the same format as the Template:DCL data component. If specified as a string, it corresponds to Template:Nbt/sprite name.
- Template:Nbt/sprite hat: Whether to display the hat layer. (Defaults to
true)
- Template:Nbt/sprite type: Optional. Defaults to
Component resolution
Text component resolution is the process of converting "advanced" (server-side) text components into "simple" (client-side) text components so that they can be displayed to the user.
Certain text component types, such as
- REDIRECT Template:Code
- REDIRECT Template:Code
- REDIRECT Template:Code
Template:Redr, and
- REDIRECT Template:Code
Template:Redr, can be directly displayed by a player client, as the client does not need any additional information to interpret them. Those are known as "client-side" or "simple" text components.
Other types, such as
- REDIRECT Template:Code
- REDIRECT Template:Code
Template:Redr, and
- REDIRECT Template:Code
Template:Redr, require additional work from the server before they can be displayed by the client. Those are known as "server-side" or "advanced" text components. As the client does not have access to the information that these text components are meant to display, they need to be resolved by the server, which involves retrieving appropriate data from the world and replacing the server-side text components with client-side ones which the client knows how to render.
If the client receives unresolved server-side text components,
- REDIRECT Template:Code
Template:Redr and
- REDIRECT Template:Code
Template:Redr text components display as empty text, but
- REDIRECT Template:Code
Template:Redr text components display the selector itself.
Additionally, text component resolution fixes a single value in place based on the appropriate data at the moment of resolution. Therefore, these content types are not dynamic, and don't update to reflect later changes. For example, {score:{name:"@p",objective:"points"}} may resolve to
- REDIRECT Template:Code
Template:Redr, and will stay that way even if the player's "
- REDIRECT Template:Code
Template:Redr" score increases or decreases.
Text component resolution can be done in many ways:
- Displaying text in chat or title slots with commands such as
- REDIRECT Template:Command
Template:Redr and
- REDIRECT Template:Command
- Writing a text component to any line on a Minecraft:sign.
- Writing a text component to a text display's
- REDIRECT Template:Code
Template:Redr tag.
- Using the set_name and set_lore item modifers, but only if their Template:Nbt/sprite entity field is set and that entity context exists.
- A text component in a written book will be resolved once first opened by an operator or, once placed into a lectern. However, if the resulting text component is too large then it will fail to resolve.
- Setting a boss bar name using
- REDIRECT Template:Command
Template:Redr while the command is executing as an entity.
- Setting a scoreboard objective's display name using
- REDIRECT Template:Command
Template:Redr while the command is executing as an entity.
- Setting a score holder's display name using
- REDIRECT Template:Command
Template:Redr while the command is executing as an entity.
- Setting a score holder or scoreboard objective's number format to a
- REDIRECT Template:Code
Template:Redr text component using
- REDIRECT Template:Command
- REDIRECT Template:Command
Template:Redr while the command is executing as an entity.
There are several places where text components are not automatically resolved, such as:
- Writing directly to data components such as Template:DCL, Template:DCL, Template:DCL, and Template:DCL. The previously mentioned item modifiers can be used to resolve text components when writing to these data components.
- Writing directly to entities'
- REDIRECT Template:Code
Template:Redr tag.
- All text in dialogs.<ref>Template:Bug</ref>
- Most JSON files in data packs, such as advancement names, chat types, painting variant authors/titles, etc.
Click events
Click events control what happens when the player clicks on the text. Can be one of the following: <section begin="click_events" />
open_url
Opens the specified URL in the user's default web browser.
- Template:Nbt
- Template:Nbt:
open_url - Template:Nbt/sprite url: The URL to open.
- Template:Nbt:
<section end="click_events" />
open_file
Opens the specified file on the user's computer. This is used in messages automatically generated by the game (e.g., on taking a screenshot) and cannot be sent by servers for security reasons.
- Template:Nbt
- Template:Nbt:
open_file - Template:Nbt/sprite path: The file to open.
- Template:Nbt:
<section begin="click_events" />
run_command
Runs the specified command. This runs as if the player typed the specified command in chat and pressed enter. However, this can only be used to run commands that do not send chat messages directly (like
- REDIRECT Template:Command
- REDIRECT Template:Command
Template:Redr, and
- REDIRECT Template:Command
Template:Redr). Since they are being run from chat, the player must have the required permissions.
On Minecraft:signs, the command is run by the server at the sign's location, with the player who {{#vardefine: control | right click on mouse or left trigger on gamepad }}used 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, and are not restricted by chat length limits.
- Template:Nbt
- Template:Nbt:
run_command - Template:Nbt/sprite command: The command to run. Does not need to be prefixed with a
/slash.
- Template:Nbt:
suggest_command
Opens chat and fills in the specified text or command. If a chat message was already being composed, it is overwritten.This does not work in books.<ref>Template:Bug</ref>
- Template:Nbt
- Template:Nbt:
suggest_command - Template:Nbt/sprite command: The command to fill in chat. Also works with normal texts.
- Template:Nbt:
change_page
Can only be used in written books. Changes to the specified page if that page exists.
- Template:Nbt
- Template:Nbt:
change_page - Template:Nbt/sprite page: The page to change to.
- Template:Nbt:
copy_to_clipboard
Copies the specified text to the clipboard.
- Template:Nbt
- Template:Nbt:
copy_to_clipboard - Template:Nbt/sprite value: The text to copy.
- Template:Nbt:
show_dialog
Opens the specified dialog.
- Template:Nbt
- Template:Nbt:
show_dialog - Template:Nbt/spriteTemplate:Nbt/sprite dialog: One dialog (an Template:Nbt ID, or a new Template:Nbt dialog definition) to display.
- Template:Nbt:
custom
Sends a custom event to the server; has no effect on vanilla servers.
- Template:Nbt
- Template:Nbt:
custom - Template:Nbt/sprite id: Any ID to identify the event.
- Template:Nbt/sprite payload: Optional payload of the event.
- Template:Nbt:
<section end="click_events" />
Hover events
Hover events control what happens when the player hovers over the text. Can be one of the following:
show_text
Shows a text component.
- Template:Nbt/sprite hover_event
- Template:Nbt/sprite action:
show_text - Template:Nbt/spriteTemplate:Nbt/spriteTemplate:Nbt/sprite value: Another text component. Can be any valid text component type: string, list, or object. Note that Template:Nbt/sprite click_event and Template:Nbt/sprite hover_event do not function within the tooltip.
- Template:Nbt/sprite action:
show_item
Shows the tooltip of an item as if it was being hovering over it in an inventory.
- Template:Nbt/sprite hover_event
- Template:Nbt/sprite action:
show_item - Template:Nbt/sprite id: The item's resource location. Defaults to
minecraft:airif invalid. - Template:Nbt/sprite count: Optional. Size of the item stack. This typically does not change the content tooltip.
- Template:Nbt/sprite components: Optional. Additional information about the item. See Data component format.
- Template:Nbt/sprite action:
show_entity
Shows an entity's name, type, and UUID. Used by Template:Nbt/sprite selector.
- Template:Nbt/sprite hover_event
- Template:Nbt/sprite action:
show_entity - Template:Nbt/sprite name: Optional. Hidden if not present. A text that is displayed as the name of the entity.
- Template:Nbt/sprite id: A string containing the type of the entity, as a resource location.
- Template:Nbt/spriteTemplate:Nbt/spriteTemplate:Nbt/sprite uuid: 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 or list format. e.g.
[I;1,1,1,1]or[1,1,1,1].
- Template:Nbt/sprite action:
Bedrock Edition
Unlike Java Edition, text components in Bedrock Edition are written in Minecraft:JSON.
- Template:Nbt/sprite The root tag.
- Template:Nbt/sprite rawtext: A list contains all text object.
- Template:Nbt/sprite To be valid, an object must contain one content tag: Template:Nbt/sprite text, Template:Nbt/sprite translate, Template:Nbt/sprite score, or Template:Nbt/sprite selector. Having more than one is allowed, but only one is used.<ref group=note>Content tags are checked in the order Template:Nbt/sprite translate, Template:Nbt/sprite text, Template:Nbt/sprite selector, Template:Nbt/sprite score. If multiple are present, whichever one comes first in that list is used.</ref>
- Content: Plain Text
- Template:Nbt/sprite text: A string containing plain text to display directly.
- Content: Translated Text
- Template:Nbt/sprite translate: A translation identifier, to be 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 translation text. This identifier is the same as the identifiers found in lang files from assets or resource packs.
- Template:Nbt/sprite with: Optional. A list of text component arguments to be inserted into slots in the translation text. Ignored if Template:Nbt/sprite translate is not present.
- Translations can contain slots for text that is not known ahead of time, such as player names. These slots are defined in the translation text itself, not in the text component, and generally take the form
%%1(displays the first argument; replace1with whichever index is desired). If no argument is provided for a slot, the slot is not displayed.
- Translations can contain slots for text that is not known ahead of time, such as player names. These slots are defined in the translation text itself, not in the text component, and generally take the form
- Content: Scoreboard Value (requires resolution)
- Template:Nbt/sprite 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.
- Template:Nbt/sprite 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
"*", it shows the reader's own score (for example,/tellraw @a { "rawtext" : [ { "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,/titleraws, and written books.{{
- Template:Nbt/sprite 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
- Template:Nbt/sprite To be valid, an object must contain one content tag: Template:Nbt/sprite text, Template:Nbt/sprite translate, Template:Nbt/sprite score, or Template:Nbt/sprite selector. Having more than one is allowed, but only one is used.<ref group=note>Content tags are checked in the order Template:Nbt/sprite translate, Template:Nbt/sprite text, Template:Nbt/sprite selector, Template:Nbt/sprite score. If multiple are present, whichever one comes first in that list is used.</ref>
- Template:Nbt/sprite rawtext: A list contains all text object.
#vardefine: verifyedition |
}}<verify for {{#var:verifyedition}}></verify for {{#var:verifyedition}}>{{
#vardefine: verifyedition |
}} It doesn't work for things like signs that can have more than one "reader".{{
#vardefine: verifyedition |
}}<verify for {{#var:verifyedition}}></verify for {{#var:verifyedition}}>{{
#vardefine: verifyedition |
}}</ref>
- Template:Nbt/sprite objective: The internal name of the objective to display the player's score in.
- Content: Entity Names (requires resolution)
- Template:Nbt/sprite selector: A string containing a selector. Displayed as the name of the player or entity found by the selector. If more than one player or entity is found by the selector, their names are displayed in either the form "Name1 and Name2" or the form "Name1, Name2, Name3, and Name4". 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.
- Basic raw text example
- Template:Cmd
This sends a message to all players saying "Hello World" in English only. See the Translate action to see how to send localized texts.
Appending
Raw text takes in an array of text objects. Each object in the list is added to the previous object. For example, Template:Cmd outputs the same "Hello World" as the first example. Appending text can be useful to combine 2 different localized texts, or apply different colors to each word etc.
Breaking lines
You can go down a line by using "\n". For example,
Translate
The translate object allows creators to provide localized text to users. If translate is specified along with text, translate overrides the text object. The string to provide to translate is the name of the string in the language files. For example, in Vanilla Minecraft "commands.op.success" is the string that displays when /op is used on a player successfully.
This outputs "Opped %s" to all players. Note that because of text being ignored with translate specified, the following example outputs the same text:
With
In the translate example above, it outputs "Opped %s". To have a name or other text show up instead of %s, "with" needs to be specified as well. Note that "with" only works with "translate" and also requires an array
- REDIRECT Template:Code
Template:Redr instead of curly brackets Template:Cd.
If you want to use a translated text inside the "with" component, instead of an array it needs to be another rawtext component (which consists of an array of text components). The following example outputs "Opped Apple".
%%s
"translate" and "%s" can be used without needing a corresponding string in the localization files. For example:
This outputs "Hello Steve" to all players.
Multiple %s
%%s can be used multiple times. They are filled in, in the order specified
Outputs: "Hello Steve and Alex"
You can again use a rawtext component to replace the plain string array, like so
Outputs: "Hello Steve and Apple"
Ordering with %%#
The order to fill in %%s can be changed by instead specifying it with %%#, replacing # with an actual number. For example, to swap the position of Steve and Alex in the above example, instead run the following:
Outputs: "Hello Alex and Steve"
Formatting
String formatting is still possible, but not using the text component format used in Java Edition. Instead, formatting codes are used to change text color and style.
History
Java Edition
Bedrock Edition
See also
- Minecraft:Commands
- Formatting code
Notes
References
<references group="">
</references>
External links
Template:Navbox Java Edition technical
de:Textkomponenten ja:Raw JSONテキストフォーマット pt:Formato de componente de texto zh:文本组件