4

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.

2 Answers 2

5

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .