Commands

Commands are advanced features activated by typing certain strings of text.

Usage
In the client, commands are entered via the chat window, which is displayed by pressing the key (default) or  key. Using the key will also enter the forward slash that commands require as a prefix, so it is a useful shortcut. The and  key can be used to view previously entered text, including all previously executed commands. Pressing while entering commands cycles through possible commands or arguments, and can be used to auto-enter the coordinates of the block looked at before entering chat.

Commands may also be entered in a multiplayer server's console, but are not preceded by a when entered this way. A server admin running commands in this way is often referred to as "ghosting".

Commands in command blocks can be preceded by a slash, but it is not required. Commands in a command block usually also require an optional argument, like a player's username.

The majority of commands are only available in the following situations:


 * In a multiplayer game, entered by an operator or command block.
 * In other multiplayer games, entered by the player who opened a LAN game with cheats enabled, or is hosting their own multiplayer server
 * In singleplayer, if cheats were enabled at world creation (via the "More World Options..." button).

Some player commands are also available in singleplayer even when cheats are not enabled.

Note: In singleplayer worlds where cheats were not enabled at creation, they can be enabled on a temporary basis by opening the current game session to LAN play ( → "Open to LAN", then "Allow Cheats" button and "Start LAN World"). The player does not actually need to be on a LAN or have others join. This is not permanent, but will allow the use of commands until the player quits the world, and changes the player makes via commands (items spawned, etc.) will be saved with the world. The player can do this each time the player starts playing the world again. Note that this will disable game pausing for the duration, so while open to LAN, you should get somewhere safe or reload your world before using the Game Menu. The player can disable the LAN world by reloading the world.

Tilde and caret notation
Many commands allow relative coordinates to be specified using tildes or carets. A number following a tilde or caret specifies an offset from a certain origin rather than a coordinate. The origin depends on the command. For example, in the offset is from the target's starting position. Other common offsets include from the position of the command's execution or from another coordinate specified by the command.

For tilde notation, the offsets are in the positive directions of the world coordinate axes:. For caret notation, they are along axes originating in the center of the target's head and pointing leftwards, upwards, and forwards, respectively, changing with the head's rotation. In terms of a :. For both, the sign of the offset specifies whether the offset is in the positive or negative direction along that axis. A single tilde or caret by itself is shorthand for  or , meaning no offset in that direction.

For example, will teleport the user to the coordinate (0, 64, 0), while  will teleport the user to a position +3 blocks in the "x" direction (i.e., east), keep their current height, and -3 blocks in the "z" direction (i.e., north) and  will teleport the user to a position +3 forwards in the direction the player is looking.

Usually absolute coordinates can be mixed with relative coordinates. For example, will keep the user's "x" and "z" coordinates the same, but teleport them to absolute height of 64. Similarly, will teleport the player 5 blocks to the right, based on the tilt of their head.

Target selectors in Java Edition
In most commands where a player may be specified as an argument, it is possible to "target" one or more players satisfying certain conditions instead of specifying players by name. To target players by condition, choose a target selector variable and, optionally, one or more target selector arguments to modify the conditions to be satisfied.

For example, to change the game mode of all players on team Red to creative mode, instead of specifying them by name individually:

Target selector variables
A target selector variable identifies the broad category of targets to select. There are five variables:




 * Target the nearest player. When run by the console, the origin of selection will be at (0, 0, 0). If there are multiple nearest players, caused by them being precisely the same distance away, the player who most recently joined the server is selected.


 * Target selector arguments may be used to reduce the set of players from which the nearest player will be selected. For example,  will target the nearest player on team Red even if there are other players closer.


 * The  or  target selector argument can be used to increase the number of nearest players targeted (for example,   or   will target the three nearest players).




 * Target a random player.


 * Target selector arguments may be used to reduce the set of players from which a random player will be targeted. For example,  will only target a random player from team Red.


 * The  target selector argument can be used to increase the number of random players targeted. For example,   will target three random players.


 * The  argument is not allowed on  . To select a random entity, use   instead.




 * Target all players, including dead players. No other selector will find dead players, except.


 * Target selector arguments may be used to reduce the set of players targeted. For example,  will only target players on team Red.




 * Target all entities (including players).


 * Target selector arguments may be used to reduce the set of entities targeted. For example,  will only target cows.




 * Target only one entity—the entity that executed the command, including dead players. If the executor was not an entity, for instance if the executor was a command block or a server console, this selector will find nothing.


 * Target selector arguments may be used to specify whether the executor is actually eligible to be targeted. For example,  will only target the executor of the command if the executor was a cow on team Red.




 * Target your agent only.


 * Target selector arguments may be used to target your agent. For example,  will teleport your agent only to specified location.




 * Target all agents.


 * Target selector arguments may be used to target all agents. For example,  will remove all agents.

