1

How we use the /testfor command to detect if there's a block missing (or a new block) in an area with only one command block and comparator?

  • Don't use testfor! It's already one if the most useless commands (especially for novice command blockers), and more to the point, it was never designed to do what you're asking. – MBraedley Mar 31 '16 at 13:28
  • Thank you to tell me this, I didn't knew it - still, /testfor command has an utility, right? :) – Kimatuy Mar 31 '16 at 13:50
  • Yes, if you know which situations to use it in. The issue is that when it is the best option, other options, like using the scoreboard, also work, and aren't significantly worse than testfor in that instance. It's often hard to tell if testfor really is the best option, so you might as well stick to the other options. – MBraedley Mar 31 '16 at 13:57
5

If you want to detect blocks, then /testforblocks is what you're looking for. /testfor is used to find entities, such as players, mobs or items. /testforblocks is used as follows:

testforblocks <x1> <y1> <z1> <x2> <y2> <z2> <x> <y> <z> [mode]

from Minecraft Wiki:

Arguments:

x1 y1 z1 and x2 y2 z2:

Specifies two opposing corners of the region to use as the pattern to test for (the "source region"). x1, z1, x2, and z2 must all be between -30,000,000 and 30,000,000 (inclusive, without the commas), and y1 and y2 must be between 0 and 255 (inclusive). May use tilde notation to specify coordinates relative to the command's position. The number of blocks in the source region must not exceed 524,288.

x y z Specifies the lower northwestern corner (the corner with the most-negative values) of the region to be checked (the "destination region"). x and z must both 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 coordinates relative to the command's position. Source and destination regions may overlap.

mode (optional)

Specifies how to match blocks. Must be one of: all — every block in the source and destination regions must match exactly. masked — air blocks in the source region will match any block in the destination region. If not specified, defaults to all.

To use testforblocks, you will need an area on your map to compare against - this will need to be in a loaded chunk, so I would put it underground and out of sight somewhere.

  • I think that we can also put it in the "mother chunk", or if I said wrong it is the chunk where the player spawn. This chunk will always be active, even if the player is far away from it. By doing this, we can make sure that the command will always be run. – Kimatuy Apr 1 '16 at 12:33
  • Sorry about this little detail, but I just tried the command. I don't understand what's the x y z are for because there is already the x1 y2 z3 x2 y2 z2. Thank you for reply. – Kimatuy Apr 6 '16 at 0:12
  • You can answer this question here: gaming.stackexchange.com/questions/261627/… – Kimatuy Apr 6 '16 at 18:13
1

Testfor is a command used to detect entities, which can be a player, a mob, item frame, item, etc. If using testfor you can hook another command block up to it, or use the execute command, which however, does not support data tags.

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.