How would one testfor a block placed?

Solution 1:

There are a few ways to detect a certain block in an area:

If you just want to detect whether or not a certain block is inside an area and if you don't mind having the block destroyed, you can use this command:

/execute @a ~ ~ ~ fill ~-10 ~-10 ~-10 ~10 ~10 ~10 air 0 replace wool 14

You can detect the block placed using a comparator or a conditional chain command block.

If you, however, want to know where the block is placed and or keep the block, you can use this more complex approach.

/execute @a ~ ~ ~ fill ~-8 ~-8 ~-8 ~8 ~8 ~8 structure_void 0 keep

#Repeat this section for how many types of blocks you want to test for
/execute @a ~ ~ ~ fill ~-8 ~-8 ~-8 ~8 ~8 ~8 air 0 replace wool 11
/execute @a ~ ~ ~ fill ~-8 ~-8 ~-8 ~8 ~8 ~8 command_block 0 keep {auto:1,Command:"summon armor_stand ~ ~ ~ {Invisible:1,NoGravity:1,Marker:1,Tags:["wool11"]}"}

/execute @a ~ ~ ~ fill ~-8 ~-8 ~-8 ~8 ~8 ~8 air 0 replace wool 14
/execute @a ~ ~ ~ fill ~-8 ~-8 ~-8 ~8 ~8 ~8 command_block 0 keep {auto:1,Command:"summon armor_stand ~ ~ ~ {Invisible:1,NoGravity:1,Marker:1,Tags:["wool14"]}"}

...

/execute @a ~ ~ ~ fill ~-8 ~-8 ~-8 ~8 ~8 ~8 air 0 replace structure_void
/blockdata ~2 ~ ~ {auto:1}
/blockdata ~1 ~ ~ {auto:0}
[Impulse] /execute @a ~ ~ ~ fill ~-10 ~-10 ~-10 ~10 ~10 ~10 air replace command_block
/execute @e[type=armor_stand,tag=wool11] ~ ~ ~ say You placed blue wool!
/execute @e[type=armor_stand,tag=wool14] ~ ~ ~ say You placed red wool!

Solution 2:

We will be referring to three areas in this answer: A, B, and C, and using wool for this testing function:

  • A: The volume you are testing. (0, 0, 0) to (9, 9, 9)
  • B: A utility volume of the same size that will have blocks cloned into it. (10, 10, 10) to (19, 19, 19)
  • C: A volume filled entirely of a block you do not want to test for. My suggestion is barriers or structure voids (this example uses the latter) (20, 20, 20) to (29, 29, 29)

When you want to activate the test function, /fill area B with structure voids:

fill 10 10 10 19 19 19 minecraft:structure_void

Next, /clone the volume tested with filtering set to the block type you want to test for:

clone 0 0 0 9 9 9 10 10 10 filtered minecraft:red_wool

Then perform /execute if blocks with areas C and B, attempting to clone area C to area B.

execute if blocks 20 20 20 29 29 29 10 10 10 all

That command will pass if the blocks match, which means that no wool was there. It will fail if the blocks did not match, indicating that wool was not there.