We're building a capture the flag style map in Minecraft, but we do not want people to take multiple flags at once.
To stop that, when a player manages to get two flags at once, we want to drop one out of their inventory. This is easily done by a combination of /clear
and /summon
.
The hard part is, how do we detect whether someone is holding two of an item?
We've tried detecting items with the following command:
/execute as @a if entity @s[nbt={Inventory:[{id:"minecraft:chest", Count:2b}]}]
This has the fatal flaw though in that it doesn't detect two stacks of one item. This is an issue because by putting an item temporarily under their cursor, players can deliberately prevent items from stacking.
How do we detect whether a player has two or more of the same item in their inventory using command blocks?