Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:Text component format

From SAS Gaming Wiki


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 Template:Cmd and Template:Cmd) and Minecraft:data packs.

Java Edition

Template:For

Text components are written in SNBT, for example Template:Cd. They are used for rich-text formatting in Minecraft:written books, Minecraft:signs, custom names and the Template:Cmd, Template:Cmd, Template:Cmd, Template:Cmd and Template:Cmd 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 string, Template:Nbt list or a Template:Nbt object. Strings and lists 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 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 A text component object. All non-content tags are optional.
    • Content
    • 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.
    • 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.
      • 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:Nbt: The color and opacity of the shadow. If omitted, the shadow is 25% the brightness of the text color and 100% the opacityTemplate: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:
        Alpha<<24 + Red<<16 + Green<<8 + Blue
      • Template:Nbt: 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: 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. See Template:Slink.
      • Template:Nbt: Optional. Allows for a tooltip to be displayed when the player hovers their mouse over text. See Template:Slink.

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.

Translated Text

Displays a translated piece of text from the currently selected Minecraft:language. This uses the client's selected language, so if players with their games set to different languages are logged into the same server, each will see the component in their own language.

Translations are defined in language files in Minecraft:resource packs, including the built-in resource pack.

Translations can contain slots for text that is not known ahead of time, such as player names. When displaying the translated text, slots will be filled from a provided list of text components. The slots are defined in the language file, 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 The text component.
    • Template:Nbt: Optional. Set to Template:Code.
    • Template:Nbt: A translation identifier, corresponding to the identifiers found in loaded language files. Displayed as the corresponding text in the player's selected language. If no corresponding translation can be found, the identifier itself is used as the translated text.
    • Template:Nbt: Optional. If no corresponding translation can be found, this is used as the translated text. Ignored if Template:Nbt is not present.
    • Template:Nbt: Optional. A list of text components to be inserted into slots in the translation text. Ignored if Template:Nbt is not present.
      • A text component. If no component is provided for a slot, the slot is displayed as no text.

Scoreboard Value

Displays a score from the Minecraft:scoreboard.

  • Template:Nbt The text component.
    • Template:Nbt: Optional. Set to Template:Code.
    • Template:Nbt: Displays a score holder's current score in an objective. Displays nothing if the given score holder or the given objective do not exist, or if the score holder is not tracked in the objective.
      • Template:Nbt: The name of the score holder whose score should be displayed. This can be a Minecraft:selector like @p or an explicit name. If the text is a selector, the selector must be guaranteed to never select more than one entity, possibly by adding limit=1. If the text is "*", it shows the reader's own score (for example, /tellraw @a {score: {name: "*", objective: "obj"}} shows every online player their own score in the "obj" objective).<ref group="note">Showing the reader's own score only works in situations where a message has one singular reader. That is chat messages, /titles, and written books. It does not work for Minecraft:bossbar display names or blocks like signs.</ref>
      • Template:Nbt: The internal name of the objective to display the player's score in.

Entity Names

Displays the name of one or more entities found by a Minecraft:selector.

If exactly one entity is found, the entity's name is displayed by itself. If more are found, their names are displayed in the form "Name1, Name2, Name3", with gray commas. If none are found, the component is displayed as no text.

Hovering over a name shows a tooltip with the name, type, and Minecraft:UUID of the target. Clicking a player's name suggests a command to whisper to that player. Shift-clicking a player's name inserts that name into chat. Shift-clicking a non-player entity's name inserts its UUID into chat.

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. As a fallback it displays the translation if it exists.

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 only works on compounds and lists which contain tags with the proper key names. If Template:Nbt 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 value between them.

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 as Template:Code, it displays a single sprite from a Minecraft:texture atlas as a character.

Player Object Type

When specifying Template:Nbt as Template:Code it displays the 2D face sprite of a player profile.

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 Template:Cd, Template:Cd, Template:Cd, and Template:Cd, 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 Template:Cd, Template:Cd, and Template:Cd, 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, Template:Cd and Template:Cd text components display as empty text, but Template:Cd 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 Template:Cd, and will stay that way even if the player's "Template:Cd" score increases or decreases.

Text component resolution can be done in many ways:

There are several places where text components are not automatically resolved, such as:

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.

<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.

<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 Template:Cmd, Template:Cmd, and Template:Cmd). 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 Template:Control the sign as the command executor (that is, the entity selected by @s). Since they are run by the server, sign commands have the same permission level as a Minecraft:command block instead of using the player's permission level, and are not restricted by chat length limits.

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>

change_page

Can only be used in written books. Changes to the specified page if that page exists.

copy_to_clipboard

Copies the specified text to the clipboard.

show_dialog

Opens the specified Minecraft:dialog.

custom

Sends a custom event to the server; has no effect on vanilla servers.

<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.

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.

Bedrock Edition

Unlike Java Edition, text components in Bedrock Edition are written in Minecraft:JSON.

  • Template:Nbt The root tag.
    • Template:Nbt: A list contains all text object.
      • Template:Nbt To be valid, an object must contain one content tag: Template:Nbt, Template:Nbt, Template:Nbt, or Template:Nbt. Having more than one is allowed, but only one is used.<ref group=note>Content tags are checked in the order Template:Nbt, Template:Nbt, Template:Nbt, Template:Nbt. If multiple are present, whichever one comes first in that list is used.</ref>
        • Content: Plain Text
        • Template:Nbt: A string containing plain text to display directly.
        • Content: Translated Text
        • Template:Nbt: 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: Optional. A list of text component arguments to be inserted into slots in the translation text. Ignored if Template:Nbt 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; replace 1 with whichever index is desired). If no argument is provided for a slot, the slot is not displayed.
        • Content: Scoreboard Value (requires resolution)
        • Template:Nbt: Displays a score holder's current score in an objective. Displays nothing if the given score holder or the given objective do not exist, or if the score holder is not tracked in the objective.
          • Template:Nbt: The name of the score holder whose score should be displayed. This can be a Minecraft:selector like @p or an explicit name. If the text is "*", 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 Minecraft:written books.Template:Verify It doesn't work for things like signs that can have more than one "reader".Template:Verify</ref>
          • Template:Nbt: The internal name of the objective to display the player's score in.
        • Content: Entity Names (requires resolution)
        • Template:Nbt: A string containing a Minecraft: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,

Template:Cmd

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.

Template:Cmd

This outputs "Opped %s" to all players. Note that because of text being ignored with translate specified, the following example outputs the same text:

Template:Cmd

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 Template:Cd instead of curly brackets Template:Cd.

Template:Cmd

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".

Template:Cmd

%%s

"translate" and "%s" can be used without needing a corresponding string in the localization files. For example:

Template:Cmd

This outputs "Hello Steve" to all players.

Multiple %s

%%s can be used multiple times. They are filled in, in the order specified

Template:Cmd

Outputs: "Hello Steve and Alex"

You can again use a rawtext component to replace the plain string array, like so

Template:Cmd

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:

Template:Cmd

Outputs: "Hello Alex and Steve"

Formatting

String formatting is still possible, but not using the text component format used in Java Edition. Instead, Minecraft:formatting codes are used to change text color and style.

History

Java Edition

Template:HistoryTable

Bedrock Edition

Template:HistoryTable

See also

Notes

Template:Notelist

References

Template:Reflist

External links

Navigation

Template:Navbox Java Edition technical

Minecraft:de:Textkomponenten Minecraft:ja:Raw JSONテキストフォーマット Minecraft:pt:Formato de componente de texto Minecraft:zh:文本组件