Test If Two Block Regions Match
The /testforblocks command checks whether the blocks in one rectangular area match the blocks in another area. You define a source region using two opposite corners and then pick a destination point to compare it against.
Map makers and builders often use this command with command blocks to create block-based puzzles, secret doors, or structure checks. You can choose to compare every single block including air, or ignore air blocks in your source region so only solid shapes are tested.
/testforblocks <begin: x y z> <end: x y z> <destination: x y z> [mode: TestForBlocksMode]Test for blocks
| Argument | Type | What it means |
|---|---|---|
begin: x y z | position | The X, Y, and Z coordinates of the first corner of the rectangular source region you want to compare. |
destination: x y z | position | The X, Y, and Z coordinates of the lower northwest corner of the target area you are testing against. |
end: x y z | position | The X, Y, and Z coordinates of the opposite corner of the rectangular source region. |
mode | TestForBlocksMode | An optional setting that can be set to 'all' to match every block including air (the default), or 'masked' so air blocks in the source region match any block in the destination. |
/testforblocks 10 64 10 15 68 15 30 64 30Checks if the blocks in the region from (10, 64, 10) to (15, 68, 15) exactly match the region starting at (30, 64, 30) using the default mode.
/testforblocks 100 70 200 104 74 204 120 70 200 allExplicitly sets the mode to 'all' to verify that a 5x5x5 cube at (100, 70, 200) is identical, including air blocks, to the area at (120, 70, 200).
/testforblocks -25 50 -25 -20 55 -20 -50 50 -50 maskedUses 'masked' mode to check if the non-air blocks between (-25, 50, -25) and (-20, 55, -20) match the area at (-50, 50, -50), ignoring any air blocks in the source.
/testforblocks ~1 ~ ~1 ~3 ~2 ~3 ~10 ~ ~10Uses relative coordinates to compare a small region right next to the player or command block with another region 10 blocks away.
/testforblocks ~-5 ~-1 ~-5 ~5 ~-1 ~5 0 60 0 allChecks if the flat floor pattern directly underneath the command executor matches the template stored at (0, 60, 0).
/testforblocks 250 80 -100 250 85 -100 ~ ~1 ~ maskedCompares a vertical column of blocks at (250, 80, -100) to the blocks directly above the executor while ignoring air blocks.
Minecraft Java Edition does not have the /testforblocks command, as this command is exclusive to Bedrock Edition.
The all mode checks that every single block matches, including air blocks, while the masked mode allows air blocks in your first region to match any block at all in the destination region.
You must always use the lower northwest corner of the target area, which is the corner with the smallest X, Y, and Z coordinate numbers.
You need the Game Directors permission level and cheats must be enabled in the world to run this command.
/dialogue/execute/function/packstack/reload/reloadpacketlimitconfig/schedule/scoreboard/scriptevent/sendshowstoreoffer/tag/testfor/testforblock/toggledownfall