You cannot use the "~" character in selectors, meaning you'd need to rely on command syntax and not selector syntax. You cannot use relative coordinates with /testfor
as its command syntax does not support it.
You would instead need to place an entity at the desired position and execute from it relatively using /execute
:
/execute <target> X Y Z <command>
"target" is the target entity to change the coordinate origin to, while XYZ is going to further modify the origin. Using relative coordinates would cause "command" to be executed relative from the target's position.
Sample armor stand to create:
/summon ArmorStand X Y Z {Tags:["anchor"]}
For example, assuming there is an armor stand tagged with "anchor" at the intended location, the following tests for players relative to the armor stand:
/execute @e[type=ArmorStand,tag=anchor] ~1 ~4 ~-3 /testfor @a[dx=0,dz=0,dy=102]
/execute @e[type=ArmorStand,tag=anchor] ~1 ~4 ~3 /testfor @a[dx=0,dz=0,dy=102]
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!
Best Answer
/testfor
is for entities only. If you want to check a block instead, use/testforblock
.It looks like you've copied the coordinates from your exact feet position. These may not end up rounding correctly to a block position; I'd recommend using the
Looking At
values instead:The following command will test for a heavy weighted pressure plate at
(-88,65,-68)
, regardless of its power level:You can then test for a specific power level with blockstates like this: