Commands/testforblock

From Minecraft Wiki
Jump to: navigation, search
testforblock
Restrictions

Operator

First introduced

1.7.2 (13w37a)
PE Alpha 0.16.0 (PE Alpha 0.16.0 build 1)

Tests whether a certain block is in a specific location.

Syntax
  • Java Edition
testforblock <x> <y> <z> <block> [dataValue|state] [dataTag]
  • Pocket Edition
testforblock <position: x y z> <tileName: string> [dataValue: int]
Arguments
x y z (PE: position: x y z)
Specifies the position of the block to test. x and z must be between -30,000,000 and 30,000,000 (inclusive, without the commas) and y must be between 0 and 255 (inclusive). May use tilde notation to specify a position relative to the command's execution.
block (PE: tileName: string)
Specifies the block to test for. Must be a valid block id (for example, minecraft:stone).
dataValue (PE: dataValue: int) (optional)
Specifies the block data to test for. dataValue must be between -1 and 15 (inclusive). If not specified, or if -1, dataValue matches any block data value.
state (optional)[Java Edition only]
Specifies the block state to test for. Must be a valid block state for the block specified in block. If not specified, or if *, state matches any block state.
dataTag (optional)[Java Edition only]
Specifies the block data tags to test for. Must be a compound NBT tag (for example, {CustomName:Fred}). If not specified, dataTag matches any block data tag.
Result
Fails if the arguments are not specified correctly, if the block at the specified position does not match the specified block id or data, or if the specified data tag has different values than are defined in the block's data tag (dataTag does not need to match the block's entire data tag, and data tags in the argument which are undefined in the block will not cause the command to fail).
On success, returns a success count of 1.
Examples
To test if the block at (0,64,0) is any type of wool:
testforblock 0 64 0 minecraft:wool
testforblock 0 64 0 minecraft:wool -1
To test if the block at (0,64,0) is orange wool:
testforblock 0 64 0 minecraft:wool 1
To test if the block below is a jukebox with the "mall" record inside:
testforblock ~ ~-1 ~ minecraft:jukebox -1 {RecordItem:{id:"minecraft:record_mall"}}