/testforblock

Not to be confused with Commands/testforblocks.
This feature is exclusive to Bedrock Edition and Minecraft Education.
 
BlockSprite rose.png: Sprite image for rose in Minecraft
This page describes content that has been removed from the game.
 
This feature was present in earlier versions of Java Edition, but has since been removed.
/testforblock
Permission level
required
  • 2 ‌
  • 1 ‌
Restrictions

Cheat only

Tests whether a certain block is in a specific location.

Syntax

testforblock <position: x y z> <tileName: Block> [blockStates: block states]

Arguments

position: x y z : CommandPosition

Specifies the coordinates of the block to test.
Must be a three-dimensional coordinates composed of <X>, <Y> and <Z>, each of which must be a single-precision floating-point number or tilde and caret notation.

tileName: Block: enum

Specifies the block to test for.
Must be a block id.

blockStates: block states: BlockStateCommandParam

Specifies the block states to match when testfor.
Must be a blockstate argument as ["<state1>"=<value1>,"<state2>"=<value2>,...]. For example: ["old_leaf_type"="birch","persistent_bit"=true].

Result

CommandTriggerBedrock Edition
AnyThe command is incomplete, or any argument is not specified correctly. Unparseable
The specified position is unloaded or out of the world. Failed
The block at the specified position does not match the specified block id or states.
OtherwiseSuccessful

Output

CommandEditionSituationSuccess Count
AnyBedrock EditionOn fail0
On success1

Examples

  • To test if the block at (0,64,0) is white wool:
    • testforblock 0 64 0 wool
    • testforblock 0 64 0 white_wool
  • To test if the block at (0,64,0) is stone:
    • testforblock 0 64 0 stone []
  • To test if the block below is a jukebox:
    • testforblock ~ ~-1 ~ jukebox

History

Java Edition
1.7.213w37aAdded /testforblock.
1.1116w32aAdded block state support to /testforblock.
1.1317w45aRemoved /testforblock in favor of /execute if.
Pocket Edition Alpha
v0.16.0build 1Added /testforblock.
Bedrock Edition
1.18.0beta 1.18.0.20Added block state support.
1.19.70Preview 1.19.70.21Removed dataValue: int argument.

Navigation