-1

I am stuck looking for a way to test for an item in a player's inventory so far nothing has worked any help would be nice

1
  • Do you mean placing it, seeing if it is there? please clarify, so that help can be better. Commented Nov 23, 2017 at 22:08

2 Answers 2

1

I did not see the pocket edition tag when I gave this answer. This answer will not work for pocket edition. These commands are for Java Edition 1.12.2

Here is a command to check all player's inventories for a diamond:

testfor @a {Inventory:[{id:"minecraft:diamond"}]}

You can change minecraft:diamond to other items/blocks.

If you need to test for a specific amount, you can add count to the command:

testfor @a {Inventory:[{id:"minecraft:diamond",Count:64b}]}

This tests for a full stack of 64.

Those commands will go positive if a player has the item(s) but is not very useful otherwise. You can also add a scoreboard tag to the player who has the item(s). This allows you to target the players that have the item in other commands:

scoreboard players tag @a add Holding {Inventory:[{id:"minecraft:diamond",Count:64b}]}

Then you can use that tag within the target selector of another command. As an example, lets make everyone who has the diamonds say hello:

/execute @a[tag=Holding] ~ ~ ~ say hello
2
  • Thank's for your reply. I have tried this formula. I should have mentioned I'm playing on Minecraft Windows 10. Any help would be grateful.
    – spacrat
    Commented Nov 25, 2017 at 14:58
  • I did not see the pocket edition tag. I apologize. Unfortunately, my knowledge is mainly the Java edition of the game.
    – IronAnvil
    Commented Nov 25, 2017 at 15:52
-1

You could use /invinsee then player name.

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