Minecraft Blogs

How to use the "detect" in "execute" command (Activate command blocks by standing on a block)

  • 5
  • 7
  • 16
avatar Veritas025
Level 51 : Grandmaster Engineer
33
Basically what you want to start out with is the basic execute command, /execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:diamond_block 0 /effect @a minecraft:strength 30 5 is an example of using detect so basically as long as the command block is running on a clock as soon as you stand on a diamond block you get strength 5 for 30 seconds. or if you want to change -1 to +1 it will test for a diamond block right above you and same for every other coordinate. /execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:iron_block 0 /effect @a minecraft:regeneration 15 2 What this does it detects that if you stand on an ironblock it will give regeneration 2 for 15 seconds.

That is basically just the intro of it you could do so much more. It doesn't have to be a potion effect for example you could run an execute command inside the execute command, for example: /execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:emerald_block 0 /execute @e[type=Creeper] ~ ~ ~ /summon PrimedTnt ~ ~ ~ {Fuse:0} if a player happened to stand on top of an emerald block this time it would summon PrimedTnt at all creepers location and kill them, or do the exact samething except do it /execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:emerald_block 0 /execute @e[type=Zombie] ~ ~ ~ /effect @e[type=Creeper] poison 60 1 instead of summoning primed tnt to creepers it will poison all zombies for a minute.

Another use you could use for this would be land mines. You have to change /execute @a ~ ~ ~ detect ~ ~-1 ~ /execute @e[type=Spider] ~ ~ ~ detect ~ ~-1 ~ minecraft:brick_block /execute @e[type=Spider] ~ ~ ~ /summon PrimedTnt ~ ~ ~ {Fuse:0} So this time if a player steps on a brick block nothing happens at all but if a spider steps on a brick block the spider will blow up. Or you could use the ! mark which means "not" /execute @e[type=Spider] ~ ~ ~ detect ~ ~-1 ~ minecraft:brick_block /execute @e[type=!Player] ~ ~ ~ /summon PrimedTnt ~ ~ ~ {Fuse:0}. This means anything that's not a player will get blown up if they happen to step on the brick block. Including items you drop onto the brick (Press Q).

There are literally so many fun things you could do with this command but a really useful concept is
/execute @e[type=Player] ~ ~ ~ detect ~ ~-1 ~ minecraft:grass /setblock X Y Z minecraft:redstone_block 0 replace This will mean when a grass block is 1 block below them(standing on it) So this can replace the testfor command and the comparators it will save you space and put coordinates of the redstone block to activate command blocks somewhere more distant (Still needs to be in same chunk).

This command basically replaces pressure plates without the pressure plate, but instead of doing ~ ~-1 ~ you can do
~1 ~ ~ or ~ ~ ~1 to detect if the block is on them side of them or ~ ~-2 ~ and see if the block is 2 blocks below them. or if you wanted to get fancy /execute @e[type=Player] ~ ~ ~ detect ~ ~-1 ~ minecraft:diamond_ore /execute @p ~ ~ ~ playsound note.pling @p ~ ~ ~ That will play a noteblock sound if you stand on a diamond. Now to make a diamond detector just make more commandblocks /execute @e[type=Player] ~ ~ ~ detect ~ ~-2 ~ minecraft:diamond_ore /execute @p ~ ~ ~ playsound note.pling @p ~ ~ ~ /execute @e[type=Player] ~ ~ ~ detect ~ ~-3 ~ minecraft:diamond_ore /execute @p ~ ~ ~ playsound note.pling @p ~ ~ ~ /execute @e[type=Player] ~ ~ ~ detect ~ ~-4 ~ minecraft:diamond_ore /execute @p ~ ~ ~ playsound note.pling @p ~ ~ ~ ETC. Eventually you'd get all the way to a really high number so if you were on the surface you were standing right above a diamond you'd hear the sound and and dig straight down to find a vein of diamonds.


I hope this blog helped you because most of the redstoners I know not many people were familiar with this part of the execute command.
Thanks for reading!
Tags

1 Update Logs

Update #1 : 06/23/2016 4:44:56 pmJun 23rd, 2016

Added 2 more paragraphs and fixed some details

