How do I test for Air in Slot 9? with the /execute command?

I've came up with this so far but it doesn't work

/execute if entity @a[nbt={Inventory:[{Slot:8b,id:"minecraft:air"}]}] run give @a minecraft:stick

What did I do wrong?

I'm playing version 1.15

1 Answer 1


The Inventory array only contains slots with items in them. If the slot is empty, it is removed from the array.

You can observe this by running /data get entity @s Inventory. For example, if you had an apple in the first slot of your Hotbar and you run the command, the following output would be displayed.


^ as you can see, only populated slots are displayed.

You can detect an empty slot by testing if it has data. Example:

/execute if data entity @s Inventory[{Slot:0b}]

^ this command will return either 1 or 0 depending on whether or not the specified slot has any data.

Now store the output of this test into a scoreboard objective so you can actually use it:

/execute store result score @s <obj> run execute if data entity @s Inventory[{Slot:0b}]

and finally, you can now do something like /execute if score @s <obj> matches 1 run say item detected!

  • "run execute" is never needed. And you can just tag the player if that data exists. But the general idea is good! Dec 15, 2019 at 3:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .