How to detect a player on a specific block(s)

Solution 1:

Note: I only noticied that it's the bedrock version as I was finishing this answer. Apologies if it does not work since I can't test myself. I read the wiki and it theoretically should work.


The execution is pretty simple. Since you didn't give me real valeus, I'll try to show it using your screenshot and will be considering the direction you are facing as north, which means foward will decrease Z and to the left will decrease X.

You want to execute as someone within the black grid range and 2-3 block above.

To do that, I'm going to be using the target selector with 'x' and 'dx' (as well for 'y' and z'). 'x' stands for the coordinates on the X axis and 'dx' stands for the distance, using the previus 'x' value

/execute as @a[x=purple.x,dx=3.9,z=purple.z,dz=1.4,y=purple.y+1,dy=3] at @s run fill blue.x blue.y+1 blue.z darkblue.x darkblue.y darkblue.z minecraft:block

Consider color.axis the coordinates for the painted block and y+1 is the block Y axis +1 (So for instance, if it is 6, you will use 7)

This will build a wall made of 'block' starting from the block above the light blue color and until the dark blue one, filling up the whole area.

Apply the same setup on the other side.


Considering the coordinates given, this will be the command:

/execute as @a[x=-44,dx=2.4,z=223,dz=-3.4,y=5,dy=3] at @s run fill -40 5 223 -40 8 219 torch

Change "torch" to any block you want.