Is there a command block command to see if there are any mobs in a player's area?

Is there a command block command to see if there are any mobs in a player's area? - Unrecognizable woman holding paw of dog

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?"

Is there a command block command to see if there are any mobs in a player's area? - Crop hacker silhouette typing on computer keyboard while hacking system
Is there a command block command to see if there are any mobs in a player's area? - Side view of young woman in hoodie sitting on floor near sofa and playing with obedient brown Labrador while resting during free time
Is there a command block command to see if there are any mobs in a player's area? - Full body optimistic young female with curly hair smiling and teaching Beagle dog beg command on sunny summer day in countryside



How do you detect mobs?

Depending on how your mobs are spawned, you can choose one of the following ways to detect them:
  • Tags: If your mobs are spawned with commands, you can tag them with a recognizable tag to detect later. You can spawn them with the following command: summon wither_skeleton ~ ~ ~ {Tags:["floor1"]} ...
  • Rectangular prismic box:


  • 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