2

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"}}}]} 
  • @Awesomedude Answers are not meant to be edited into question regardless of any kind of block – Memor-X Jul 4 '17 at 23:50
1

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]
  • Hey, poster here, another thing that i didn't think of is that this will limit the number scanned, is there anyway to add an or more to the count, like: Count:26>b – CrackedJudgement Jul 5 '17 at 21:40
  • See my second solution, which provides a way to do just that. – AjaxGb Jul 6 '17 at 1:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.