Difference between revisions of "Command Data"

From wiki.vg
Jump to navigation Jump to search
(Created page with "From Minecraft 1.13, the '''Command Graph''' data structure defines commands which can be used in chat or in command blocks, and how they're parsed. == Graph Structure == Th...")
 
(Add internal links + tweaks)
Line 5: Line 5:
 
The graph consists of nodes of type <code>root</code>, <code>literal</code> and <code>argument</code>. A node may point to a number child nodes, or redirect to another node, or neither. The root node is nameless, and its children are literal nodes for familiar commands ("msg", "me", etc).  
 
The graph consists of nodes of type <code>root</code>, <code>literal</code> and <code>argument</code>. A node may point to a number child nodes, or redirect to another node, or neither. The root node is nameless, and its children are literal nodes for familiar commands ("msg", "me", etc).  
  
Nodes are marked as executable if node stack to this point constitutes a valid command. E.g. this is false for <code>/ban</code> but true for <code>/ban Dinnerbone</code> and <code>/ban Dinnerbone created this crazy format</code>.
+
Nodes are marked as executable if the node stack to this point constitutes a valid command. E.g. this is false for <code>/ban</code> but true for <code>/ban Dinnerbone</code> and <code>/ban Dinnerbone created this crazy format</code>.
  
 
When including redirects, this structure is a directed graph that may include cycles (e.g. consider <code>/execute run execute run execute ...</code>). When excluding redirects, the structure no longer contains cycles but may still not be a tree, as a node may have multiple parents.
 
When including redirects, this structure is a directed graph that may include cycles (e.g. consider <code>/execute run execute run execute ...</code>). When excluding redirects, the structure no longer contains cycles but may still not be a tree, as a node may have multiple parents.
Line 16: Line 16:
 
  ! Notes
 
  ! Notes
 
  |-
 
  |-
  | Flags
