Minecraft command to clear all but one item entity (tile) type
I've got a capture the flag arena. One issue we keep running into during play, is that of clutter.
We have /gamerule keepInventory false, so the pitch gets rather cluttered with armor, weapons and building materials, such that it becomes difficult to pick the flag up, due to full inventories.
I've discovered the following command to remove all drops from the arena:
/kill @e[type=Item]
However, this removes all the floating items from the ground. I'd like, if possible, to preserve the flag from being destroyed.
I have this command for detecting the flag:
/testfor @e[type=Item,x=40,y=1,z=40,dx=40,dy=27,dz=80] {Item:{id:"minecraft:banner",Damage:4s}}
But I'm not sure how to combine the two in a way that it will destroy everything except for the flag.
Any ideas?
Best Answer
Starting with Minecraft 1.9, you can use a scoreboard tag to mark the flag rather than a dummy objective as outlined in colorfusion's answer.
/scoreboard players tag @e[type=Item,tag=!isFlag] add isFlag {Item:{id:"minecraft:banner",Damage:4s}}
/kill @e[type=Item,tag=!isFlag]
This has three benefits:
- You don't need to set up an objective.
- Note how there is no command to tag every item. This is because tags are initialized as an empty list by default, meaning
tag=!isFlagworks on entities by default. This is unlike scoreboard objectives, which are initialized to Null/None, which fails all comparisons with numbers (for the purpose of target selector arguments), e.g.(Null>=0)==False,(Null<0)==False. - As a result of 2, we can make it so every flag is only tagged once, rather than once per tick.
Pictures about "Minecraft command to clear all but one item entity (tile) type"



How do you clear one type of entity in Minecraft?
The \u201c /kill \u201d command can be used to remove any entity from the game, including players, mobs, drops, and other items, useful or not. It can be extremely selective when you want it to be, allowing you to remove a single mob at a time by typing its unique identifier (UUID) as the command parameter.How do you clear specific items in Minecraft with commands?
You can clear items from a player's inventory using the /clear command in Minecraft.Can you clear specific items in Minecraft?
The kill command or \u201c/kill @e[type=item]\u201d can remove all the dropped items in the Minecraft world instantly. You'll need operator status and cheats to be enabled to use the kill command. If you want to clear all the dropped items within a specific radius, use the \u201c/kill @e[type=item, r=x]\u201d command.How do you clear tiles in Minecraft?
Minecraft: Using the fill command to clear chunks To do this, players can either use the F3 key on Minecraft: Java Edition or the "show coordinates" option in Bedrock Edition to note the start and end points of where they want the fill command to clear.Kill Command Explained
More answers regarding minecraft command to clear all but one item entity (tile) type
Answer 2
Try:
/kill @e[type=Item,name=!Flag]
Alternatively, you can have it check for the dropped flag (remove the !) and then send the result through a NOT gate to a command block that runs:
/kill @e[type=Item]
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Skylar Kang, Max Vakhtbovych, Egor Kamelev, Brett Sayles
