I used this command:

/testfor @p[score_Room1_min=2,score_Room1=2] {Inventory[{id:minecraft:dye,Damage:1s,tag:{display:{Name:"Body part"}},Count:10b}]}

It all works, but only when I have 10 body parts.

How can I test for at least 10, for example 11 or 12 without needing to make new command blocks?


/testfor also does not have multi-target support. It just tells you there was a match, but not who that match was, and therefore you cannot target that player afterwards.

Even further, if there were multiple players with a "Room1" score of 2 and because you're only targeting the closest one of those, only that player will have their NBT data checked. The selector is processed before the NBT data, so if that player did not match, the command fails (even if the further player could've matched).

Checking NBT data requires you to specify exact values. For a range, you must use CommandStats to store the number of items the player has as a score, which is multi-target friendly. This also has the benefit of not requiring those items to be in the same stack.


Objective to hold return value from CommandStats.

/scoreboard objectives add ItemCount dummy

Trigger to apply to players. The player will target their own "ItemCount" score when they run a command that returns an "AffectedItems" value (in this case, it'll be /clear). If new players can join at any time, you may need to run this on a clock.

/stats entity @a set AffectedItems @a[c=1] ItemCount

In order for CommandStats to modify its target's score, that target must be tracked on the scoreboard prior. This may also need to run on a clock.

/scoreboard players add @a ItemCount 0


Now when a player runs /clear, their "ItemCount" score will be set equal to the number of items cleared. If you set the maximum amount to 0, then the return value is the total number of those items in the player's inventory.

/execute @a ~ ~ ~ /clear @a[c=1] minecraft:dye 1 0 {display:{Name:"Body part"}}

And you can then target players based on their "ItemCount" score.

/say @a[score_Room1_min=2,score_Room1=2,score_ItemCount_min=10] has 10+ items.
| improve this answer | |
  • Thanks, but I can's really figure out what does the stats command do. And I don't want the items to dissapear, I want the player to get poisoned when he has 10+ body parts – Super Dirt May 7 '16 at 8:04
  • @SuperDirt CommandStats are a huge beast and is not simple to explain, but the mechanism will work regardless. I have a long guide here if you need an explanation. As well, setting the maximum amount to 0 in /clear prevents items from being removed. It will not remove items. – Skylinerw May 7 '16 at 11:27

Ill just get into to it:

First of all do this:

/scoreboard objective add BodyParts dummy

To give the item:

/give @p dye 1 1 {UnCounted:1b,{display:{Name:"Body part"}}

then have a command block doing this: (Repeating Command Block/Command Block on a clock)

/clear @p[score_Room1_min=2,score_Room1=2] dye 1 1 {UnCounted:1b}

then have a command block doing this: (Chain Commmand Block on Conditional/Comperator to another command block)

/scoreboard players add @p[score_Room1_min=2,score_Room1=2] BodyParts 1

then last command block on Chain Conditional again or Comperator to command block again:

/give @p[score_Room1_min=2,score_Room1=2] dye 1 1 {display:{Name:"Body part"}

Now that should add one to the BodyParts scoreboard and quickly replace the item held by the person.

Side Notes:

  • This will only work if 1 person has the score Room1 of 2 if you want me to optimize it for multiplayer please comment.
  • If in 1.9 all the repeat and chain command blocks must be always active
| improve this answer | |

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