detecting item with custom name and amount
So I'm wanting to detect a certain amount of a named entity, I have the majority of the command, but I cant figure out how to add the amount. Here's my current command.
/testfor @a {Inventory:[{id:"minecraft:gold_nugget",tag:{display:{Name:"Enchanting Token"}}}]}
You can use testfor
to find players with an exact count in a single slot like so:
testfor @a {Inventory:[{id:"minecraft:gold_nugget",Count:26b,tag:{display:{Name:"Enchanting Token"}}}]}
If you want to detect items across multiple slots, or detect a minimum amount of items, you'll need to use command stats. Create a scoreboard objective numItems
, then use
scoreboard players add @a numItems 0
stats entity @a set AffectedItems @s numItems
clear @a minecraft:gold_nugget -1 0 {display:{Name:"Enchanting Tokens"}}
stats entity @a clear AffectedItems
say Players with at least five Enchanting Tokens: @a[score_numItems_min=5]