1
06/22/2019 4:08 amhistory
Level 6 : Apprentice Miner
rstar23
Great!
And this same command" /execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:iron_block 0 /effect @a minecraft:regeneration 15 2" for version 1.14.1 and put it in a command block and it works? I have tried to make the command block detect a player / entity on top of a block and execute another command (for 1.14.1) but it only works if I execute it but not if it is in the command block. Would someone know how to do it? Thanks in advance.
1
09/03/2017 8:14 pm
Level 1 : New Miner
NinjaStarBlade23
Hi, I'm making a adventure map but I can't seem to figure out how I can a make a command block to something specific for me.

What Im trying to do:
I want the command block to detect when a player walks into a certain X Y Z coordinate. (Such as a 20x20x20 area), Im trying to make it so when any of the 2 players walks in front of a castle, it makes the bad guy of the map speak through command blocks. (Which I already know how to do) but I can't seem how to make command blocks detect it, and send a signal to redstone to play the "dialog". Any help with this would be very grateful. I can't find anything to help with this online, so I came here because you seem to know what your doing with the detect tool. Thanks.
1
09/02/2017 8:46 am
Level 1 : New Miner
ItsLazerBlitz
It helped a lot!!! :D
1
07/28/2017 9:14 am
Level 8 : Apprentice Miner
euanPC
how do you do it so the comand only activates when you are standing on a dispencer with certain blocks in certain areas of the GUI?
1
11/13/2016 4:47 pm
Level 1 : New Explorer
danarox34
thanks!!!!!!!!!!!!!!!!!
1
08/06/2016 11:07 pm
Level 34 : Artisan Nerd
Brodie The Nerd
Is is possible to detect what a player is typing. I am making a map and I want to make it so if they type: "/gamemode 1/0/3" or "/spawnpoint" or "/give" they will die and have to go back to the last checkpoint. Is this possible?
1
04/03/2017 7:52 pm
Level 51 : Grandmaster Engineer
Veritas025
Sorry for the delayed reply. I went inactive for couple years. You probably found your solution or have no need for one anymore, but anyways, you can not detect if a player is typing. However, what you can do is use the Test for command: As follows /testfor @a[m=1]. Sorry I haven't played MC in forever so I don't remember which game mode is which so just change it to your liking. And for your spawn point. Just have a redstone clock keep setting the spawn point to wherever you want them to spawn so even if they type it, the command block just resets it back. As for the "give" that's a little bit trickier. If you are still curious just PM me, and I'll give you somewhat of a fool proof way to set up an anti cheat system for that. It's been 7 months so this might even be pointless writing it now, but sorry for the delay I'll be active more often from now on.
1
07/29/2016 2:04 am
Level 9 : Apprentice Engineer
wessltov
Question: Is it possible to detect a block with a datatag?
1
04/03/2017 7:55 pm
Level 51 : Grandmaster Engineer
Veritas025
Sorry I went active for a couple years. I know it's been 8 months, and probably don't need this answer anymore. But believe me I have tried, and no it is not
1
08/06/2017 5:43 pm
Level 9 : Apprentice Engineer
wessltov
Thanks for at least getting back to me. As you can see, you're not the only one who goes away from time to time
1
05/29/2016 4:37 am
Level 1 : New Miner
LynTS
Thank you very much! I've been looking for this command for a few months! TY!!!!!!!!!!!
1
11/14/2015 12:41 pm
Level 47 : Master Pixel Painter
Sardonyx
Congrats on front page popreel!  :D  This explains it really well, although I already knew how to do this. :P
1
11/14/2015 6:30 pm
Level 47 : Master Pixel Painter
Sardonyx
:) NP
1
11/14/2015 5:31 pm
Level 51 : Grandmaster Engineer
Veritas025
Thank you!
1
11/14/2015 11:51 am
Level 39 : Artisan Pokemon
RandomMelonHere
daho;dncs7edgkefnd THANK YOU THIS HELPED SO MUCH

seriously though you have no idea how much ive been trying to figure this out
1
11/14/2015 5:31 pm
Level 51 : Grandmaster Engineer
Veritas025
Glad I could help!
Planet Minecraft Logo

Website

© 2010 - 2020
www.planetminecraft.com

Welcome