Minecraft – Select players with empty inventory slot

minecraft-commandsminecraft-java-edition

Is it possible to testfor players with a specific inventory slot (more specific the 100th/boots slot) if it is empty. I have tried

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

and

/testfor @a {Inventory:[100:{}]}

and

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

but none of them work.

Best Answer

We're going to use the fact that you are checking for boots to our advantage, since boots are not stackable and there can normally only be 0 or 1 item in that slot.

Set up a dummy scoreboard objective called boots and run the following two Commands on a setblock/fill clock.

scoreboard players set @a boots 0
scoreboard players set @a boots 1 {Inventory:[{Slot:100b,Count:1b}]}

For example, you can use a setup like this one.

Full setup

This will set the boots score to 1 for everyone having exactly one item in their foot inventory slots. From there, you can use @a[score_boots=0] to detect barefoot players.

A general answer for every inventory slot is more difficult, because checking for Count:0b does not work, since for the game, "no item" is different from "0 items of any kind".