Advertisement
Not to be confused with Commands/testforblocks.
This feature is exclusive to Bedrock Edition and Education Edition. 
This page describes content that exists only in outdated versions of Java Edition. 
This feature used to be in the game but has since been removed.
testforblock
Permission level
required

1

Restrictions

Cheat only

Tests whether a certain block is in a specific location.

Syntax

testforblock <position: x y z> <tileName: Block> [dataValue: int]

Arguments

position: x y z : CommandPosition

Specifies the coordinates of the block to test.
It must be a three-dimensional coordinates composed of <x>, <y> and <z>, each of which must be a floating-point number or tilde and caret notation.

tileName: Block: Block

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

BE: dataValue: int: int

Specifies the block data to match when testfor. Values (bitwise AND 0xFFFF) that are invalid for the specified block id revert to 0. If it is negative, all blocks that match tileName: Block are tested.
Must be a 32-bit integer number.

Result

CommandTriggerBedrock Edition
anythe arguments are not specified correctly Failed
the specified position is unloaded or out of the world
the block at the specified position does not match the specified block id or data
anyOn successRetruns the success message.

Output

CommandEditionSituationSuccess Count
anyBedrock EditionOn fail0
On success1

Examples

  • To test if the block at (0,64,0) is any type of wool:
    • testforblock 0 64 0 wool
    • testforblock 0 64 0 wool -1
  • To test if the block at (0,64,0) is orange wool:
    • testforblock 0 64 0 wool 1
  • To test if the block below is a jukebox:
    • testforblock ~ ~-1 ~ jukebox -1

History

Java Edition
1.7.213w37aAdded /testforblock.
1.1116w32aAdded block state support to /testforblock.
1.1317w45aRemoved /testforblock in favour of /execute if.
Pocket Edition Alpha
v0.16.0build 1Added /testforblock.
Community content is available under CC BY-NC-SA 3.0 unless otherwise noted.