I am designing a minigame where players have to kill all the animals summoned in with tag "summoned". I know that if I want to check if they are still alive I can do:

testfor @e[tag=summoned]

But the command:

testfor @e[tag=!summoned]

Simply finds entities that don't have the tag. My old solution was a comparator coming out of the first command, facing into a block with a torch on the other side, but I want a more elegant solution preferably using chain command blocks. Any ideas?


2 Answers 2


Here is one solution that works, but I am not sure I would use elegant to describe it. It involves creating a scoreboard objective to create an inversion. First the score is set to 1 for a fake player and then an execute command resets the score. If no tagged entities exist, the score does not get reset. Then you can test for the score.

Create a dummy objective:

/scoreboard objectives add Invert dummy

Create a Repeat Unconditional Always Active command block with command:

scoreboard players set FakePlayer Invert 1

Follow with a Chain Unconditional Always Active command block with command:

execute @e[tag=summoned] ~ ~ ~ scoreboard players reset FakePlayer Invert

Create another Repeat Unconditional Always Active command block with command:

scoreboard players test FakePlayer Invert 1

Follow that with a Chain Conditional Always Active command block. This block is used to run whatever commands you want after the entities have all been killed. Note: this command will run repeatedly unless you stop the system.

Also, if you don't mind having an extra armor stand to store data as part of your system, you could use a scoreboard tag instead of adding an objective.

  • Would the final command blocks not be "Chain" "Conditional" "Always active"? As they rely on the condition that FakePlayer has a score of 1 for objective Invert? If it's "Unconditional", wont it just execute regardless of the output of the score test?
    – Xav
    Jun 28, 2018 at 16:49
  • You are correct in your understanding. I must have been typing too fast. I edited the answer to fix that.
    – IronAnvil
    Jun 29, 2018 at 3:42

It might be best to add 1 to the scoreboard each time a summon happens and then use a hidden 'utility' advancement to subtract from the score when the animals are killed - advancements have built in 'player-killed-type' features for ease of development.

the utility advancement function would need to revoke itself after being called so that multiple kills can be counted down.

one problem you might encounter assuming the entities have persistence is that execute could fail if the animals are far enough away from the player that they get unloaded - execute wont find them even though they haven't died.

A summon counter gets away from this problem by mimicking the animals persistence. Advancements would also be very useful for multiplayer as they would help with the player tracking.

It might help to elaborate on how the mini-game should play out. Are you trying to track animal deaths, or player kill-counts or living animals. You might get different results on these metrics depending on if a zombie killed it or it drowned, fell, or despawned.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .