How To Use The /execute Command - Minecraft: Java Edition

Help Sign In/Register
  • Home
  • Minecraft Forum
  • Minecraft: Java Edition
  • Redstone Discussion and Mechanisms
  • Commands, Command Blocks and Functions
  • How To Use The /execute Command
  • ||
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 12
  • Next
  • #1 Feb 16, 2014 kwerti kwerti
    • View User Profile
    • View Posts
    • Send Message
    View kwerti's Profile
    • A Space Odyssey
    • Join Date: 1/18/2013
    • Posts: 2,013
    • Location: Louverdahl
    • Member Details

    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

    /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,

    /execute @e[0,70,0,5,type=Creeper,name=Bob] ~ ~5 ~

    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:

    /execute {selector} {x} {y} {z} detect {x} {y} {z} {block} {data} {command}

    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.

    Last edited by kwerti: Jul 25, 2017 Rollback Post to Revision RollBack My resource packs: Argon 32x, Basic Lodef | I18n for your map | ENIM: Custom Entity Models Putting the CENDENT back in transcendent!
  • #2 Jun 27, 2014 steved steved
    • View User Profile
    • View Posts
    • Send Message
    View steved's Profile
    • Zombie Killer
    • Join Date: 10/2/2011
    • Posts: 163
    • Minecraft: steved14000
    • Member Details
    wow, this is pretty awesome :D Rollback Post to Revision RollBack Ultimate Redstone Tutorial Map (currently v0.1a Or ceck out my old mod for 1.4.7 :
  • #3 Aug 9, 2014 camerdude001 camerdude001
    • View User Profile
    • View Posts
    • Send Message
    View camerdude001's Profile
    • Tree Puncher
    • Join Date: 10/8/2012
    • Posts: 37
    • Member Details
    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 :( Rollback Post to Revision RollBack
  • #4 Aug 9, 2014 DerpBoy DerpBoy
    • View User Profile
    • View Posts
    • Send Message
    View DerpBoy's Profile
    • Zombie Killer
    • Location: Nope
    • Join Date: 11/7/2013
    • Posts: 171
    • Location: Seven
    • Minecraft: TheDerpBoy
    • Member Details
    Quote from camerdude001can 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 :(
    For that it would be something like: /execute @e[type=arrow] ~ ~ ~ setblock ~ ~ ~ air 0 replace Rollback Post to Revision RollBack

    If you're reading this, then you're definitely not a sandwich. Sorry, my dear, but I don't give a snickerdoodle. :steve_csi: Spoiler alert!

    I am not a toenail.
  • #5 Aug 10, 2014 camerdude001 camerdude001
    • View User Profile
    • View Posts
    • Send Message
    View camerdude001's Profile
    • Tree Puncher
    • Join Date: 10/8/2012
    • Posts: 37
    • Member Details
    ok thanks it works Rollback Post to Revision RollBack
  • #6 Aug 27, 2014 Marcusher_ Marcusher_
    • View User Profile
    • View Posts
    • Send Message
    View Marcusher_'s Profile
    • Out of the Water
    • Join Date: 9/12/2013
    • Posts: 5
    • Member Details
    Hi! Im making a hide N seek map where I execute command to players with a certain score so i do this kind of command: 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: Last edited by Marcusher_: Aug 27, 2014 Rollback Post to Revision RollBack
  • #7 Aug 27, 2014 kwerti kwerti
    • View User Profile
    • View Posts
    • Send Message
    View kwerti's Profile
    • A Space Odyssey
    • Join Date: 1/18/2013
    • Posts: 2,013
    • Location: Louverdahl
    • Member Details
    First, check that there is in fact a player which fulfills the requirements. Also, numeric IDs no longer exist in NBT data. Use /execute @a[score_bedrock_min=1] ~ ~ ~ summon FallingSand ~ ~ ~ {Time:1,Block:"minecraft:anvil"} Rollback Post to Revision RollBack My resource packs: Argon 32x, Basic Lodef | I18n for your map | ENIM: Custom Entity Models Putting the CENDENT back in transcendent!
  • #8 Sep 4, 2014 spicylevel2washere spicylevel2washere
    • View User Profile
    • View Posts
    • Send Message
    View spicylevel2washere's Profile
    • Tree Puncher
    • Join Date: 1/3/2014
    • Posts: 32
    • Minecraft: spicylevel2
    • Xbox: minergordon
    • Member Details
    could you help me. im trying to experiment and make blocks placed wherever i go, but the command doesent work. /execute @a -1 ~ ~ setblock minecraft:command_block Rollback Post to Revision RollBack

  • #9 Sep 6, 2014 ScorpionGamer880 ScorpionGamer880
    • View User Profile
    • View Posts
    • Send Message
    View ScorpionGamer880's Profile
    • Out of the Water
    • Join Date: 8/28/2014
    • Posts: 9
    • Member Details
    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: execute @p ~ ~ ~ setblock ~ ~ ~ minecraft:torch You also forgot to put a " ~ " before " -1 ". Last edited by ScorpionGamer880: Sep 20, 2014 Rollback Post to Revision RollBack
  • #11 Sep 6, 2014 kwerti kwerti
    • View User Profile
    • View Posts
    • Send Message
    View kwerti's Profile
    • A Space Odyssey
    • Join Date: 1/18/2013
    • Posts: 2,013
    • Location: Louverdahl
    • Member Details
    Quote from Ginodb»Can someone help me out with this command, im not the best at command blocks so ): execute @e[type=Player,SelectedItem:{id:minecraft:feather]}} ~ ~ ~ particle cloud ~ ~ ~ 1 2 1 0 10000 The entity UUID provided is in an invalid format
    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. Rollback Post to Revision RollBack My resource packs: Argon 32x, Basic Lodef | I18n for your map | ENIM: Custom Entity Models Putting the CENDENT back in transcendent!
  • #13 Sep 13, 2014 kwerti kwerti
    • View User Profile
    • View Posts
    • Send Message
    View kwerti's Profile
    • A Space Odyssey
    • Join Date: 1/18/2013
    • Posts: 2,013
    • Location: Louverdahl
    • Member Details
    Quote from David_Thorpe »I tried the execute command to set spawn points. It did not work. TP also did not work, is this correct? my command: execute @a[score_home_min=1] ~ ~ ~ spawnpoint It worked when I substituted the spawnpoint command to: say test
    You need to specify the player and coordinates of the spawn point /execute @a[score_home_min=1] ~ ~ ~ spawnpoint @p ~ ~ ~ Last edited by kwerti: Sep 13, 2014 Rollback Post to Revision RollBack My resource packs: Argon 32x, Basic Lodef | I18n for your map | ENIM: Custom Entity Models Putting the CENDENT back in transcendent!
  • #14 Sep 13, 2014 KaizoBlade KaizoBlade
    • View User Profile
    • View Posts
    • Send Message
    View KaizoBlade's Profile
    • Tree Puncher
    • Join Date: 7/3/2013
    • Posts: 13
    • Minecraft: KaizoBlade
    • Member Details
    Can someone tell me why this doesn't work? /execute @e[type=!Player,type=!Rabbit] ~ ~ ~ /summon LightningBolt ~ ~ ~ It's striking the player even when I don't want it to. Rollback Post to Revision RollBack
  • #15 Sep 13, 2014 kwerti kwerti
    • View User Profile
    • View Posts
    • Send Message
    View kwerti's Profile
    • A Space Odyssey
    • Join Date: 1/18/2013
    • Posts: 2,013
    • Location: Louverdahl
    • Member Details
    Quote from KaizoBlade»Can someone tell me why this doesn't work? /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. Rollback Post to Revision RollBack My resource packs: Argon 32x, Basic Lodef | I18n for your map | ENIM: Custom Entity Models Putting the CENDENT back in transcendent!
  • #16 Sep 17, 2014 ThegameboySP ThegameboySP
    • View User Profile
    • View Posts
    • Send Message
    View ThegameboySP's Profile
    • Tree Puncher
    • Join Date: 11/7/2012
    • Posts: 18
    • Member Details
    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) Rollback Post to Revision RollBack
  • #17 Sep 20, 2014 KaizoBlade KaizoBlade
    • View User Profile
    • View Posts
    • Send Message
    View KaizoBlade's Profile
    • Tree Puncher
    • Join Date: 7/3/2013
    • Posts: 13
    • Minecraft: KaizoBlade
    • Member Details
    Quote from kwerti There can only be one of each parameter.
    Is there a way to make it so I can target multiple targets? Rollback Post to Revision RollBack
  • #18 Sep 21, 2014 kwerti kwerti
    • View User Profile
    • View Posts
    • Send Message
    View kwerti's Profile
    • A Space Odyssey
    • Join Date: 1/18/2013
    • Posts: 2,013
    • Location: Louverdahl
    • Member Details
    Quote from KaizoBlade» 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. Rollback Post to Revision RollBack My resource packs: Argon 32x, Basic Lodef | I18n for your map | ENIM: Custom Entity Models Putting the CENDENT back in transcendent!
  • #19 Sep 21, 2014 stegy17 stegy17
    • View User Profile
    • View Posts
    • Send Message
    View stegy17's Profile
    • Tree Puncher
    • Join Date: 7/7/2014
    • Posts: 30
    • Minecraft: KnightSirCody
    • Member Details
    Quote from Ginodb»Can someone help me out with this command, im not the best at command blocks so ): execute @e[type=Player,SelectedItem:{id:minecraft:feather]}} ~ ~ ~ particle cloud ~ ~ ~ 1 2 1 0 10000 The entity UUID provided is in an invalid format
    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 Rollback Post to Revision RollBack

    https://www.youtube.com/channel/UCdBhYidKks49-AiLxAeCCog

    Redstone, Command blocks, PVP, Archery, Building, and all your other minecraft needs.

    :steve_csi:

  • #20 Oct 5, 2014 Lucario400 Lucario400
    • View User Profile
    • View Posts
    • Send Message
    View Lucario400's Profile
    • Newly Spawned
    • Location: Somewhere
    • Join Date: 10/5/2014
    • Posts: 2
    • Location: In a place
    • Minecraft: Lucario400
    • Xbox: Linkario400
    • Member Details
    my command: /execute @p ~ ~ ~ summon Slime @e[type=Pig, r=7] ~ ~ ~ Not sure whats wrong. Rollback Post to Revision RollBack
  • #21 Oct 5, 2014 kwerti kwerti
    • View User Profile
    • View Posts
    • Send Message
    View kwerti's Profile
    • A Space Odyssey
    • Join Date: 1/18/2013
    • Posts: 2,013
    • Location: Louverdahl
    • Member Details
    Quote from Lucario400»my command: /execute @p ~ ~ ~ summon Slime @e[type=Pig, r=7] ~ ~ ~ Not sure whats wrong.
    The /summon command does not have a player selector. You probably want /execute @e[type=Pig,r=7] ~ ~ ~ summon Slime ~ ~ ~ Rollback Post to Revision RollBack My resource packs: Argon 32x, Basic Lodef | I18n for your map | ENIM: Custom Entity Models Putting the CENDENT back in transcendent!
  • #22 Nov 9, 2014 Alpha_ThePro Alpha_ThePro
    • View User Profile
    • View Posts
    • Send Message
    View Alpha_ThePro's Profile
    • Coal Miner
    • Join Date: 6/13/2012
    • Posts: 138
    • Location: utube: AlphaAnimations
    • Minecraft: Alpha_ThePro
    • Xbox: AlphaFox_13
    • Member Details
    Quote from ThegameboySP»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 Last edited by Alpha_ThePro: Nov 9, 2014 Rollback Post to Revision RollBack

    Be involved in the Survival of Modding in the Post-Notch Era. Enigma + M3L + LiteLoader/API + BlazeLoader {ALL Open-Source!}

  • To post a comment, please login.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 12
  • Next
  • ||
Posts Quoted: Reply Clear All Quotes
  • Home
  • Minecraft Forum
  • Minecraft: Java Edition
  • Redstone Discussion and Mechanisms
  • Commands, Command Blocks and Functions
  • How To Use The /execute Command
Previous Thread Jump to Forum Next Thread

Tag » How To Use Execute As Command In Minecraft