I created a level-based minigame, and every level, it checks your inventory, and makes sure you don't have any forbidden items. I make items forbidden my adding a tag to them: discard:1b. Any items that should get removed from the inventory at the end of each level get this tag, so they are discarded.

I then started working on the clear command, and I found that you cannot remove items based upon NBT, but rather only by item, although you can add an NBT specification to items afterwards.

I then saw this answer, and got excited, but then I realized it used datapacks, and that would not be an option for me.
I looked around a bit more, and discovered this, who had a very similar problem to me, but its only answer was something I already knew how to do, and it wasn't enough.

  • It's great to hear that you've searched our site to see if your question has already been asked. I'm the user that originally wrote the first post that you linked here, and I have to ask, why can't you use data packs? They're becoming more and more standard these days for developing code in Minecraft.
    – One 2 Many
    Commented Jan 31, 2021 at 19:00

1 Answer 1


You can do this using /replaceitem and a technique similar to the one described in Fabian Röling's answer to this related question:

/execute if entity @s[nbt={Inventory:[{Slot:0b,tag:{discard:1b}}]}] run replaceitem entity @s hotbar.0 air
/execute if entity @s[nbt={Inventory:[{Slot:8b,tag:{discard:1b}}]}] run replaceitem entity @s hotbar.8 air
/execute if entity @s[nbt={Inventory:[{Slot:9b,tag:{discard:1b}}]}] run replaceitem entity @s inventory.0 air
/execute if entity @s[nbt={Inventory:[{Slot:35b,tag:{discard:1b}}]}] run replaceitem entity @s inventory.26 air
/execute if entity @s[nbt={Inventory:[{Slot:-106b,tag:{discard:1b}}]}] run replaceitem entity @s weapon.offhand air
  • (This is directly copied from my deleted answer to the first linked question, which turned out to not be applicable there, but seems to be applicable here)
    – pppery
    Commented Jan 31, 2021 at 20:22
  • The commands here will require some tweaking for the Minecraft 1.20.5 update, but the concept should still be valid.
    – pppery
    Commented Apr 26 at 2:13

You must log in to answer this question.

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