Chat

From wiki.vg
Revision as of 16:50, 14 April 2016 by Pokechu22 (talk | contribs) (Fix chat message link)
Jump to navigation Jump to search

Minecraft supports two-way chat communication via the Chat Message packet.

Current system (JSON Chat)

Comments (//) are not valid json and shouldn't be sent, they are only here to explain the format

 {
     // 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
     // * 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
         "action":"run_command",
         //The value to run the action with
         //open_url: Url to open
         //open_file: File to open
         //run_command: Command to execute
         //suggest_command: Text to place in the player's text box
         "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"   
 }

Old system

Control Sequences

The client treats certain two-character sequences specially. The first character must be:

  • § (U+00A7) for minecraft
  • & for minecraft classic

The following character indicates a certain colour or formatting to apply to the proceeding text.

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.

Colors

These correspond very roughly to the colors available in ANSI terminals.

e.g.: This is white, but §4this is dark red

Hex digit to color mapping
Sample Code Common Name Foreground Color Background Color Hexadecimal
R G B R G B
0 Black 0 0 0 0 0 0 #000000
1 Dark blue 0 0 170 0 0 42 #0000aa
2 Dark green 0 170 0 0 42 0 #00aa00
3 Dark cyan 0 170 170 0 42 42 #00aaaa
4 Dark red 170 0 0 42 0 0 #aa0000
5 Purple 170 0 170 42 0 42 #aa00aa
6 Gold 255 170 0 42 42 0 #ffaa00
7 Gray 170 170 170 42 42 42 #aaaaaa
8 Dark gray 85 85 85 21 21 21 #555555
9 Blue 85 85 255 21 21 63 #5555ff
a Bright green 85 255 85 21 63 21 #55ff55
b Cyan 85 255 255 21 63 63 #55ffff
c Red 255 85 85 63 21 21 #ff5555
d Pink 255 85 255 63 21 63 #ff55ff
e Yellow 255 255 85 63 63 21 #ffff55
f White 255 255 255 63 63 63 #ffffff

Styles

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.

Sample Code Style
Random chat.gif k Random
Bold chat.png l Bold
Strikethrough chat.png m Strikethrough
Underlined chat.png n Underlined
Italic chat.png o Italic
Plain chat.png r Plain White

Font

Minecraft has two fonts types: Default (default.png) and Unicode(glyph_XX.png). 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 glyph_sizes.bin. Each byte in glyph_sizes.bin 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