Minecraft – Why is this command deleting all entities

minecraft-commandsminecraft-java-edition

I'm trying to remove a specific, named, item if it is dropped on the floor. I have the following on my command block:

kill @e[type=Item] {Item:{tag:{display:{Name:"RedFlag"}}}

But it's removing all items, not just the one I want. What am I doing wrong?

I also tried

kill @e[type=Item] {Item:{id:"red_flower",Damage:2}}

But that didn't work either, it's still removing all items, even things that aren't red flowers!

Best Answer

The /kill command does not support killing objects (not yet anyway) who fit through a NBT citeria. Only identifiers with the @e command will be considered.

When you entered:

kill @e[type=Item] {Item:{tag:{display:{Name:"RedFlag"}}}
kill @e[type=Item] {Item:{id:"red_flower",Damage:2}}

It is considered as:

kill @e[type=Item]
kill @e[type=Item]

Regardless of how much NBT data an object has, it'll always kill all the entities of the type specified.


This means that /kill @e[type=Sheep] {CustomName:"Sheep"} will kill all sheep(s) in the world. Even if they have/don't have the custom name "Sheep", or a completely different name altogether.
Think about all the sheeps! (Those loaded in anyway)