Minecraft – Detect an Empty Hopper in MC 1.12.2

minecraft-commandsminecraft-java-edition

I'd like to use a command block to detect when the first slot of a hopper has no items in it in 1.12.2 (Or alternatively, if no slots have items in them). I already know how to search for a specific item in the first slot:

/testforblock ~a ~b ~c hopper -1 {Items:[{id:"minecraft:dirt",Count:1b,Slot:0b}]}

I've tried to search for minecraft:air as a way to detect nothing, but this doesn't seem to work. Any help is appreciated! It must be a command block solution (I know that you can detect an empty hopper "manually" by having a comparator output with redstone torch, but in my scenario the hopper and signal destination (command block location) are very far apart)

Best Answer

In Minecraft 1.12.2, you can detect a hopper with no items in it with the command:

/testforblock <x> <y> <z> hopper -1 {Items:[]}

in one command block, followed by a conditional chain command block to do something when this is true.