How does /execute if blocks work?

I'm building an custom map and i want to detect if all block in a X large area is air blocks... i have tried to use this command: execute if blocks ~1 ~ ~1 ~8 ~5 ~8 16 100 -263 all run ... but it doesn't work.

I think it is like this: The first two XYZ (coordinates) is to mark an specific area and then the last XYZ is what block all blocks in that area should be! For example if the block at the specific xyz is an air block all blocks in the area I marked need to be exact that block... but it feels so weird why cant you just type what block you want it to be for example why can't I just type minecraft:air instead?

I also have no idea what the the last option means( all<>masked).

I'm playing version 1.16 (snapshot 20w22a)!


/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 masked mode.
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. Two samples of blocks. More block samples. Two more samples. Even more samples! 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:

  1. Create a template area filled with air, which is the same size as the area you want to detect.
  2. For the first set of coordinates of /execute if blocks, choose one corner of this template area.
  3. For the second set of coordinates, use the coordinates of the opposite corner of this template area.
  4. 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!