Note: This is to clarify the /execute command's syntax and abilities. It is NOT a place to ask for help with /summon, /scoreboard, selector arguments, or data tags.
The syntax for the /execute command is
/execute {selector} {x} {y} {z} {command}
but what does it mean? At first, I couldn't figure it out. In fact, I almost posted on the bug tracker. But after some thought, this paradoxical command started to make sense.
Who's Executing?
First, this part selects the entity:
/execute {selector}
The can be @p, @r, @a, or @e with all the parameters. For example,
/execute @e[0,70,0,5,type=Creeper,name=Bob]
will select all Creepers within a radius of 5 blocks of coordinates (0,70,0) named "Bob".
Now...Where To Execute?
This next part may seem redundant, but it has a use.
{x} {y} {z}
determines the coordinates where the command will be executed. For the previous example,
Will now execute the command not at the Creeper's position, but five blocks above the Creeper. Just imagine that you first find a Creeper at (0,70,0), then the Creeper executes a command at (0,75,0).
Now, using fixed coordinates for this is completely redundant. This is used for when an entity may be moving; the command will always be executed in the same position relative to the entity.
Finally...What To Do
And now, the actual command:
{command}
This is a full command with all the arguments, including player selectors. So this,
/execute @e[0,70,0,5,type=Creeper,name=Bob] ~ ~5 ~ give @p[r=3] stone
will make all Creepers named Bob at most five blocks from (0,70,0) give the nearest player within three blocks of the block(s) five blocks above said Creepers stone...right.
Anyways, the command can even be the /execute command itself, which can lead to some interesting scenarios. As a last example,
/execute @e[type=Chicken] ~ ~ ~ execute @p ~ ~ ~ give @p stone
will have all Chickens force the nearest player to give themselves stone.
Execute Detect
The execute command has an alternate syntax:
This part allows for the command to test for a block at a certain position.
detect {x} {y} {z} {block} {data}
The coordinates may be relative or absolute, allowing for the command to test if a certain block is around an entity. Using the example command:
/execute @e[0,70,0,5,type=Creeper,name=Bob] ~ ~5 ~ detect ~ ~-1 ~ minecraft:wool 14 give @p[r=3] stone
This will give said players stone only if the detected Creepers have red wool one block below them. In full sentence structure: "Execute five blocks above all Creepers named Bob within five blocks of the coordinates (0,70,0) with the block red wool one block below them, a command that gives the nearest player within three blocks stone."
The damage value of the block is required, however it can be set to -1 to test for any damage value. This can be used to test for any type of stone brick, or for any color of wool.
can you help, i need to figure out a way for a shot arrow to remove a torch when the arrow is in the block the torch is in, i already have the basic part
/execute [type=Torch] ~ ~ ~ but when i try to do
/execute [type=Torch] ~ ~ ~ fill ~ ~ ~ ~ ~ ~ air replace torch 0 it doesnt work
can you help, i need to figure out a way for a shot arrow to remove a torch when the arrow is in the block the torch is in, i already have the basic part
/execute [type=Torch] ~ ~ ~ but when i try to do
/execute [type=Torch] ~ ~ ~ fill ~ ~ ~ ~ ~ ~ air replace torch 0 it doesnt work
It seems you made a simple mistake. You forgot to put in the coords for the setblock command. I tried it with torches, and it worked amazingly. Here it is:
Unfortunately that only works for on the first slot on your hotbar and if you wanted it to be all hotbar slots you'll have to set this up multiple time using 0-8 for hotbar slots 1-9.
For the commandblock testing for the feather in a sselected slot you will need a redstone clock hooked up to it so it runs forever.
You will then need to put a comparator next to the command block so that that when the command block successfully finds the feather in your hand it will get a signal taken out by the comparator.
Now have that comparater run into a command block that has
/execute @p ~ ~ ~ particle cloud ~ ~ ~ 1 2 1 0 10000
P.S i didn't change the particles part so i don't know if it will work, I've never been good with the particle command stuff
Hi, I'm wondering if there's a way that you could detect if an entity DOESN'T exist, instead of just inverting the signal (as that does eat up time)
I am unfortunately the fasted way test if an entity doesn't exist is to do [1] /testfor @e[0,70,0,r=0,type=Blaze] then in the same tick directly after do [2] /testforblock ~ ~-2 ~ command_block 0 {SuccessCount:0}
this asumes you have it like this
[2] /testforblock -> comparator output to command block [3]
[r ] power source (20hz clock normally)
[1] /testfor @e
if you want to be more specific with what you are trying to achieve i could possibly help more
Pre-note: For 1.13+, see here.
Note: This is to clarify the /execute command's syntax and abilities. It is NOT a place to ask for help with /summon, /scoreboard, selector arguments, or data tags.
The syntax for the /execute command is
but what does it mean? At first, I couldn't figure it out. In fact, I almost posted on the bug tracker. But after some thought, this paradoxical command started to make sense.
Who's Executing?
First, this part selects the entity:
The can be @p, @r, @a, or @e with all the parameters. For example,
will select all Creepers within a radius of 5 blocks of coordinates (0,70,0) named "Bob".
Now...Where To Execute?
This next part may seem redundant, but it has a use.
determines the coordinates where the command will be executed. For the previous example,
Will now execute the command not at the Creeper's position, but five blocks above the Creeper. Just imagine that you first find a Creeper at (0,70,0), then the Creeper executes a command at (0,75,0).
Now, using fixed coordinates for this is completely redundant. This is used for when an entity may be moving; the command will always be executed in the same position relative to the entity.
Finally...What To Do
And now, the actual command:
This is a full command with all the arguments, including player selectors. So this,
will make all Creepers named Bob at most five blocks from (0,70,0) give the nearest player within three blocks of the block(s) five blocks above said Creepers stone...right.
Anyways, the command can even be the /execute command itself, which can lead to some interesting scenarios. As a last example,
will have all Chickens force the nearest player to give themselves stone.
Execute Detect
The execute command has an alternate syntax:
This part allows for the command to test for a block at a certain position.
The coordinates may be relative or absolute, allowing for the command to test if a certain block is around an entity. Using the example command:
This will give said players stone only if the detected Creepers have red wool one block below them. In full sentence structure: "Execute five blocks above all Creepers named Bob within five blocks of the coordinates (0,70,0) with the block red wool one block below them, a command that gives the nearest player within three blocks stone."
The damage value of the block is required, however it can be set to -1 to test for any damage value. This can be used to test for any type of stone brick, or for any color of wool.
Putting the CENDENT back in transcendent!
Or ceck out my old mod for 1.4.7 :
/execute [type=Torch] ~ ~ ~ but when i try to do
/execute [type=Torch] ~ ~ ~ fill ~ ~ ~ ~ ~ ~ air replace torch 0 it doesnt work
For that it would be something like:
/execute @e[type=arrow] ~ ~ ~ setblock ~ ~ ~ air 0 replace
If you're reading this, then you're definitely not a sandwich.
Sorry, my dear, but I don't give a snickerdoodle.
Spoiler alert!
execute @a[score_bedrock_min=1] ~ ~ ~ summon FallingSand ~ ~ ~ {TileID:145}
i hook it to a clock but then it writes:
[12:37:10] The entity UUID provided is in an invalid format
What should i do?:huh:
Putting the CENDENT back in transcendent!
/execute @a -1 ~ ~ setblock minecraft:command_block
execute @p ~ ~ ~ setblock ~ ~ ~ minecraft:torch
You also forgot to put a " ~ " before " -1 ".
It is currently impossible to do this with the execute command. You probably want /stats and /scoreboard objectives, which is far too advanced for me.
Putting the CENDENT back in transcendent!
You need to specify the player and coordinates of the spawn point
Putting the CENDENT back in transcendent!
/execute @e[type=!Player,type=!Rabbit] ~ ~ ~ /summon LightningBolt ~ ~ ~
It's striking the player even when I don't want it to.
There can only be one of each parameter.
Putting the CENDENT back in transcendent!
Is there a way to make it so I can target multiple targets?
Not with a single command. You will have to use one command per entity.
Putting the CENDENT back in transcendent!
I know you might not see this but you need to make a command block with this command:
/testfor @p {SelectedItemSlot:0,Inventory:[{Slot:0b,id:"minecraft:feather"}]}
Unfortunately that only works for on the first slot on your hotbar and if you wanted it to be all hotbar slots you'll have to set this up multiple time using 0-8 for hotbar slots 1-9.
For the commandblock testing for the feather in a sselected slot you will need a redstone clock hooked up to it so it runs forever.
You will then need to put a comparator next to the command block so that that when the command block successfully finds the feather in your hand it will get a signal taken out by the comparator.
Now have that comparater run into a command block that has
/execute @p ~ ~ ~ particle cloud ~ ~ ~ 1 2 1 0 10000
P.S i didn't change the particles part so i don't know if it will work, I've never been good with the particle command stuff
The /summon command does not have a player selector. You probably want
Putting the CENDENT back in transcendent!
I am unfortunately the fasted way test if an entity doesn't exist is to do [1] /testfor @e[0,70,0,r=0,type=Blaze] then in the same tick directly after do [2] /testforblock ~ ~-2 ~ command_block 0 {SuccessCount:0}
this asumes you have it like this
[2] /testforblock -> comparator output to command block [3]
[r ] power source (20hz clock normally)
[1] /testfor @e
if you want to be more specific with what you are trying to achieve i could possibly help more
Be involved in the Survival of Modding in the Post-Notch Era. Enigma + M3L + LiteLoader/API + BlazeLoader {ALL Open-Source!}