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


1 Answer 1


/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.][1]][1] [![More block samples.][2]][2] [![Two more samples.][3]][3] [![Even more samples!][4]][4] 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][5] on the Minecraft Wiki! [1]: https://i.sstatic.net/8IaxN.png "Fails. The chests face in different directions." [2]: https://i.sstatic.net/RwVel.png "Passes. Every block in each region is the same. Returns 8 because 8 blocks were evaluated (2 × 2 × 2)" [3]: https://i.sstatic.net/XbQlc.png "Fails. The carpet on the left is not present on the right. Although command is set to "masked" mode, only counts for air blocks in the source side (left)." [4]: https://i.sstatic.net/WY8N7.png "Passes. Although the regions don't quite match, the carpet on the right is not evaluated because the same position on the left is air, which is not evaluated in masked mode. Returns 5 because 5 blocks were evaluated (volume of left side - air blocks)" [5]: https://minecraft.wiki/w/Commands/execute

  • thanks for answer i think i understand better now :)
    – user246332
    Commented May 30, 2020 at 14:35

You must log in to answer this question.