Note: 1.13 snapshots have not been released as of the current time. And the syntax has changed again. Who knows how many times it will. This is an informational page only.
In a recent Reddit post, Dinnerbone announced several changes to commands for 1.13, among them the possible removal of the /execute command in favor of more powerful alternatives. The syntax is very volatile at the moment, so this thread may not be up to date at all times. This thread is a second description of how the new commands relate to /execute, and a sequel to my previous thread: How to Use the /execute Command.
The New Commands
The current syntax of the /execute command is:
/execute <selector> <x> <y> <z> <command> /execute <selector> <x> <y> <z> detect <x> <y> <z> <block> <data> <command>
This will be refactored as follows:
/execute as /execute at /execute at /execute if|unless block
/execute if|unless blocks all|masked
/execute if|unless entity
These commands are actually subcommands, which means you can leave off the /execute label when chaining them. The final command is signified by the keyword then.
/execute as <selector> <command>
This runs the specified command with the specified entity(s) as command senders. However, the position the command runs from remains unchanged. For example, running the following from a command block:
/execute as @e[type=creeper,name=Bob] then give @p stone
will give stone to the single player nearest the command block, one block for each creeper named Bob. Use /as for commands where the sender is important, such as the below. A good rule of thumb is to use /as if you plan to use @s later in the command, and to otherwise use /at.
/execute as @e then say @s //each entity says their name /execute as @a[score_importance_min=5] then function importance:do_things_to_important_person //does important things to each matched player
Now...where to execute?
/execute at /execute offset
The /at command is similar to /as, but runs the command from the position of the entity(s) and not using the entity(s) as command senders. For example, the intended use of the previous command targeting creepers named Bob is this.
/execute at @e[type=creeper,name=Bob] then give @p stone
This command will give stone to the player(s) nearest to any creeper named Bob. Use /at for when the sender is not important. When both the sender and the position are important, use both.
/execute as @e[type=creeper] at @s then tell @p Ssssss... //each creeper creeps out the nearest player /execute at @p then teleport @e[tag=special] ~ ~-5 ~ //teleports the special entity five blocks below the nearest player
The /offset command may be used as a direct correspondence to the portion of the original /execute command, to be used in the same circumstances. I don't really have much to say about this one other than to use it when you put anything other than "~ ~ ~" as the coordinates to the old /execute.
/execute if|unless block <x y z> <block> <command> /execute if|unless blocks <src begin> <src end> <dest> all|masked <command> /execute if|unless entity <selector> <command>
The conditional commands are the new and improved /execute ... detect command syntax. For example, this command, which kills arrows that hit tripwire:
/execute @e[type=arrow] ~ ~ ~ detect ~ ~ ~ tripwire -1 kill @s
is rewritten as this:
/execute as @e[type=arrow] at @s if block ~ ~ ~ tripwire then kill @s
/if block is the new version of /testforblock, while /if blocks is the new version of /testforblocks and /if entity is the new version of /testfor
/execute if block ~ ~5 ~ red_wool then function mymap:do_red_wool_things /execute if entity @e[score_awesome_min=1] then setblock ~ ~5 ~ redstone_block
When to use /as or /at?
Each command provides half the functionality of /execute. Which one to use depends on what functionality you need.
- Use /as when you need a specific entity or entities to run the command
- Use /as when you use @s later in the command (including functions)
- Use /at when you need the command run at an entity's position
- Use /if entity when you are testing for the existence of an entity
- Use both when you need the functionality of both
- Remember: /as @s makes no sense!
Removal of common commands
In the process of overhauling /execute, several common commands were removed in favor of the new /execute. Migrating these commands is as follows.
/testfor <entity> /execute if entity <entity> /testforblock <x y z> <block> /execute if block <x y z> /testforblocks <src begin> <src end> <dest> all|masked /execute if blocks <src begin> <src end> <dest> all|masked /tp <selector> <~x ~y ~z> /execute as <selector> at @s then teleport @s <~x ~y ~z>
For writing commands, I recommend the order listed in this thread (/as, /at, /if) as this will reduce bugs caused by incorrect positions or entities. That is, set the command sender, set the position, test conditions.
/execute @e[type=creeper,name=Bob] ~ ~ ~ detect ~ ~-1 ~ minecraft:wool 14 give @p[r=3] stone /execute at @e[type=creeper,name=Bob] if block ~ ~-1 ~ minecraft:red_wool[color=#000000] then give @p[distance=..3] stone /execute @e[tag=destroyable] ~ ~ ~ execute @p ~ ~ ~ playsound portal:destroy player @s ~ ~ ~ 1 1 /execute at @p if entity @e[tag=destroyable] then playsound portal:destroy player @p ~ ~ ~ 1 1 /execute @p ~ ~ ~ detect ~ ~ ~ tripwire -1 function portal:destroy_portals /execute at @p if block ~ ~ ~ tripwire then function portal:destroy_portals /execute @e[tag=portal] ~ ~-1 ~ scoreboard players set @p[dy=1] cooldown 1 /execute at @e[tag=portal] at ~ ~-1 ~ then scoreboard players set @p[dy=1] cooldown 1 /execute @e[name=BluePortal] ~ ~-1 ~ execute @p[dy=1] ~ ~ ~ function portal:teleport_b2o /execute at @e[name=BluePortal] offset ~ ~-1 ~ as @p[dy=1] then function portal:teleport_b2o[/color]