Commands/execute

is a versatile command that modifies variables or procedures in the execution of another command.

Java Edition
$$, there are twelve instructions (or sub-commands) for the  command. Multiple sub-commands are connected after /execute. Subcommands are divided into 4 categories: modify subcommands, condition subcommands, store subcommands, and  subcommand.
 * Modify subcommands modify command variables and change the situation the command is executed, and execute subcommands following it with specific executor(s), execution position(s), execution dimension(s), and execution rotation(s).
 * Condition subcommands are used to test whether certain conditions are true and output results or limit conditions of execution.
 * Store subcommands can store the return values of the command in a scoreboard or the data of an entity, block entity or storage, and can also change the maximum or current value of a boss bar.
 * subcommand is used for carrying out another command.

A number of sub-commands needed can be chained together. Subcommands other than the  subcommand can be arranged arbitrarily or used multiple times. But the  subcommand can only be used once and must at the end of the subcommands chain. A  subcommand or a condition subcommand finalizes the command, otherwise the command does nothing. The game processes these subcommands in order from front to end, for example, the following commands are different:
 * All entities move one block forward:
 * All entities move to one block in front of the executor:

The game processes other subcommands before processing  and store subcommands, so the   and store subcommands cannot affect other subcommands. The  commands and store subcommands cannot affect each other as well. In some cases, the command terminates halfway and does nothing.

After the command is executed (if it does not terminate halfway), it returns a  and a   value (see  for details). These two values ​​come from the last subcommand (may be a condition subcommand or  subcommand). Note that the return value of the command must be an integer, if not, it is rounded down. The  value is usually 0 or 1. When the command fails, both return values ​​are 0. When the last subcommand (may be a condition subcommand or  subcommand) is executed multiple times, only values of the last execution can be returned. The two values can be stored by store subcommands.

command also has a success count (whether or not terminates halfway). This is usually  or , but if the command split up (as perhaps with "/execute as @a -> execute") then success can be a number higher than. When executing it with the command block, the success count is returned to the command block, which can be checked by the conditional command block for success or be read with a redstone comparator.

There are twelve instructions (or sub-commands) for the  command, and each has its own special syntax, so describing syntax takes a large branching tree.


 * Full syntax tree:
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.
 * where  represents the start of another subcommand.

align
Convert execution position's coordinates of specified axes to block position (rounding down, toward negative infinity.).
 * Syntax
 * Arguments
 * Any non-repeating combination of the characters 'x', 'y', and 'z'. (For example,,  ,  , or  .)
 * Result
 * Error if the argument is not specified correctly.
 * Example
 * Given the position (-1.8, +2.3, +5.9), the command  summons a zombie at (-2.0, +2.3, +5.0).
 * Given (+2.4, -1.1, +3.8), using  sets the player's spawnpoint to (2, -2, 3).
 * Given the position (-1.8, +2.3, +5.9), the command  summons a zombie at (-2.0, +2.3, +5.0).
 * Given (+2.4, -1.1, +3.8), using  sets the player's spawnpoint to (2, -2, 3).

anchor
Stores the distance from the feet to the eyes of the entity that is executing the command in the anchor, which is part of the command context. Default of anchor is feet.

The only places where the anchor is used is in the caret notation and in the   subcommand of the   command.
 * Syntax
 * Arguments
 * Must be one of  and.
 * Result
 * Error if the argument is not specified correctly.
 * Result
 * Error if the argument is not specified correctly.

as
Change the executor to the targeted entity/entities, but does not change position or rotation of execution. Changes the function of the  target selector variable
 * Syntax
 * Arguments
 * Specifies the target(s). Must be a player name, a target selector or a UUID
 * Permits entities other than players.
 * Result
 * Error if the argument is not specified correctly.
 * Terminates if  fails to resolve to one or more valid entities (named players must be online).
 * When multiple entities are selected, next subcommand is executed once each per executor.
 * Example
 * Get data of all sheep:
 * Example
 * Get data of all sheep:

at
Use the position, rotation, and dimension of the target(s), but does not change the current executor. Changes the function of  and   positioning.
 * Syntax
 * Arguments
 * Specifies the target(s). Must be a player name, a target selector or a UUID
 * Permits entities other than players.
 * Result
 * Error if the argument is not specified correctly.
 * Terminates if  fails to resolve to one or more valid entities (named players must be online).
 * When multiple entities are selected, next subcommand is executed once each per execution position.
 * Example
 * All sheep move upward 1 block:
 * Kill yourself:
 * All sheep move upward 1 block:
 * Kill yourself:

facing
Change the execution rotation to facing either the given position or the targeted entity's/entities' eyes or feet, but does not change the current executor. Changes the function of  positioning.
 * Syntax
 * Arguments
 * Specifies the target(s). Must be a player name, a target selector or a UUID
 * Permits entities other than players.
 * Must be one of  and.
 * Must be in form of . May use tilde and caret notation.
 * Result
 * Error if the argument is not specified correctly.
 * Terminates if  fails to resolve to one or more valid entities (named players must be online).
 * When multiple entities are selected, next subcommand is executed once each per execution rotation.
 * Example
 * All entities move one block in the direction of (0, 64, 0) (without changing their rotation):
 * All entities move one block in the direction of (0, 64, 0) (with changing their rotation):
 * All non player entities move one space in the direction of their nearest player (without changing their orientation):
 * Example
 * All entities move one block in the direction of (0, 64, 0) (without changing their rotation):
 * All entities move one block in the direction of (0, 64, 0) (with changing their rotation):
 * All non player entities move one space in the direction of their nearest player (without changing their orientation):

in
Change the execution dimension to specified dimension.
 * Syntax
 * Arguments
 * Must be in form of namespaced ID.
 * The standard dimensions in the minecraft namespace are "overworld", "the_nether", and "the_end".
 * Result
 * Error if the argument is not specified correctly.
 * Example
 * Looking for an end city in the end (can find even though players is in the overworld):
 * Transport player to the nether with coordinates unchanged:
 * Looking for an end city in the end (can find even though players is in the overworld):
 * Transport player to the nether with coordinates unchanged:

positioned
Use either the given coordinates or the targeted entity's coordinates for the execution position. Changes the function of  and   positioning. Does not change rotation, dimension, or executor.
 * Syntax
 * Arguments
 * Specifies the target(s). Must be a player name, a target selector or a UUID
 * Permits entities other than players.
 * Must be in form of . May use tilde and caret notation.
 * Result
 * Error if the argument is not specified correctly.
 * Terminates if  fails to resolve to one or more valid entities (named players must be online).
 * When multiple entities are selected, next subcommand is executed once each per execution position.
 * Example
 * Look for a village near (0, 64, 0):
 * Let all sheep move one block in the direction of the executor's rotation (for example, when the executor looks east, the sheep moves one block eastward; when the executor looks up, the sheep moves one block upward):
 * When multiple entities are selected, next subcommand is executed once each per execution position.
 * Example
 * Look for a village near (0, 64, 0):
 * Let all sheep move one block in the direction of the executor's rotation (for example, when the executor looks east, the sheep moves one block eastward; when the executor looks up, the sheep moves one block upward):

rotated
Change the execution rotation to rotating either in the given direction or the same the targeted entity is facing.
 * Syntax
 * Arguments
 * Specifies the rotation. In form of
 * For the horizontal rotation, -180.0 for due north, -90.0 for due east, 0.0 for due south, 90.0 for due west, to 179.9 for just west of due north, before wrapping back around to -180.0.
 * For the vertical rotation, -90.0 for straight up to 90.0 for straight down.
 * Tilde notation can be used to specify a rotation relative to the current execution rotation.
 * Result
 * Error if the argument is not specified correctly.
 * Terminates if  fails to resolve to one or more valid entities (named players must be online).
 * When multiple entities are selected, next subcommand is executed once each per execution rotation.
 * Example
 * Move every sheep 1 block toward the player closest to it:
 * When multiple entities are selected, next subcommand is executed once each per execution rotation.
 * Example
 * Move every sheep 1 block toward the player closest to it:

Condition subcommands
The particular use of the  and   subcommands are to restrict command execution to happen only under specified conditions. is a negation of, equivalent to "if not..." The two commands have identical argument structures.