Target selector arguments
After a target selector, optional arguments can be used to modify the set of targets selected. When used with  or , arguments narrow down the number of targets from the full list to a specific few. When used with  or , arguments narrow the number of targets down from the full list to a smaller set from which the nearest or random player is selected. When used with, the command user will only be targeted if all arguments pass, otherwise the command will fail.

Add argument-value pairs as a comma-separated list contained within square brackets after the target selector variable:



Arguments and values are case-sensitive. Spaces are allowed around the brackets, equal signs, and commas, except in between the target variable and the first bracket. Commas must be used to separate argument-value pairs.


 * Position arguments


 * Define a position in the world for use with either the  argument or the distance component arguments, ,   and  . Defining position alone has no use without these, so applying it (and only it) to   still selects all entities in the world.
 * The positional components are doubles, allowing for values like, and they are not center-corrected, meaning   is no longer corrected to   - tilde notation is available for selector argument coordinates.
 * The positional components are doubles, allowing for values like, and they are not center-corrected, meaning   is no longer corrected to   - tilde notation is available for selector argument coordinates.


 * Selecting targets by distance


 * - Filter target selection based on their Euclidean distances from some point. If the positional arguments are left undefined, radius/i is calculated relative to the postion of the command's execution. Only unsigned values are allowed.
 * Ranges are supported, allowing circular regions to be defined:
 * — Target all entities exactly 10 blocks away.
 * — Target all entities more than 10 blocks but less than 12 blocks away (inclusive).
 * — Target all entities at least 5 blocks away.
 * — Target all entities at most 15 blocks away.




 * - Filter target selection based on their x-difference, y-difference, and z-difference from some point, as measured from the closest corner of the entities' hitboxes.
 * This can be interpreted as creating a rectangular volume defined by an initial position (,,) and diagonal vector (,,), then selecting all entities whose hitboxes are at least partially contained by that volume. If the positional arguments are left out, the selection is interpreted as originating from the position of the command's execution. Any values are allowed, including signed and fractional numbers.
 * Note that, ,  specify signed differences from the given coordinate. They do not specify a separate coordinate, nor do they extend in both the positive and negative directions.
 * — Select all entities whose hitbox collects with the block region (1~5, 2~7, 3~9) (or, mathematically speaking, the region which is {(x,y,z)∈R3|x∈[1.0,5.0),y∈[2.0,7.0),z∈[3.0,9.0)}).
 * — Select all entities whose hitbox contains the point (1,2,3).
 * It is possible to combine selection by distance and selection by volume, in which case the command will only select targets within the overlap of both regions (within certain radius/i of the volume's initial point and not outside the defined volume).


 * Selecting targets by scores


 * - Filter target selection based on their scores in specified objectives.
 * All tested objectives are in a single tag, with a list of individual score selectors between braces afterwards. The selectors inside the braces support ranges.
 * — Select all entities with a score in objective myscore of exactly 10.
 * — Select all entities with a score in objective myscore of between 10 and 12 (inclusive).
 * — Select all entities with a score in objective myscore of 5 or greater.
 * — Select all entities with a score in objective myscore of 15 or less.
 * To
 * — Select all entities with a score in objective foo of exactly 10, and a score in objective bar of between 1 and 5 (inclusive).


 * Selecting targets by team


 * - Filter target selection to those who are on a given team.
 * — Filter to those who are not on a given team.
 * — Filter to those who are teamless.
 * — Filter to those who have some team.


 * Limiting and sorting target selection


 * - Limit the number of targets selected to be no higher than the given value.
 * When using the variables  and , this argument defaults to 1. Applying the   argument to them may artificially increase the number of nearest or random targets selected. When applying this argument to   or  , this argument returns only a limited number of targets.
 * - Limit the number of targets, and specify selection priority.
 * — Sort by increasing distance. (Default for )
 * — Sort by decreasing distance.
 * — Sort randomly. (Default for )
 * — Do not sort. (Default for,  )
 * or  or   — Select the nearest 3 players.
 * or  — Select the furthest 4 players.
 * or  — Select 2 players, chosen randomly.


 * Selecting targets by experience level


 * - Filter target selection based on their experience levels. This naturally filters out all non-player targets.
 * This selector supports ranges:
 * — Select all players who have exactly 10 levels.
 * — Select all players who have between 10 and 20 levels (inclusive).
 * — Select all players who have at least 30 levels.
 * — Select all players who have at most 29 levels.


 * Selecting targets by game mode


 * — Filter target selection to those who are in the specified game mode.
 * — Filter target selection to those who are not in the specified game mode.
 * Permitted values for  are,  ,  , and.
 * This naturally filters out all non-player targets.
 * or  or   — Select all players who are in Survival mode.
 * — Select all players who are not in Spectator mode.


 * Selecting targets by name


 * — Filter target selection to all those with a given name.
 * — Filter target selection to all those without a given name.
 * This is a string, so spaces are only allowed if quotes are applied. This cannot be a JSON text compound.
 * - Select all entities that are not named "Steve".


 * Selecting targets by vertical rotation


 * — Filter target selection based on their pitch, or more specifically their declination from the horizon, measured in degrees. Values range from -90 (straight up) to 0 (at the horizon) to +90 (straight down).
 * This argument supports ranges:
 * — Select all entities that are looking directly at the horizon.
 * — Select all entities that are looking between 30&deg; and 60&deg; (inclusive) below the horizon.
 * — Select all entities that are looking 45&deg; or more below the horizon.
 * — Select all entities that are looking at or above the horizon.


 * Selecting targets by horizontal rotation


 * — Filter target selection based on their rotation in the horizontal XZ-plane, measured clockwise in degrees from due south (or the positive Z direction). Values vary from -180 (facing due north) to -90 (facing due east) to 0 (facing due south) to +90 (facing due west) to +180 (facing due north again).
 * This argument supports ranges.
 * — Select all entities that are facing due south.
 * — Select all entities that are facing 45&deg;west of south.
 * — Select all entities that are facing 6&deg;north of west.
 * — Select all entities that are facing in the 90&deg; between due east and due south (inclusive).
 * — Select all entities that are facing between due east and due west (inclusive), through south.
 * — Select all entities that are not facing at all east.


 * Selecting targets by type


 * — Filter target selection to those of a specific entity type.
 * — Filter target selection to those not of a specific entity type.
 * The given entity type must be a valid entity ID or tags used to identify different types of entities internally. The namespace can be left out if the ID is within the  namespace. (For example,   for creepers,   for regular minecarts,   for primed TNT, etc.) Entity IDs or tags are case-sensitive.
 * When using the  parameter, this argument defaults to the type  . Defining a type for this parameter can filter the random selection to only entities.
 * — Select all skeletons.
 * — Select all entities except chickens and cows.
 * - Not applicable; select all entities that are simultaneously a chicken and a cow.
 * — Select all skeletons, wither skeletons, and strays.


 * Selecting targets by data tag


 * — Filter target selection to those that have at least one tag of the given name.
 * — Filter to those that have no tags of the given name.
 * — Filter to those that have exactly zero tags.
 * — Filter to those that have at least one tag.
 * Multiple tag arguments are allowed. All arguments specifications must be fulfilled for an entity to be selected.
 * — Select all entities that have tags a and b but not tag c.
 * — Select one random player who has tag a.


 * Selecting targets by NBT


 * — Select all targets that have the specified NBT. The NBT is written in its command definition.
 * For example:
 * — Select all players on the ground.
 * — Select all sheep that are dyed white.
 * — Selects all slime ball drops.
 * is the same as . The latter is simpler and reduces CPU load.
 * Note: When matching string form of namespaced IDs within a tag, the namespace cannot be omitted.
 * Hence  cannot find any drop as the  field always contains a namespaced ID-converted string.


 * Selecting targets by advancements


 * Since 1.13, target selector uses advancements in place of . The argument name is the advancement id (namespace can be left out when namespaced ). The value is true, false or so.
 * — Selects players who have achieved the advancement minecraft:story/from_obsidian.
 * — Selects players who haven't achieved the advancement minecraft:story/from_obsidian.
 * — Selects players who had armored with iron helmet. The selected players needn't be wearing iron helmet when selected, and needn't have achieved the advancement minecraft:story/obtain_armor.
 * is the same as.

Data tags
A data tag is a tree-shaped data structure which can be described starting with attribute-value pairs enclosed in curly braces. One common usage of data tags in Java Edition is in commands, used to specify complex data for any entity.

A data tag consists of zero or more attribute-value pairs delimited by commas and enclosed in curly braces. Each attribute-value pair consists of an attribute name and the attribute's value, separated by a colon. Some values, however, may themselves contain attribute-value pairs, allowing a data tag to describe a hierarchical data structure.


 * Example:

The data structures that data tags describe are the same ones used in Minecraft's save files. These data structures are described in other articles and commands expect data tags to use the same attribute names (which are case-sensitive):

The defined data structures also expect the values to be of the correct type.

Some commands may require that a number's type be specified by adding a letter (B, S, L, F, D) to the end of the value. For example,  for a short,   for a float, etc. (This doesn't work with I for int.) The letter can be uppercase or lowercase. When no letter is used and Minecraft can't tell the type from context, it assumes double if there's a decimal point, int if there's no decimal point and the size fits within 32 bits, or string if neither is true. A square-bracketed literal is assumed to be a list unless an identifier is used:  for an int array and   for a long array.

When commands such as, , and are used to match data tags, they only check for the presence of the provided tags in the target entity/block/item. This means that the entity/block/item may have additional tags and will still match. This is true even for lists and arrays: the order of a list is not acknowledged, and as long as every requested element is in the list, it will match even if there are additional elements.

The format used for data tags is a lenient form of JSON.

Raw JSON text
The and  commands use strict JSON syntax.

Scores and target selectors are evaluated for a Sign when it is placed or edited and for a Written Book when it is "resolved" (opened for the first time after signing). They won't update after that, and they won't work if edited onto an existing sign with an NBT editor, or onto a book that's already marked resolved. There's no way to wrap text onto the next line of a sign or the next page of a book during resolution; instead, the extra text will simply disappear.

The format of raw JSON text is a JSON string, a  JSON array, or a  JSON Object which supports the following (mostly optional) elements:
 * A string representing raw text to display directly in chat. Same as only having a tag in the  base object.
 * Same as having all elements except the first in this array appended to the end of the array of the first chat component in this array. Each element repeats this raw JSON text structure.
 * The base chat component object.
 * : A string representing raw text to display directly in chat. Note that selectors such as "@a" and "@p" are not translated into player names; use selector instead. Can use escape characters, such as for newline (enter),  for tab, etc.
 * : The translation identifier of text to be displayed using the player's selected language. This identifier is the same as the identifiers found in lang files from assets or resource packs. Ignored when exist in the root object.
 * : A player's score in an objective. Displays nothing if the player is not tracked in the given objective. Ignored when any of the previous fields exist in the root object.
 * : The name of the player whose score should be displayed. Selectors (such as @p) can be used, in addition to "fake" player names created by the scoreboard system. In addition, if the name is "*", it will show the reader's own score (for example,  will show every online player their own score in the "obj" objective).
 * : The internal name of the objective to display the player's score in.
 * : Optional. If present, this value is used regardless of what the score would have been.
 * : A string containing a selector (@p,@a,@r,@e or @s) and, optionally, selector arguments. Unlike text, the selector will be translated into the correct player/entity names. If more than one player/entity is detected by the selector, it will be displayed in a form such as 'Name1 and Name2' or 'Name1, Name2, Name3, and Name4'. Ignored when any of the previous fields exist in the root object. Clicking a player's name inserted into a /tellraw command this way will suggest a command to whisper to that player. Shift-clicking a player's name will insert that name into chat. Shift-clicking a non-player entity's name will insert its UUID into chat.
 * : A string that can be used to display the key needed to preform a certain action. An example is  which will always display "E" unless the player has set a different key for opening their inventory. Ignored when any of the previous fields exist in the root object.
 * : A string indicating the NBT path used for looking up NBT values from an entity or a block entity. Ignored when any of the previous fields exist in the root object.
 * : A list of chat component arguments and/or string arguments to be used by . Useless otherwise.
 * The arguments are text corresponding to the arguments used by the translation string in the current language, in order (for example, the first list element corresponds to "%1$s" in a translation string). Argument structure repeats this raw JSON text structure.
 * : A boolean to indicate whether the game should interpret the SNBT value at the path indicated by as a raw JSON text (according to this raw JSON text structure). Useless otherwise.
 * : A string specifying the coordinates of the block entity from which the NBT value is obtained. The coordinates can be absolute or relative. Useless if is absent.
 * : A string specifying the target selector for the entity from with the NBT value is obtained. Useless if is absent.
 * : A list of additional objects, sharing the same format as the base object.
 * A list element whose structure repeats this raw JSON text structure. Note that all properties of this object are inherited by children except for text, extra, translate, with, and score. This means that children will retain the same formatting and events as this object unless they explicitly override them.
 * : The color to render this text in. Valid values are "black", "dark_blue", "dark_green", "dark_aqua", "dark_red", "dark_purple", "gold", "gray", "dark_gray", "blue", "green", "aqua", "red", "light_purple", "yellow", "white", and "reset" (cancels out the effects of colors used by parent objects). Technically, "bold", "italic", "underlined", "strikethrough", and "obfuscated" are also accepted, but it may be better practice to use the tags below for such formats.
 * : Boolean (true/false) - whether to render text in bold. Defaults to false.
 * : Boolean (true/false) - whether to render text in italics. Defaults to false.
 * : Boolean (true/false) - whether to render text underlined. Defaults to false.
 * : Boolean (true/false) - whether to render text with a strikethrough. Defaults to false.
 * : Boolean (true/false) - whether to render text obfuscated. Defaults to false.
 * : When the text is shift-clicked by a player, this string will be inserted in their chat input. It will not overwrite any existing text the player was writing.
 * : Allows for events to occur when the player clicks on text.
 * : The action to perform when clicked. Valid values are "open_url" (opens value as a URL in the player's default web browser), "open_file" (opens the value file on the user's computer), "run_command" (has value entered in chat as though the player typed it themselves. This can be used to run commands, but the command will fail if the player does not have the required permissions to use it), "change_page" (can only be used in written books) changes to page value if that page exists, and "suggest_command" (similar to "run_command" but it cannot be used in a written book, the text only appears in the player's chat input and it is not automatically entered. Unlike insertion, this will replace the existing contents of the chat input). "open_file" is used in messages automatically generated by the game (e.g. on taking a screenshot) and cannot be used in commands or signs.
 * : The URL, file, chat, command or book page used by the specified action. Note that commands must be prefixed with the usual "/" slash.
 * : Allows for a tooltip to be displayed when the player hovers their mouse over text.
 * : The type of tooltip to show. Valid values are "show_text" (shows raw JSON text), "show_item" (shows the tooltip of an item which can have NBT tags), and "show_entity" (shows an entity's name, possibly its type, and its UUID).
 * : The formatting of this tag varies depending on the action. Note that "show_text" is the only action to support an Object as the value; all other action values are Strings and should thus be wrapped in quotes.
 * "show_text" can be either a raw string of text or an object with the same formatting as this base object. Note that clickEvent and hoverEvent do not function within the tooltip, but the formatting and extra tags still work.
 * "show_item" can be a string formatted like item NBT data. Contains the "id" tag, and optionally the "Damage" tag and "tag" tag (which is the same compound used as "dataTag" in the command).
 * "show_entity" can be string formatted like a compound with the string values "type" (such as "Zombie"), "name", and "id" (should be an entity UUID, but can actually be any string).

Due to the extra tag, the above format may be recursively nested to produce very complex and functional text strings. However, a raw json text doesn't have to be complicated at all: virtually all properties are optional and may be left out.

To be valid, each object must have at least either text, translate, score, selector or keybind (everything else is optional). As a matter of shorthand, however, the entire Object may be substituted with a String. In this case, that string will be considered the value of the text property. For example,  is equivalent to. This shorthand substitution is valid anywhere a raw text object is required (including the base  argument of, the elements of the extra list, and the value of a "show_text" hover_event).

also accepts an array of objects and/or strings; they are concatenated. It even accepts a tree of nested arrays; they are traversed depth-first. For example:

/tellraw @a ["Hello there, ",{"selector":"@p"},"."] /tellraw @a [["The "],[["quick ","brown "],[{"selector":"@p"}," jumps "],"over "],"the "],["lazy ","dog."]

Finally, unlike other commands using JSON, Strings support Unicode via the notation , where #### is the Unicode hexadecimal number for the desired character.


 * External links


 * Skylinerw's JSON Text Component
 * Tellraw Generator
 * List of all Keybinds

Block/item/entity... names
Many commands have arguments that identify particular types of blocks, items, entities, advancements, bossbars, effects, enchantments and so on. In the command syntax below, these typically appear as elements named,  , or the like which are replaced with identifiers such as   in the examples. These IDs all have namespaces. All original Minecraft contents are namespaced  while contents from mods or data packs have other namespaces. Namespace prefix of IDs namespaced  can be omitted for most situations; however, in certain cases, such as NBT data tag matching, full namespaced ids are required.

List of argument types in Java Edition
These are the argument types in Minecraft: Java Edition.

List and summary of commands
The table below summarizes all commands, including upcoming ones. Click a column heading to sort by that column. Click the link in the first unit of each row to get detailed usage of each command.

Command guide

 * Syntax


 * {| class="wikitable" style="text-align:center" data-description="Syntax"

! If you see... !! Then
 * plain text || Enter this literally, exactly as shown.
 * || Replace this with an appropriate value.
 * || This is an optional argument.
 * || (Required) Pick one of the entries shown, often literal words.
 * || (Optional) Pick one of the entries shown, often literal words.
 * ellipsis ... || This entry may repeat more than once.
 * : || The argument is expected to be an integer.
 * : || The argument is expected to be a double-precision float.
 * : || The argument is expected to be a string. Quotes must be applied if any non-alphanumeric characters show up in the string.
 * }
 * ellipsis ... || This entry may repeat more than once.
 * : || The argument is expected to be an integer.
 * : || The argument is expected to be a double-precision float.
 * : || The argument is expected to be a string. Quotes must be applied if any non-alphanumeric characters show up in the string.
 * }
 * : || The argument is expected to be a double-precision float.
 * : || The argument is expected to be a string. Quotes must be applied if any non-alphanumeric characters show up in the string.
 * }
 * }


 * Success Conditions


 * A command's Success Conditions must be met in order for the game to consider the command "successful". This is used to determine a variety of things, such as the output of a redstone comparator feeding from a command block with a command. Note that not all "successful" commands actually do something, and not all "failed" commands fail to do something useful.


 * Restrictions


 * Describes restrictions on who can use the command or in what context.
 * None: The command can be used by any player in any world. The following commands have no restrictions:, , , and.
 * Operator: The command may only be used by an operator or in singleplayer mode with cheats enabled. On multiplayer servers, the results of these commands are broadcast to other ops online.
 * Multiplayer: The command is only available on a multiplayer server. The following commands are restricted to multiplayer servers:, , , , , , , , , , , , , ,.
 * No multiplayer commands permit target selectors in arguments.
 * Except for, multiplayer commands cannot be used in command blocks.
 * Many of these commands can be used on players who have never been to the server, or even on names which are not (or cannot be) registered as Minecraft accounts.
 * No command blocks: The command cannot be executed by a command block.

Video
Video made by slicedlime: