/execute if blocks works somewhat like a test version of
/clone. The first two sets of coordinates represent the start and end of a rectangular prism for the source area, and the 3rd represents the lower northwest corner of another rectangular prism the same size as the first one. If typing a
/clone command using these coordinates will return a "No blocks cloned" because every block is the same, then the conditional argument returns a YES.
Even NBT data has to match for the conditional to count! This means you can test if a chest's contents matches the contents of a template chest by using:
/execute if blocks [templateX] [templateY] [templateZ] [templateX] [templateY] [templateZ] [testX] [testY] [testZ]
The all/masked option represents whether to ignore air blocks in the source region. If set to
all, all air blocks in the source region have to be air blocks in the destination region.
If set to
masked, air blocks in the source region are ignored in the destination, and can be anything and will still count.
If test passes, the command will return a number equal to the number of blocks evaluated. This includes the total volume of the source region, minus air blocks if set to
If test fails, returns 0.
Anything but 0 will mean your command at
run will be executed, and if your conditional returns 0 the command won't execute.
Here are some examples. The source is on the left, the test is right, I am facing north. The command used is shown on screen in the chat box, as well as the result from it in the chat. Additionally, the images' hover texts contain additional explanation to the results you see.
In order to detect if all blocks in a certain area are a certain block ID, you don't give the command a block ID directly, you give it a template area to compare with the area to test for.
In this case, to solve the problem detailed in your question, you can use
/execute if blocks, just make the following modifications:
- Create a template area filled with air, which is the same size as the area you want to detect.
- For the first set of coordinates of
/execute if blocks, choose one corner of this template area.
- For the second set of coordinates, use the coordinates of the opposite corner of this template area.
- For the third set of coordinates, head to the area you want to detect. Go to the lower northwest corner of it and use those coordinates.
Learn more about
/execute on the Minecraft Wiki!