Minecraft Java Edition, Minecraft Commands – How to /testfor No Mobs in an Area in Minecraft

minecraft-commandsminecraft-java-edition

Trying to use command blocks to check if all mobs in an area have been killed.

Tried several commands, apparently my syntax is off, but no where can I find the proper usage.

How do I check to see if all mobs have been killed in a radius?

I've seen some solutions using an inverter, but I'd prefer to use command blocks for space, plus I also wanna learn how to use them.

Commands I've tried:

/testfor @e[type=PigZombie, x=1000, y= 125, z=941, !r=12]
/testfor @e[type=PigZombie, !(x=1000, y= 125, z=941, r=12)]
/testfor !@e[type=PigZombie, x=1000, y= 125, z=941, r=12]

Best Answer

The wiki has an explanation of how to implement each command.

For your command, the example is written like this:

To count the number of zombies within a 20-block radius of (0,64,0): testfor @e[0,64,0,20,type=Zombie]

So your command should look like this:

/testfor @e[x=1000, y= 125, z=941, r=12, type=PigZombie]

Note: the use of the ! ("not") doesn't seem to apply in the syntax for the Minecraft commands, therefore, if you want to invert the command (or atleast invert the use of the command), you'll have to use redstone for that.

Eg. (as from the comments) if you want to do something when it doesn't detect any Pigmen, you'll have to invert the redstone signal that is emitted.