+
  | [[ #Flags | Flags ]]
 
  | Byte
 
  | Byte
 
  | See below.
 
  | See below.
Line 36: Line 36:
 
  | Only for <code>command</code> and <code>literal</code> nodes.
 
  | Only for <code>command</code> and <code>literal</code> nodes.
 
  |-
 
  |-
  | Parser
+
  | [[ #Parsers | Parser ]]
 
  | Optional String
 
  | Optional String
 
  | Only for <code>command</code> nodes.
 
  | Only for <code>command</code> nodes.
 
  |-
 
  |-
  | Properties
+
  | [[ #Properties | Properties ]]
 
  | Optional Varies
 
  | Optional Varies
 
  | Only for <code>command</code> nodes. Varies by parser.
 
  | Only for <code>command</code> nodes. Varies by parser.
 
  |-
 
  |-
  | Suggestions type
+
  | [[ #Suggestions_Types | Suggestions type ]]
 
  | Optional String
 
  | Optional String
 
  | Only if <code>flags & 0x10</code>.
 
  | Only if <code>flags & 0x10</code>.
 
  |}
 
  |}
  
=== Node Flags ===
+
=== Flags ===
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 61: Line 61:
 
|-
 
|-
 
| <code>0x04</code>
 
| <code>0x04</code>
| Executable
+
| Is executable
 
| Set if the node stack to this point constitutes a valid command.
 
| Set if the node stack to this point constitutes a valid command.
 
|-
 
|-
Line 78: Line 78:
 
{| class="wikitable"
 
{| class="wikitable"
 
  ! Identifier
 
  ! Identifier
 +
! Properties
 
  ! Description
 
  ! Description
 
  |-
 
  |-
 
  | <code>brigadier:bool</code>
 
  | <code>brigadier:bool</code>
 +
|
 
  | Boolean value (<code>true</code> or <code>false</code>, case-sensitive)
 
  | Boolean value (<code>true</code> or <code>false</code>, case-sensitive)
 
  |-
 
  |-
 
  | <code>brigadier:double</code>
 
  | <code>brigadier:double</code>
 +
| [[ #brigadier:double | See below ]]
 
  | Double
 
  | Double
 
  |-
 
  |-
 
  | <code>brigadier:float</code>
 
  | <code>brigadier:float</code>
 +
| [[ #brigadier:float | See below ]]
 
  | Float
 
  | Float
 
  |-
 
  |-
 
  | <code>brigadier:integer</code>
 
  | <code>brigadier:integer</code>
 +
| [[ #brigadier:integer | See below ]]
 
  | Integer
 
  | Integer
 
  |-
 
  |-
 
  | <code>brigadier:string</code>
 
  | <code>brigadier:string</code>
 +
| [[ #brigadier:string | See below ]]
 
  | A string
 
  | A string
 
  |-
 
  |-
 
  | <code>minecraft:entity</code>
 
  | <code>minecraft:entity</code>
 +
| [[ #minecraft:entity | See below ]]
 
  | A selector, player name, or UUID.
 
  | A selector, player name, or UUID.
 
  |-
 
  |-
 
  | <code>minecraft:game_profile</code>
 
  | <code>minecraft:game_profile</code>
 +
|
 
  | A player, online or not.  Can also use a selector, which may match one or more players (but not entities).
 
  | A player, online or not.  Can also use a selector, which may match one or more players (but not entities).
 
  |-
 
  |-
 
  | <code>minecraft:block_pos</code>
 
  | <code>minecraft:block_pos</code>
 +
|
 
  | A location, represented as 3 numbers (which must be integers).  May use relative locations with <code>~</code>.
 
  | A location, represented as 3 numbers (which must be integers).  May use relative locations with <code>~</code>.
 
  |-
 
  |-
 
  | <code>minecraft:vec3</code>
 
  | <code>minecraft:vec3</code>
 +
|
 
  | A location, represented as 3 numbers (which may have a decimal point, but will be moved to the center of a block if none is specified).  May use relative locations with <code>~</code>.
 
  | A location, represented as 3 numbers (which may have a decimal point, but will be moved to the center of a block if none is specified).  May use relative locations with <code>~</code>.
 
  |-
 
  |-
 
  | <code>minecraft:vec2</code>
 
  | <code>minecraft:vec2</code>
 +
|
 
  | A location, represented as 2 numbers (which may have a decimal point, but will be moved to the center of a block if none is specified).  May use relative locations with <code>~</code>.
 
  | A location, represented as 2 numbers (which may have a decimal point, but will be moved to the center of a block if none is specified).  May use relative locations with <code>~</code>.
 
  |-
 
  |-
 
  | <code>minecraft:block_state</code>
 
  | <code>minecraft:block_state</code>
 +
|
 
  | A block state, optionally including NBT and state information.
 
  | A block state, optionally including NBT and state information.
 
  |-
 
  |-
 
  | <code>minecraft:block_predicate</code>
 
  | <code>minecraft:block_predicate</code>
 +
|
 
  | A block, or a block tag.
 
  | A block, or a block tag.
 
  |-
 
  |-
 
  | <code>minecraft:item_stack</code>
 
  | <code>minecraft:item_stack</code>
 +
|
 
  | An item, optionally including NBT.
 
  | An item, optionally including NBT.
 
  |-
 
  |-
 
  | <code>minecraft:item_predicate</code>
 
  | <code>minecraft:item_predicate</code>
 +
|
 
  | An item, or an item tag.
 
  | An item, or an item tag.
 
  |-
 
  |-
 
  | <code>minecraft:color</code>
 
  | <code>minecraft:color</code>
 +
|
 
  | A chat color.  One of the names from [[Chat#Colors]], or <code>reset</code>.  Case-insensitive.
 
  | A chat color.  One of the names from [[Chat#Colors]], or <code>reset</code>.  Case-insensitive.
 
  |-
 
  |-
 
  | <code>minecraft:component</code>
 
  | <code>minecraft:component</code>
 +
|
 
  | A JSON [[Chat]] component.
 
  | A JSON [[Chat]] component.
 
  |-
 
  |-
 
  | <code>minecraft:message</code>
 
  | <code>minecraft:message</code>
 +
|
 
  | A regular message, potentially including selectors.
 
  | A regular message, potentially including selectors.
 
  |-
 
  |-
 
  | <code>minecraft:nbt</code>
 
  | <code>minecraft:nbt</code>
 +
|
 
  | An NBT value, parsed using JSON-NBT rules.
 
  | An NBT value, parsed using JSON-NBT rules.
 
  |-
 
  |-
 
  | <code>minecraft:nbt_path</code>
 
  | <code>minecraft:nbt_path</code>
 +
|
 
  | A path within an NBT value, allowing for array and member accesses.
 
  | A path within an NBT value, allowing for array and member accesses.
 
  |-
 
  |-
 
  | <code>minecraft:objective</code>
 
  | <code>minecraft:objective</code>
 +
|
 
  | A scoreboard objective.
 
  | A scoreboard objective.
 
  |-
 
  |-
 
  | <code>minecraft:objective_criteria</code>
 
  | <code>minecraft:objective_criteria</code>
 +
|
 
  | A single score criterion.
 
  | A single score criterion.
 
  |-
 
  |-
 
  | <code>minecraft:operation</code>
 
  | <code>minecraft:operation</code>
 +
|
 
  | A scoreboard operator.
 
  | A scoreboard operator.
 
  |-
 
  |-
 
  | <code>minecraft:particle</code>
 
  | <code>minecraft:particle</code>
 +
|
 
  | A particle effect (an identifier with extra information following it for specific particles, mirroring the [[#Particle|Particle]] packet)
 
  | A particle effect (an identifier with extra information following it for specific particles, mirroring the [[#Particle|Particle]] packet)
 
  |-
 
  |-
 
  | <code>minecraft:rotation</code>
 
  | <code>minecraft:rotation</code>
 +
|
 
  | An angle, represented as 2 numbers (which may have a decimal point, but will be moved to the center of a block if none is specified).  May use relative locations with <code>~</code>.
 
  | An angle, represented as 2 numbers (which may have a decimal point, but will be moved to the center of a block if none is specified).  May use relative locations with <code>~</code>.
 +
|
 
  |-
 
  |-
 
  | <code>minecraft:scoreboard_slot</code>
 
  | <code>minecraft:scoreboard_slot</code>
 +
|
 
  | A scoreboard display position slot.  <code>list</code>, <code>sidebar</code>, <code>belowName</code>, and <code>sidebar.team.${color}</code> for all chat colors (<code>reset</code> is not included)
 
  | A scoreboard display position slot.  <code>list</code>, <code>sidebar</code>, <code>belowName</code>, and <code>sidebar.team.${color}</code> for all chat colors (<code>reset</code> is not included)
 
  |-
 
  |-
 
  | <code>minecraft:score_holder</code>
 
  | <code>minecraft:score_holder</code>
 +
| [[ #minecraft:score_holder | See below ]]
 
  | Something that can join a team.  Allows selectors and <code>*</code>.
 
  | Something that can join a team.  Allows selectors and <code>*</code>.
 
  |-
 
  |-
 
  | <code>minecraft:swizzle</code>
 
  | <code>minecraft:swizzle</code>
 +
|
 
  | A collection of up to 3 axes.
 
  | A collection of up to 3 axes.
 
  |-
 
  |-
 
  | <code>minecraft:team</code>
 
  | <code>minecraft:team</code>
 +
|
 
  | The name of a team.  Parsed as an unquoted string.
 
  | The name of a team.  Parsed as an unquoted string.
 
  |-
 
  |-
 
  | <code>minecraft:item_slot</code>
 
  | <code>minecraft:item_slot</code>
 +
|
 
  | A name for an inventory slot.
 
  | A name for an inventory slot.
 
  |-
 
  |-
 
  | <code>minecraft:resource_location</code>
 
  | <code>minecraft:resource_location</code>
 +
|
 
  | An Identifier.
 
  | An Identifier.
 
  |-
 
  |-
 
  | <code>minecraft:mob_effect</code>
 
  | <code>minecraft:mob_effect</code>
 +
|
 
  | A potion effect.
 
  | A potion effect.
 
  |-
 
  |-
 
  | <code>minecraft:function</code>
 
  | <code>minecraft:function</code>
 +
|
 
  | A function.
 
  | A function.
 
  |-
 
  |-
 
  | <code>minecraft:entity_anchor</code>
 
  | <code>minecraft:entity_anchor</code>
 +
|
 
  | The entity anchor related to the facing argument in the teleport command, is feet or eyes.
 
  | The entity anchor related to the facing argument in the teleport command, is feet or eyes.
 
  |-
 
  |-
 
  | <code>minecraft:range</code>
 
  | <code>minecraft:range</code>
 +
| [[ #minecraft:range | See below ]]
 
  | A range of values with a min and a max.
 
  | A range of values with a min and a max.
 
  |-
 
  |-
 
  | <code>minecraft:item_enchantment</code>
 
  | <code>minecraft:item_enchantment</code>
 +
|
 
  | Represents a item enchantment.
 
  | Represents a item enchantment.
 
  |}
 
  |}

Revision as of 00:52, 4 June 2018

From Minecraft 1.13, the Command Graph data structure defines commands which can be used in chat or in command blocks, and how they're parsed.

Graph Structure

The graph consists of nodes of type root, literal and argument. A node may point to a number child nodes, or redirect to another node, or neither. The root node is nameless, and its children are literal nodes for familiar commands ("msg", "me", etc).

Nodes are marked as executable if the node stack to this point constitutes a valid command. E.g. this is false for /ban but true for /ban Dinnerbone and /ban Dinnerbone created this crazy format.

When including redirects, this structure is a directed graph that may include cycles (e.g. consider /execute run execute run execute ...). When excluding redirects, the structure no longer contains cycles but may still not be a tree, as a node may have multiple parents.

Node Format

Field Name Field Type Notes
Flags Byte See below.
Children count VarInt Number of elements in the following array.
Children Array of VarInt Array of indices of child nodes.
Redirect node Optional VarInt Only if flags & 0x08. Index of redirect node.
Name Optional String (32767) Only for command and literal nodes.
Parser Optional String Only for command nodes.
Properties Optional Varies Only for command nodes. Varies by parser.
Suggestions type Optional String Only if flags & 0x10.

Flags

Bit mask Field Name Notes
0x03 Node type 0: root, 1: literal, 2: argument
0x04 Is executable Set if the node stack to this point constitutes a valid command.
0x08 Has redirect Set if the node redirects to another node.
0x10 Has suggestions type Only present for argument nodes.

Parsers

Identifier Properties Description
brigadier:bool Boolean value (true or false, case-sensitive)
brigadier:double See below Double
brigadier:float See below Float
brigadier:integer See below Integer
brigadier:string See below A string
minecraft:entity See below A selector, player name, or UUID.
minecraft:game_profile A player, online or not. Can also use a selector, which may match one or more players (but not entities).
minecraft:block_pos A location, represented as 3 numbers (which must be integers). May use relative locations with ~.
minecraft:vec3 A location, represented as 3 numbers (which may have a decimal point, but will be moved to the center of a block if none is specified). May use relative locations with ~.
minecraft:vec2 A location, represented as 2 numbers (which may have a decimal point, but will be moved to the center of a block if none is specified). May use relative locations with ~.
minecraft:block_state A block state, optionally including NBT and state information.
minecraft:block_predicate A block, or a block tag.
minecraft:item_stack An item, optionally including NBT.
minecraft:item_predicate An item, or an item tag.
minecraft:color A chat color. One of the names from Chat#Colors, or reset. Case-insensitive.
minecraft:component A JSON Chat component.
minecraft:message A regular message, potentially including selectors.
minecraft:nbt An NBT value, parsed using JSON-NBT rules.
minecraft:nbt_path A path within an NBT value, allowing for array and member accesses.
minecraft:objective A scoreboard objective.
minecraft:objective_criteria A single score criterion.
minecraft:operation A scoreboard operator.
minecraft:particle A particle effect (an identifier with extra information following it for specific particles, mirroring the Particle packet)
minecraft:rotation An angle, represented as 2 numbers (which may have a decimal point, but will be moved to the center of a block if none is specified). May use relative locations with ~.
minecraft:scoreboard_slot A scoreboard display position slot. list, sidebar, belowName, and sidebar.team.${color} for all chat colors (reset is not included)
minecraft:score_holder See below Something that can join a team. Allows selectors and *.
minecraft:swizzle A collection of up to 3 axes.
minecraft:team The name of a team. Parsed as an unquoted string.
minecraft:item_slot A name for an inventory slot.
minecraft:resource_location An Identifier.
minecraft:mob_effect A potion effect.
minecraft:function A function.
minecraft:entity_anchor The entity anchor related to the facing argument in the teleport command, is feet or eyes.
minecraft:range See below A range of values with a min and a max.
minecraft:item_enchantment Represents a item enchantment.

Properties

brigadier:double

Specifies min and max values.

Name Type Description
Flags Byte
Min Optional double Only if flags & 0x01. If not specified, defaults to -Double.MAX_VALUE (≈ -1.7976931348623157E307)
Max Optional double Only if flags & 0x02. If not specified, defaults to Double.MAX_VALUE (≈ 1.7976931348623157E307)
brigadier:float

Specifies min and max values.

Name Type Description
Flags Byte
Min Optional float Only if flags & 0x01. If not specified, defaults to -Float.MAX_VALUE (≈ 3.4028235E38)
Max Optional float Only if flags & 0x02. If not specified, defaults to Float.MAX_VALUE (≈ 3.4028235E38)
brigadier:integer

Specifies min and max values.

Name Type Description
Flags Byte
Min Optional integer Only if flags & 0x01. If not specified, defaults to Integer.MIN_VALUE (-2147483648)
Max Optional integer Only if flags & 0x02. If not specified, defaults to Integer.MAX_VALUE (2147483647)
brigadier:string

A VarInt enum.

Value Name Description
0 SINGLE_WORD Reads a single word
1 QUOTABLE_PHRASE If it starts with a ", keeps reading until another " (allowing escaping with \). Otherwise behaves the same as SINGLE_WORD
2 GREEDY_PHRASE Reads the rest of the content after the cursor. Quotes will not be removed.
minecraft:entity

Has a single flags byte.

Bit mask Meaning
0x01 If set, only allows a single entity/player
0x02 If set, only allows players
minecraft:score_holder

Has a single flags byte:

Bit mask Meaning
0x01 If set, allows multiple.
minecraft:range

A range of values with a min and a max.

Name Type Description
Decimals Boolean Whether decimal values are allowed.

Suggestions Types

Identifier Description
minecraft:ask_server Sends the Tab-Complete packet to the server to request tab completions.
minecraft:all_recipes Suggests all the available recipes.
minecraft:available_sounds Suggests all the available sounds.
minecraft:summonable_entities Suggests all the summonable entities.