How to kill every armor stand with an empty head slot

I need a command to kill every armor stand that has air in his head.

I tried using /kill @e[type=minecraft:armor_stand,nbt={ArmorItems:[{},{},{},{}]}] and also tried /kill @e[type=minecraft:armor_stand,nbt={ArmorItems:[{},{},{},{id:"minecraft:air"}]}]

I have armor stands with heads you can right click to pick up, but I want them to die after someone click their head.


Solution 1:

Based on the title, here is the answer. Kill any armor stand that doesn't have a player head.

/execute as @e[type=minecraft:armor_stand] unless entity @s[type=minecraft:armor_stand,nbt={ArmorItems:[{id:"minecraft:player_head"}]}] run kill @s

But OP meant "Kill every armor stand that has an empty helmet slot" and here is the solution:

Create a scoreboard:

/scoreboard objectives add ArmorSlots dummy

In command blocks, we will do:

  • Store the armor stand's helmet slot key lenght into a scoreboard
  • Test for 0 length

By doing:

/execute as @e[type=minecraft:armor_stand] store result score @s ArmorSlots run data get entity @e[limit=1,type=minecraft:armor_stand] ArmorItems[3]
/execute as @e[type=minecraft:armor_stand] if score @s ArmorSlots matches 0 run kill @s

Where ArmorItems[x] stands for:

  • x = 0, boots
  • x = 1, legs
  • x = 2, chestplate
  • x = 3, helmet