I'm trying to have players unlock a door by finding 5 key fragments. I already have a command block that will open the door when the player's objective reaches 5 but I'm having trouble figuring out how to make an objective match the amount of items in their inventory. I looked around online and found a few commands to base mine off of but they don't seem to work. This is what I have so far with a repeating command block: scoreboard players add @a TempKEnt 1 {Inventory:[{id:"minecraft:prismarine_shard",Count:1b}]} But the output says "The dataTag does not match for (ign). I'm running on 1.12.1, any help is appreciated!

1 Answer 1


The solution is to use command stats and clear with a count of 0. This will clear 0 items, but it will set a command stat with the total number of matching items in the inventory, cleared or not.

The commands are as follows:

# Tell all players to store the AffectedItems stat of any commands
# they run in their own TempKEnt objective.
stats entity @a set AffectedItems @s TempKEnt

# Make sure all players have a score in TempKEnt, since /stats can
# only update scoreboard values, not create them.
scoreboard players add @a TempKEnt 0

# Have all players run the clear command to get the item count.
execute @a ~ ~ ~ clear @s minecraft:prismarine_shard -1 0

# Tell all players to stop storing their AffectedItems stat.
stats entity @a clear AffectedItems

In 1.13, this will be much simpler:

# Does not work in 1.12!
execute as @a store result score @s TempKEnt run clear @s minecraft:prismarine_shard 0

You must log in to answer this question.

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