Commands/execute

is a versatile command that executes other commands in a variety of scenarios:


 * Syntax (Java Edition)


 * Full syntax tree:


 * Details


 * There are 11 chainable instructions&mdash;9 instructions that modify command behaviour and 2 conditional instructions&mdash;and a final  instruction for carrying out some following command. A number of instructions can be chained together, but   finalises the command.  The simplest usage for this command is:.


 * Alternatively, using the conditional instructions  or   without   is still valid syntax, in which case the result of the test is returned:


 * The conditional instructions  and   can prevent a command from running at all. All specified conditions must be met for the test to pass and the command to run.


 * The 11 chainable instructions are:


 * 1)   &mdash; Align the current position to the block grid, rounding down (towards negative infinity).
 * 2) *  is any non-repeating combination of the characters 'x', 'y', and 'z'. (For example, ,  ,  , or  .)
 * 3) * Example: Given the position (-1.8, +2.3, +5.9), the command carried out by  instead uses (-2.0, +2.3, +5.0) as the "current position."
 * 4) * Example: Given (+2.4, -1.1, +3.8), using  carries the command out with (2, -2, 3) as the "current position."
 * 5)   &mdash; Use either feet or eye height for ^ ^ ^ coordinates and facing commands.
 * 6)   &mdash; Use the targeted entity/entities, but don't change "current position." If an entity doesn't have an eye anchor point, the command anchors to the feet of the previous executor (not the specified entity).
 * 7)   &mdash; Use the position, rotation, and dimension of the target, but don't change "target entity."
 * 8)   &mdash; Use an execution position that faces either the given position or the targeted entity's eyes or feet.
 * 9)   &mdash; Test for some condition before choosing whether to carry out the command.
 * &mdash; Execute if or unless the block at  matches the ID specified by.
 * &mdash; Execute if or unless the region between  and   matches the block located at.
 * &mdash; Execute if or unless the targeted entity or block has any data for the tag named by.
 * is a string of tag names of the Java-like form.
 * Example:.
 * means foo's child called bar.
 * means element 0 of bar.
 * "quoted strings" may be used if a name of a key needs to be escaped.
 * Example:  would test for if any entity has an "id" for the item in their boot armour slot. Note that this returns true for all mobs, armoured or not.
 * &mmdash; Execute if or unless one or more  exist.
 * &mdash; Execute if or unless the target entity's score accurately relates to source entity's score, given some conditional operator.
 * &mdash; Execute if or unless target entity's score is within given range (e.g.,  ).
 * 1)   &mdash; Execute as though the executor is in the given dimension.
 * 2) *  can be ,  ,  , or any dimension not in the Minecraft namespace.
 * 3)   &mdash; Use either the given coordinates or the targeted entity's coordinates for the "current position."
 * 4)   &mdash; Execute as though the executor is rotated either in the given direction or the same the targeted entity is facing.
 * 5)   &mdash; Store the result or success of a command somewhere. This instruction replaced the   command.
 * 6) *  returns the result of the command. (This replaces the old stats AffectedBlocks, AffectedEntities, AffectedItems, QueryResult.)
 * 7) *  returns how many times the command was successful. This is usually   or , but if the command split up (as perhaps with  ) then success can be a number higher than  . (This replaces the old stat SuccessCount.)
 * 8) * If a command fails,  and   are both  . The return value is stored when the full command has finished executing.
 * &mdash; Use the data tag  from the specified block to save the return value. Store as a byte, short, int, float, or double.
 * &mdash; Use either the  or   setting of the given bossbar to save the return value.
 * &mdash; Use the data tag  from one targeted entity to save the return value. Store as a byte, short, int, float, or double.
 * Like the  command,   cannot modify player NBT. NBT data inside the   key of items in the player's   or  is an exception and can be modified by.
 * &mdash; Use the scoreboard under  and   to save the return value.
 * must exist, but unlike with  you don't need to set an initial value for.
 * 1)   &mdash; See   above.


 * Examples




 * Syntax (Bedrock Edition)


 * 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:

Color added to make reading easier.


 * Arguments


 * origin: target
 * 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 will be run once as each of them.
 * position: x y z
 * Specifies the position from which to run the command. x and z must be within the range -30,000,000 to 30,000,000 (inclusive). Coordinates specified with tilde notation are relative to the target, not to the position of the command's execution.
 * command: command
 * Specifies the command to be run. Must be a valid command.
 * detectPos: x y z ( mode only)
 * Specifies the position of the block to check. x2 and z2 must be within the range -30,000,000 to 30,000,000 (inclusive). May use tilde notation to specify distances relative to (x,y,z).
 * block: Block ( mode only)
 * Specifies the block ID which the block at (x2,y2,z2) must match for the command to run. block must be a valid block id (for example, )
 * data: int ( mode only)
 * 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 entity 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) 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