1.15 - How to test for "air" in Hotbar - /execute Command

Solution 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.

[{Slot:0b,id:"minecraft:apple",Count:1b}]

^ 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!