There are six different types of conditions:
 * 1) (if|unless) block – Tests a single real block
 * 2) (if|unless) blocks – Tests a real 3D rectangular volume against another
 * 3) (if|unless) data – Tests the data held by a real block, entity, or a storage
 * 4) (if|unless) entity – Tests whether an entity like the one given is real
 * 5) (if|unless) predicate – Tests a predicate
 * 6) (if|unless) score - Tests an target's score

(if|unless) block
Compares the block at a given position to a given block ID.


 * Syntax
 * Arguments
 * – Position of a target block to test.
 * – A block ID or a block tag to test against, followed by block states and data tags if needed; see Command.
 * – A block ID or a block tag to test against, followed by block states and data tags if needed; see Command.

(if|unless) blocks
Compares two equally sized volumes.


 * Syntax
 * Arguments
 * and  – Positions of any two diagonal corners of the source volume (the comparand; the volume to compare).
 * – Position of the lower northwest corner of destination volume (the comparator; the volume to compare to). Assumed to be of the same size.
 * All three of the above may use tilde and caret notation.
 * – Specifies whether all blocks in the source volume should be compared, or if air blocks should be masked/ignored.
 * – Specifies whether all blocks in the source volume should be compared, or if air blocks should be masked/ignored.

(if|unless) data
Checks whether the targeted block, entity or storage has any data for the tag named by.


 * Syntax
 * Arguments
 * Option:  – Checks a targeted block
 * – Position of the block to test
 * – An NBT path to check for
 * Option:  –
 * – Target entity
 * – An NBT path to check for
 * Option:  –
 * – An NBT path to check for
 * – An NBT path to check for
 * Option:  –
 * – An NBT path to check for
 * – An NBT path to check for

(if|unless) entity
Checks whether one or more exist.


 * Syntax
 * Arguments
 * – The target(s) to check, in the form of a player name, a UUID, or a target selector.
 * Permits entities other than players.
 * Permits entities other than players.

(if|unless) predicate
Checks whether the evaluates to a positive result. See Predicate for more information.


 * Syntax

(if|unless) score
Check whether the target entity's score accurately relates to source entity's score, given some conditional operator.


 * Syntax
 * Arguments
 * – A single score holder, in the form of a player name, a UUID, a target selector or a (can be executed but fails)
 * – A scoreboard objective
 * Option:  – For comparing one entity's score to that of another
 * – A second score holder to compare against, in the form of a player name, a UUID, a target selector or a (can be executed but fails)
 * – A scoreboard objective
 * Option:  – For comparing one entity's score to a range
 * – A range arguement (e.g.,  ).
 * Option:  – For comparing one entity's score to a range
 * – A range arguement (e.g.,  ).

Result

 * Error if the argument is not specified correctly.
 * When not at the end of the subcommands chain, only if the condition tests pass is the subcommand following it executed. If it is executed multiple times by multiple variables (e.g. executors, execution positions, execution rotations), it acts as a variable filter - Only the variable that matches the condition executes the next subcommand.
 * When at the end of the subcommands chain, it checks whether the condition is met and then outputs.

Example

 * Kill all players standing on a wool:
 * Check whether your own scores A and B are equal:

Store subcommand
Store the  or a   value of the final command somewhere. It first records the location to store in, and then stores in the location after all the commands are executed. Note that the return values of commands must be an integer. If a decimal, it is rounded down.

There are five different modes of storage:
 * 1) store block – Store return value under one of a block's NBTs
 * 2) store bossbar – Store return value as a bossbar data
 * 3) store entity – Store return value under one of an entity's NBTs
 * 4) store score – Store return value under a target's score on an objective
 * 5) store storage – Store return value under one of a storage's NBTs

store ... block
Saves the final command's return value as tag data within a block entity. Store as a byte, short, int, long, float, or double. If the return value is a decimal, it is rounded first and then multiplied by.


 * Syntax
 * Arguments
 * – Position of target block
 * Result
 * Error if the argument is not specified correctly.
 * Does not store anything when the path does not exist.
 * Does not store anything when the path does not exist.

store ... bossbar
Saves the final command's return value in either a bossbar's current value or its maximum value.


 * Syntax
 * Arguments
 * – ID of the bossbar to target for saving
 * Result
 * Error if the argument is not specified correctly.
 * Result
 * Error if the argument is not specified correctly.

