-2

So I'm working on a project and I need help with a testfor command. So is there anyway of Testing a inventory slot etc slot 20 in the inventory. And let me clerify that I don't want to testfor the item I'm holding in or the hotbars. And can you do this with scoreboard?

  • 1
    Have you made any attempt to solve this yourself? Arqade works better when askers show effort to solve their own problems; we see that you have a problem you've worked on, and answerers respond to that. You also get a more specific answer that's tailored exactly to the part you're stuck, and Arqade gets a very specific question. Everybody wins! – Frank Jan 27 '18 at 23:41
  • You can't test slots. The slots are always there. What would you expect as the result? – Fabian Röling Jan 28 '18 at 8:38
1

This is done by using the dataTag portion of the testfor command. The tag information to be tested can be found in the wiki on player data. In this case you are searching in Inventory for Slot information.

Here is the command:

/testfor @a {Inventory:[{Slot:20b}]}

This simply tests for the existence of Slot 20 which would mean there is any item stored in that slot.

This command tests slot 20 for stone:

/testfor @a {Inventory:[{Slot:20b,id:"minecraft:stone"}]}

On the same wiki page for player data is an image which contains all the slot numbers.

Here is a similar image I had created for 1.12.2: Slot numbers


Update after question edit. This can be done with scoreboard objectives and scoreboard tags. This will use the same tag information as used in the testfor commands.

To set an objective score to 1:

scoreboard players set @a <objective> 1 {Inventory:[{Slot:20b}]}

To add a tag use the command:

scoreboard players tag @a add <tagName> {Inventory:[{Slot:20b}]}

Generally, you want these commands in a chain command block after a repeat command block which sets the score to 0 or removes the tag. This way if the player then removes the item from the slot, they will no longer be targeted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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