Is there a command block command to see if there are any mobs in a player's area?
I would like to have a security system to see if there are mobs in my area. I want to set up a command block with an always-active command which is going to send a signal to another command block if there are any mobs in my area. The other command block will send me a warning. Is it possible to do something like that?
Best Answer
Run the following commands in order, replacing X, Y and Z with the values of the X, Y and Z coordinates respectively. Also replace DX, DY and DZ with the size of the area in the X, Y and Z direction respectively:
/scoreboard players add @e[type=!Player] tell 0
/scoreboard players tag @e[type=!Player] add mob
/scoreboard players tag @e[type=ArmorStand] remove mob
/execute @e[tag=mob,x=X,y=Y,z=Z,dy=DY,dx=DX,dz=DZ,score_tell=0] ~ ~ ~ /tellraw @p ["Mob Detected"]
/scoreboard players set @e[tag=mob,x=X,y=Y,z=Z,dy=DY,dx=DX,dz=DZ,score_tell=0] tell 1
Also replace "Mob Detected" with the text you want to show.
How this works is it executes a tellraw command as every mob inside the specified area and then adds a score to the mob so that it doesn't execute the command again.
Pictures about "Is there a command block command to see if there are any mobs in a player's area?"



How do you detect mobs?
Depending on how your mobs are spawned, you can choose one of the following ways to detect them:How do you check for mobs in Minecraft?
Type the command in the chat window and press the Enter key to run the command. Once the cheat has been entered, the testfor command will check for mooshrooms. You will see the message "Found Mooshroom" appear in the lower left corner of the game window for each mooshroom found within 50 blocks of you.How do you detect if a player is in a certain area?
/moblocation could be a mob locate command. It may seem useless, but /moblocation sheep (color=pink) would help find the nearest pink sheep, or using /moblocation horse (tamed=true) would help you find your pet horse that got lost.Minecraft Commands: /summon Tutorial
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Ivan Babydov, Anete Lusina, Ivan Babydov, Blue Bird
