TestForBlock command

TestForBlock command - Unrecognizable woman holding paw of dog

I am trying to make a custom crafting table using a dropper. I use this command to detect a shovel that is placed in the dropper:

testforblock 193 58 -314 minecraft:dropper 0 {Items:[0:{id:minecraft:stone_shovel,Count:1b,Damage:0s,Slot:4b}]}

And it works, it detects the shovel in the middle as it is supposed to. So the shovel is in the middle right now, and the comparator activates. If I keep the shovel there, and put another item into a different slot, the redstone comparator still activates. I want it to only activate when there is 1 item in the table.

My idea is to detect air for the other 8 slots, but it is not working, is minecraft:air invalid? How do I make /testforblock detect air (blank slot) inside the container (dropper)?



Best Answer

"air" is indeed not a valid inventory item. Slots without items will simply not exist whatsoever, so you cannot directly detect them through NBT.

What you'll need to do instead is use multiple /testforblock commands: one to detect the shovel and others to detect slots having any items in them. You'd only allow a signal to pass if the first succeeds while the others fail:

Must succeed:

/testforblock 193 58 -314 minecraft:dropper -1 {Items:[{id:"minecraft:stone_shovel",Count:1b,Damage:0s,Slot:4b}]}

Must all fail:

/testforblock 193 58 -314 minecraft:dropper -1 {Items:[{Slot:0b}]}
/testforblock 193 58 -314 minecraft:dropper -1 {Items:[{Slot:1b}]}
/testforblock 193 58 -314 minecraft:dropper -1 {Items:[{Slot:2b}]}
/testforblock 193 58 -314 minecraft:dropper -1 {Items:[{Slot:3b}]}
/testforblock 193 58 -314 minecraft:dropper -1 {Items:[{Slot:5b}]}
/testforblock 193 58 -314 minecraft:dropper -1 {Items:[{Slot:6b}]}
/testforblock 193 58 -314 minecraft:dropper -1 {Items:[{Slot:7b}]}
/testforblock 193 58 -314 minecraft:dropper -1 {Items:[{Slot:8b}]}

What you cannot do is combine all of the failure commands into one, because then it's looking for an item in every one of those slots rather than any one.




Pictures about "TestForBlock command"

TestForBlock command - Side view of young woman in hoodie sitting on floor near sofa and playing with obedient brown Labrador while resting during free time
TestForBlock command - Crop hacker silhouette typing on computer keyboard while hacking system
TestForBlock command - Full body optimistic young female with curly hair smiling and teaching Beagle dog beg command on sunny summer day in countryside



Quick Answer about "TestForBlock command"

  • x y z is the coordinate to test. ...
  • block is name of the block to test for. ( ...
  • dataValue is optional. ...
  • dataTag is optional.


Is there a command to find blocks?

The blank is for the particular block you are looking for. Let's say you're lost in the Nether and need to find your Nether Portal, you could type : /locateblock obsidian, and get the coordinates for the nearest obsidian, most likely being your, said, Portal.



How To Use '/testfor' \u0026 'testforblock' Command In Minecraft Bedrock | Command Tutorial #24




Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Ivan Babydov, Ivan Babydov, Anete Lusina, Blue Bird