store ... entity
Save the final command's return value in one of an entity's data tags. Store as a byte, short, int, long, float, or double. If the return value is a decimal, it is rounded first and then multiplied by. Like the "" command, "/execute store " cannot modify player NBT.


 * Syntax
 * Arguments
 * – A single entity, which can be a player name, a target selector or a UUID.
 * – A single entity, which can be a player name, a target selector or a UUID.


 * Result
 * Error if the argument is not specified correctly.
 * Does not store anything when the path does not exist.

store ... score
Overrides 's score on the given   with the final command's return value.


 * Syntax
 * Arguments
 * – Specifies score holder(s) whose score is to be overridden, which can be a player name, UUID, target selector or a
 * – A scoreboard objective
 * Result
 * Error if the argument is not specified correctly.
 * Error if the argument is not specified correctly.

store ... storage
Uses the  within storage to store the return value in. Store as a byte, short, int, long, float, or double. If the return value is a decimal, it is rounded first and then multiplied by. If the storage does not yet exist, it gets created.


 * Syntax
 * Arguments
 * – Target storage container, as a namespaced ID
 * – Target storage container, as a namespaced ID


 * Result
 * Error if the argument is not specified correctly

Run subcommand
Its single argument is the command to be executed, the variables of which may be modified by the subcommands used.

Arguments

 * Can be any command


 * Technical: Resets the command node to the root of the command dispatcher
 * Information on modelling commands as chat text:
 * The command dispatcher is what starts when the player begins a message with a forward-slash.
 * A command node is the specific word/entry the cursor is editing, either a command or an argument.
 * The root node comes before the first word in the current command.

Result
Execute this command. Fails if  is failure.

More examples

 * Teleport all players who have an item enchanted with Efficiency in their first hotbar slot to coordinates (0, 64, 0):
 * Create a smoke particle three blocks in front of all players:
 * Place a saddle on pigs located within 5 blocks of the executing player, and remove saddles from pigs located over 5 blocks away from the executing player:
 * Make a player say "My feet are soaked!" in chat if they are located in a block of water:
 * Make a player say "Score is reset" in chat if the score 'test' is not set, eg by doing "scoreboard players reset @s test":
 * Make a player say "My feet are soaked!" in chat if they are located in a block of water:
 * Make a player say "Score is reset" in chat if the score 'test' is not set, eg by doing "scoreboard players reset @s test":
 * Make a player say "Score is reset" in chat if the score 'test' is not set, eg by doing "scoreboard players reset @s test":
 * Make a player say "Score is reset" in chat if the score 'test' is not set, eg by doing "scoreboard players reset @s test":

Syntax

 * An alternate syntax allows the command to be executed only if a specific block is detected:
 * An alternate syntax allows the command to be executed only if a specific block is detected:

Arguments

 * Specifies the target to be the command's executor. Must be a player name or target selector. If more than one entity is selected, the command is run once as each of them.


 * Specifies the position from which to run the command. Coordinates specified with tilde and caret notation are relative to the target, not to the position of the command's execution.


 * Specifies the command to be run. Must be a valid command.


 * Specifies the position of the block to check. May use tilde and caret notation to specify distances relative to.


 * Specifies the block ID that the block at detectPos, must match for the command to run. Must be a valid block ID.


 * Must be a valid block data for that type of block or  to match any block data.

Result
Fails if arguments are not specified correctly, if  fails to resolve to one or more valid entities (named players must be online), if the checked block is not of the correct block id, data or state, or if the specified command fails.

On success, executes the specified command as if executed by the specified target(s), done with operator-level permission at the specified coordinate.

Examples

 * To summon lightning bolts at the positions of every zombie:
 * To summon lightning bolts at the positions of every zombie standing on any type of sand:
 * To summon 10 creepers at the nearest player's position (only works as long as there are at least 10 entities in the loaded world):
 * To summon 10 creepers at the nearest player's position (only works as long as there are at least 10 entities in the loaded world):
 * To summon 10 creepers at the nearest player's position (only works as long as there are at least 10 entities in the loaded world):

History
Befehl/execute Команды консоли/execute Команди консолі/execute 命令/execute