I am trying to /testfor 10 wheat anywhere in the players inventory.

I have tried this command:

testfor @a {SelectedItemSlot:0,Inventory:[{Count:10b­,id:minecraft:wheat}]}

But it gives me this same error all the time:

The entity UUID provided is in an invalid format

How can I do this?


The entity UUID provided is in an invalid format

That error is for the target selector, which usually occurs when no target was found (and is unrelated to the remainder of the command). Ensure there are targets available first or that there are no typos in your selector.

Using direct NBT detection will not reliably allow you to count the number of items. If you look specifically for a Count of 10, you'll only find wheat in an exact stack of 10 in a single slot, rather than 10 wheat spread across the inventory in any number of slots.

To accomplish that, you'll need to use CommandStats, which sets a score related to the success of a command. The AffectedItems trigger will set a score based on the number of items found.


Objective to hold the value.

/scoreboard objectives add ItemCount dummy

The AffectedItems trigger to apply to the player. This may need to run on a clock if new players can join at any time. The players will set their own "ItemCount" score based on the success of a command relevant to AffectedItems (such as /give, /clear, and /replaceitem).

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

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

/scoreboard players add @a ItemCount 0

Clock commands:

The following must be run in numerical order on a clock.

  1. Cause all players to clear 0 wheat in their inventory. While this does not remove any wheat, the command will return an AffectedItems value equal to the number of items that could have been cleared.

    /execute @a ~ ~ ~ clear @a[c=1] minecraft:wheat -1 0
  2. Players will then have their "ItemCount" score set equal to the number of wheat all across their inventory, regardless if they're not in the same stack. You can then target players based on their score, which also allows for a range of values (which is otherwise not possible with direct NBT detection).

    /say @a[score_ItemCount_min=10] has 10 wheat.
  • QueryResult also works, AFAIK. – MBraedley Dec 20 '15 at 18:57
  • @MBraedley It does not. QueryResult only returns a value for very specific commands, being /gamerule <gamerule>, /list, /scoreboard players list, /scoreboard players list <player>, /scoreboard teams list, /scoreboard teams list <team>, /time query <daytime|gametime|day>, /worldborder get, and /xp <0|0L> <player>. – Skylinerw Dec 20 '15 at 19:01
  • Oh, you're running the stats on the players, not on the command block like I've done previously. That makes sense, then. – MBraedley Dec 20 '15 at 19:16
  • @MBraedley Well, even setting on a block instead of player would still require the use of AffectedItems, since the type of executor does not change the function of the triggers. Using /stats on players for cases like this is to allow multiplayer support, as otherwise only the last target obtained by a command block would affect the resulting score (for example, if 19 out of 20 players has 10+ wheat, but the last player targeted does not, the resulting AffectedItems will be misrepresented and assumed that no players at all have 10+ wheat, which can be detrimental if relying on the value). – Skylinerw Dec 20 '15 at 20:03
  • So take a look at how I did it in the linked answer. I know it works fine in single player, but now you're making me wonder if it works for multiplayer. – MBraedley Dec 22 '15 at 14:21

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