how do I testfor blocks? like if I put down stone near a command block with a comparator attached to it and it will activate a piston connected by the comparator on the command block? please answer.


The command you want is /testforblock. The syntax of it is:

testforblock <x> <y> <z> <TileName> [dataValue] [dataTag]

So to test for a stone block at X=10, Y=64, Z=10, the command would be:

testforblock 10 64 10 stone
  • Could you also test for a block relative for the command block, say, like this: /testforblock ~ ~-1 ~ stone Jun 1 '14 at 3:09
  • @DatEpicCoderGuyWhoPrograms Yep.
    – SirBenet
    Jun 1 '14 at 11:03
  • Note that /testforblock is an upcoming feature and not yet in the latest stable version (1.7.9).
    – L3viathan
    Jun 3 '14 at 14:38

1.13+ Update

/testforblock has been deprecated. New command is /execute if block.

/execute if block 10 64 10 stone

You can now run a success command directly in the same command:

/execute if block 10 64 10 stone run give @p diamond_shovel

You can also use unless to negate the check:

/execute unless block 10 64 10 stone run give @p diamond_shovel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.