Difference between revisions of "Chat"

From wiki.vg
Jump to navigation Jump to search
m (Note change_page; also open_file cannot be used. (This page still needs some major improvements))
 
(77 intermediate revisions by 17 users not shown)
Line 1: Line 1:
Minecraft supports two-way chat communication via the [[Protocol#Chat Message (clientbound)|Chat Message]] packet.
+
{{Hatnote|This page previously contained documentation on text formatting features, which can now be found at [[Text formatting]].}}
  
== Current system (JSON Chat) ==
+
This article details various aspects of Minecraft's chat system. The packets themselves are documented in [[Protocol]].
  
Comments (<code>//</code>) are not valid json and shouldn't be sent, they are only here to explain the format
+
== Client chat mode ==
  
<syntaxhighlight lang="javascript">
+
The client may use the Chat Mode field of the [[Protocol#Client Information (configuration)|Client Information]] packet to indicate that it only wants to receive some types of chat messages.
{
 
    // Plain text
 
    "text": "Hello world",
 
    //or
 
    // Translatable string
 
    "translate": "multiplayer.player.joined",
 
    "with": [
 
        //This can be replaced another json object allowing the parts
 
        //to be styled/translated seperately
 
        "thinkofdeath"
 
    ],
 
    //or
 
    // Displays the player's value for a scoreboard objective (1.8+)
 
    "score": {
 
        "name": "<playername>", // * for current player
 
        "objective": "<objectivename>"
 
    },
 
    //or
 
    // A standard minecraft selector, eg: @p, @a, @e, @r (1.8+)
 
    "selector": "",
 
    //
 
    //Items in the extra section will be appended to the message.
 
    //They can strings or json objects. If included the array must
 
    //not be empty
 
    "extra": [
 
        "Testing",
 
        {"translate":"demo.day.2"}
 
    ],
 
    //Controls whether the text is bold or not. Default false
 
    "bold":true,
 
    //Controls whether the text is italic or not. Default false
 
    "italic":false,
 
    //Controls whether the text is underlined or not. Default false
 
    "underlined": false,
 
    //Controls whether the text is striked out or not. Default false
 
    "strikethrough": false,
 
    //Controls whether the text is randomised constantly or not. Default false
 
    "obfuscated": false,
 
    //Controls the color of the text
 
    //Supported colors:
 
    // * black
 
    // * dark_blue
 
    // * dark_green
 
    // * dark_aqua
 
    // * dark_red
 
    // * dark_purple
 
    // * gold
 
    // * gray
 
    // * dark_gray
 
    // * blue
 
    // * green
 
    // * aqua
 
    // * red
 
    // * light_purple
 
    // * yellow
 
    // * white
 
    // Additional format names can be used, but the other properties should be preferred:
 
    // * obfuscated
 
    // * bold
 
    // * strikethrough
 
    // * underline
 
    // * italic
 
    // * reset
 
    "color":"red",
 
    //Executes the action once the text is clicked
 
    "clickEvent":{
 
        //The action to execute
 
        //Supported actions:
 
        // * open_url
 
        // * open_file
 
        // * run_command
 
        // * suggest_command
 
        // * change_page
 
        "action":"run_command",
 
        //The value to run the action with
 
        //open_url: Url to open
 
        //open_file: File to open (Cannot be used; only allowed when generated clientside in the screenshot message)
 
        //run_command: Command to execute
 
        //suggest_command: Text to place in the player's text box
 
        //change_page: Page number to change in a written book.  No effect in normal chat.
 
        "value": "/time set day"
 
    },
 
    //Displays the action upon hovering over the text
 
    "hoverEvent": {
 
        //The action to execute
 
        //Supported actions
 
        // * show_text
 
        // * show_achievement
 
        // * show_item
 
        "action":"show_text",
 
        //The value to the action with
 
        //show_text: Text to display can be a JSON object
 
        //show_achievement: Name of the achievemnt to display e.g: "achievement.openInventory"
 
        //show_item: JSON version of the item, must be quoted. e.g: "{id:35,Damage:5,Count:2,tag:{display:{Name:Testing}}}"
 
        "value": "Hello"
 
    },
 
    // Inserts the text into the chat on shift click (1.8+)
 
    "insertion": "Hello world" 
 
}
 
</syntaxhighlight>
 
  
== Old system ==
+
It is the server's responsibility to not send packets if the client has the given type disabled.  However, it is the client's responsibility to not send incorrect chat packets.
  
=== Control Sequences ===
+
Here's a matrix comparing what packets the server should send to clients based on their chat settings:
  
The client treats certain two-character sequences specially. The first character must be:
+
{| class="wikitable"
 +
!rowspan="2" | Clientbound packet
 +
!colspan="3" | Client setting
 +
!rowspan="2" | Usage
 +
|-
 +
! Full
 +
! Commands only
 +
! Hidden
 +
|-
 +
| [[Protocol#Player Chat Message|Player Chat Message]]
 +
| {{yes|✔}}
 +
| {{no|✘}}
 +
| {{no|✘}}
 +
| Player-initiated chat messages, including the commands <code>/say</code>, <code>/me</code>, <code>/msg</code>, <code>/tell</code>, <code>/w</code> and <code>/teammsg</code>.
 +
|-
 +
| [[Protocol#Disguised Chat Message|Disguised Chat Message]]
 +
| {{yes|✔}}
 +
| {{no|✘}}
 +
| {{no|✘}}
 +
| Messages sent by non-players using the commands <code>/say</code>, <code>/me</code>, <code>/msg</code>, <code>/tell</code>, <code>/w</code> and <code>/teammsg</code>.
 +
|-
 +
| [[Protocol#System Chat Message|System Chat Message]]
 +
| {{yes|✔}}
 +
| {{yes|✔}}
 +
| {{no|✘}}
 +
| Feedback from running a command, such as "Your game mode has been updated to creative."
 +
|-
 +
| [[Protocol#System Chat Message|System Chat Message]] (overlay)
 +
| {{yes|✔}}
 +
| {{yes|✔}}
 +
| {{yes|✔}}
 +
| Game state information that is displayed above the hot bar, such as "You may not rest now, the bed is too far away".
 +
|}
  
*§ (U+00A7) for minecraft
+
Here's a matrix comparing what the client may send based on its chat setting:
*& for minecraft classic
 
  
The following character indicates a certain colour or formatting to apply to the proceeding text.
+
{| class="wikitable"
 +
!rowspan="2" | Serverbound packet
 +
!colspan="3" | Client setting
 +
|-
 +
! Full
 +
! Commands only
 +
! Hidden
 +
|-
 +
| [[Protocol#Chat Message|Chat Message]]
 +
| {{yes|✔}}
 +
| {{maybe|✘<ref group="note">This behavior varies.  The Notchian server <em>previously</em> rejected chat messages, but now allows them to go through (sending them to all players, but they're invisible on the sender's side).  CraftBukkit and derivatives continue to reject this.  See [https://bugs.mojang.com/browse/MC-116824 MC-116824] for more information.</ref>}}
 +
| {{no|✘}}
 +
|-
 +
| [[Protocol#Chat Command|Chat Command]]
 +
| {{yes|✔}}
 +
| {{yes|✔}}
 +
| {{no|✘}}
 +
|}
  
The Notchian client expects that an escape code in a chat message will be followed by at least one character, and will otherwise crash with a StringIndexOutOfBoundsException. The workaround for servers is to never end a message with a color control character.
+
If the client attempts to send a chat message and the server rejects it, the Notchian server will send that client a [[Protocol#System Chat Message|System Chat Message]] (non-overlay) with a red <code>chat.disabled.options</code> translation component (which becomes "Chat disabled in client options.").
  
==== Colors ====
+
== Social Interactions (blocking) ==
  
These correspond very roughly to the colors available in ANSI terminals.
+
1.16 added a ''social interactions screen'' that lets players block chat from other players. Blocking takes place clientside by detecting whether a message is from a blocked player.
  
e.g.: <code>This is white, but §4this is dark red</code>
+
[[Protocol#Player Chat Message|Player Chat Message]] packets are blocked based on the included sender UUID.
  
[[File:Colors.png|thumb|Hex digit to color mapping]]
+
[[Protocol#Disguised Chat Message|Disguised Chat Message]] packets are never blocked.
  
{| class="wikitable" style="text-align:center;" border="1" cellpadding="5"
+
[[Protocol#System Chat Message|System Chat Message]] packets (regardless of the Overlay field!) are blocked based on the first occurrence of <code><''playername''></code> anywhere in the message, including split across multiple text components, where ''playername'' may be any text, including the empty string or whitespace. If ''playername'' is the name of a blocked player (matched case-sensitively), the message is blocked. This only occurs if Hide Matched Names is enabled in Chat Settings (the default).
|-
 
! colspan="1"  width="8px"| Sample
 
! colspan="1" | Code
 
! colspan="1" | Common Name
 
! colspan="3" | Foreground Color
 
! colspan="3" | Background Color
 
! colspan="1" | Hexadecimal
 
|-
 
| || ||
 
|width="30px"|R
 
|width="30px"|G
 
|width="30px"|B
 
|width="30px"|R
 
|width="30px"|G
 
|width="30px"|B
 
||
 
|-
 
| bgcolor="black" |
 
| 0 || Black || 0 || 0 || 0 || 0 || 0 || 0 || #000000
 
|-
 
| bgcolor=#0000aa |
 
| 1 || Dark blue || 0 || 0 || 170 || 0 || 0 || 42 || #0000aa
 
|-
 
| bgcolor=#00aa00 |
 
| 2 || Dark green || 0 || 170 || 0 || 0 || 42 || 0 || #00aa00
 
|-
 
| bgcolor=#00aaaa |
 
| 3 || Dark cyan || 0  || 170 || 170 || 0 || 42 || 42 || #00aaaa
 
|-
 
| bgcolor=#aa0000 |
 
| 4 || Dark red || 170 || 0 || 0 || 42 || 0 || 0 || #aa0000
 
|-
 
| bgcolor=#aa00aa |
 
| 5 || Purple || 170 || 0 || 170 || 42 || 0 || 42 || #aa00aa
 
|-
 
| bgcolor=#ffaa00 |
 
| 6 || Gold || 255 || 170 || 0 || 42 || 42 || 0 || #ffaa00
 
|-
 
| bgcolor=#aaaaaa |
 
| 7 || Gray || 170 || 170 || 170 || 42 || 42 || 42 || #aaaaaa
 
|-
 
| bgcolor=#555555 |
 
| 8 || Dark gray || 85 || 85 || 85 || 21 || 21 || 21 || #555555
 
|-
 
| bgcolor=#5555ff |
 
| 9 || Blue || 85 || 85 || 255 || 21 || 21 || 63 || #5555ff
 
|-
 
| bgcolor=#55ff55 |
 
| a || Bright green || 85 || 255 || 85 || 21 || 63 || 21 || #55ff55
 
|-
 
| bgcolor=#55FFFF |
 
| b || Cyan || 85 || 255 || 255 || 21 || 63 || 63 || #55ffff
 
|-
 
| bgcolor=#FF5555 |
 
| c || Red || 255 || 85 || 85 || 63 || 21 || 21 || #ff5555
 
|-
 
| bgcolor=#FF55FF |
 
| d || Pink || 255 || 85 || 255 || 63 || 21 || 63 || #ff55ff
 
|-
 
| bgcolor=#FFFF55 |
 
| e || Yellow || 255 || 255 || 85 || 63 || 63 || 21 || #ffff55
 
|-
 
| bgcolor=#FFFFFF |
 
| f || White || 255 || 255 || 255 || 63 || 63 || 63 || #ffffff
 
|}
 
  
==== Styles ====
+
== Notes ==
  
Like the color codes above, style escape codes are created by combining § (U+00A7) with one of the following characters. Style codes can be combined (except for "r") to enable multiple effects at once. Using any color codes will reset the current style back to plain (unknown if this is a bug or intended behavior). The "r" plain style code will also reset the current chat color back to white (may also be a bug). The "k" random style code is used for the "§kFUNKY LOL" message in /title/splashes.txt inside minecraft.jar.
+
<references group="note" />
 
 
{| class="wikitable" style="text-align:center;" border="1" cellpadding="5"
 
|-
 
! colspan="1" | Sample
 
! colspan="1" | Code
 
! colspan="1" | Style
 
|-
 
| [[File:random_chat.gif]] || k || Random
 
|-
 
| [[File:bold_chat.png]] || l || Bold
 
|-
 
| [[File:strikethrough_chat.png]] || m || Strikethrough
 
|-
 
| [[File:underlined_chat.png]] || n || Underlined
 
|-
 
| [[File:italic_chat.png]] || o || Italic
 
|-
 
| [[File:plain_chat.png]] || r || Plain White
 
|}
 
 
 
== Font ==
 
 
 
Minecraft has two fonts types: Default (<code>default.png</code>) and Unicode(<code>glyph_XX.png</code>). Default will fallback on unicode characters if they are not provided (default only has the first 256 glyphs). The minecraft client calculates the widths of the default font type on startup whilst the sizes of the unicode type are provided in <code>glyph_sizes.bin</code>. Each byte in <code>glyph_sizes.bin</code> contains the start and end position of each character, the top nibble (0xF0) is the start position and the bottom nibble (0x0F) is the end position (relative to the characters position in the font sheet).
 
 
 
Example: https://gist.github.com/TkTech/dff9bbe54c9a074612e1
 
  
 
[[Category:Protocol Details]]
 
[[Category:Protocol Details]]
 
[[Category:Minecraft Modern]]
 
[[Category:Minecraft Modern]]

Latest revision as of 23:22, 13 March 2024

This page previously contained documentation on text formatting features, which can now be found at Text formatting.

This article details various aspects of Minecraft's chat system. The packets themselves are documented in Protocol.

Client chat mode

The client may use the Chat Mode field of the Client Information packet to indicate that it only wants to receive some types of chat messages.

It is the server's responsibility to not send packets if the client has the given type disabled. However, it is the client's responsibility to not send incorrect chat packets.

Here's a matrix comparing what packets the server should send to clients based on their chat settings:

Clientbound packet Client setting Usage
Full Commands only Hidden
Player Chat Message Player-initiated chat messages, including the commands /say, /me, /msg, /tell, /w and /teammsg.
Disguised Chat Message Messages sent by non-players using the commands /say, /me, /msg, /tell, /w and /teammsg.
System Chat Message Feedback from running a command, such as "Your game mode has been updated to creative."
System Chat Message (overlay) Game state information that is displayed above the hot bar, such as "You may not rest now, the bed is too far away".

Here's a matrix comparing what the client may send based on its chat setting:

Serverbound packet Client setting
Full Commands only Hidden
Chat Message [note 1]
Chat Command

If the client attempts to send a chat message and the server rejects it, the Notchian server will send that client a System Chat Message (non-overlay) with a red chat.disabled.options translation component (which becomes "Chat disabled in client options.").

Social Interactions (blocking)

1.16 added a social interactions screen that lets players block chat from other players. Blocking takes place clientside by detecting whether a message is from a blocked player.

Player Chat Message packets are blocked based on the included sender UUID.

Disguised Chat Message packets are never blocked.

System Chat Message packets (regardless of the Overlay field!) are blocked based on the first occurrence of <playername> anywhere in the message, including split across multiple text components, where playername may be any text, including the empty string or whitespace. If playername is the name of a blocked player (matched case-sensitively), the message is blocked. This only occurs if Hide Matched Names is enabled in Chat Settings (the default).

Notes

  1. This behavior varies. The Notchian server previously rejected chat messages, but now allows them to go through (sending them to all players, but they're invisible on the sender's side). CraftBukkit and derivatives continue to reject this. See MC-116824 for more information.