Minecraft-Java-Edition-Commands – How to Detect a Mob That No Longer Has a Passenger

minecraft-commandsminecraft-java-edition

On Minecraft 1.12, I'm making a thing for a boss fight, and it has baby zombies riding chickens. You can kill the zombies and they will die but the chicken won't. How should I detect the chicken no longer having a passenger?

Best Answer

Sadly you can't just test for an empty list of passengers, because the game removes the Passengers tag when the zombie is killed instead of just emptying it.
But you can detect all chickens and you can detect all chickens with passengers, so you can do something like this:

/scoreboard players tag @e[type=chicken] add noPassenger
/scoreboard players tag @e[type=chicken] remove noPassenger {Passengers:[{id:"minecraft:zombie"}]}

This first adds the tag noPassenger to all chickens and then removes it from every chicken that is ridden by a zombie. You can later select all tagged chickens with @e[tag=noPassenger].