How to detect 15 to 20 item in minecraft?

In Minecraft, how can I detect five or more item in players inventory? I alraedy know: @p[nbt={Inventory:[{id:"minecraft:cod",Count:5b}]}] But it only works with five item and no more or less.


You can tally how many of an item a player has in their inventory, then use /scoreboard to detect if that tally is more or less than 5.

First, create a dummy objective. This will keep track of how many of a certain item you have in your inventory (in this example, cods)

/scoreboard objectives add cod_count dummy

Next, run this command to match your cod_count score with your item count.

/execute as @p store result score @s cod_count run clear @s cod 0

You can now detect if you have 5 or more cods with this command:

/execute as @p[scores={cod_count=5..}] run tellraw @s "You have more than 5 items"

Detecting a range, like in your title, is just as easy:

/execute as @p[scores={cod_count=15..20}] run tellraw @s "You have between 15 and 20 items"