Minecraft /testfor
My question is simple, How do I test for at least 2 items in an inventory.
I don't want to test for exactly 2, I want at least two, so they have the ability to have more in their inventory and still get the result.
I have made this code but it doesn't work, it doesn't even give me an error:
testfor @a[score_craft_min=1] {Inventory:[{id:"minecraft:stick",Count:>1b}]}
Best Answer
You can use CommandStats to obtain the number of items in the inventory as a scoreboard value, without being restricted to a single slot.
Prerequisites:
Objectives to hold the value.
/scoreboard objectives add StickCount dummy
/scoreboard objectives add IronCount dummy
In order for CommandStats to modify a score, the target must be tracked prior. This may need to run on a clock in the event new players can join at any time.
/scoreboard players add @a StickCount 0
/scoreboard players add @a IronCount 0
Detection:
The following must be run in numerical order on a clock.
Apply the necessary AffectedItems trigger such that the player modifies their
StickCountscore./stats entity @a set AffectedItems @a[c=1] StickCountCause players to run a /clear command, targeting themselves. While it does not remove any item, this causes their
StickCountscore to be set equal to the items that could have been cleared, which is equal to the number of sticks they had./execute @a ~ ~ ~ clear @a[c=1] minecraft:stick 0 0For other items, you repeat #1 and #2.
/stats entity @a set AffectedItems @a[c=1] IronCount /execute @a ~ ~ ~ clear @a[c=1] minecraft:iron_ingot 0 0You can then run commands targeting players based on their score. For example, the following says the name of players who had 2 or more sticks and iron ingots anywhere in their inventory (including spread across 2 separate stacks).
/say @a[score_StickCount_min=2,score_IronCount_min=2] had 2 or more sticks & iron ingots.
Pictures about "Minecraft /testfor"

How do you use Testfor in Minecraft?
How to Enter the CommandWhat happened to Testfor Minecraft?
The /testfor command became obsolete in Minecraft 1.13, and has been replaced by the /execute command*. It will do the same as typing /testfor @e {SelectedItem:{id:"<item>"}} and then putting a comparator to the command block with the command, and then running the command which you wanna run.Is there a detect command in Minecraft?
detectPos is the x y z coordinate to detect the block. command is any Minecraft command that you want the entity to execute such as summon, give, fill, clone, setblock, tp, xp, kill, etc.Minecraft Redstone Tutorial | How to use testfor commands in MCPE!
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Pixabay, Kaboompics .com
