How to /testfor 10 wheat [duplicate]

How to /testfor 10 wheat [duplicate] - Field of Plants

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?



Best Answer

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.

Prerequisites:

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.
    



Pictures about "How to /testfor 10 wheat [duplicate]"

How to /testfor 10 wheat [duplicate] - Brown Wheat Field
How to /testfor 10 wheat [duplicate] - Free stock photo of agriculture, barley, bread
How to /testfor 10 wheat [duplicate] - Field of Wheat





Starch and Amylase




Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Pixabay, Tymur Khakimov, Tymur Khakimov, Tymur Khakimov