Use the ry
and rym
selectors. When a player is facing north the player selector will be @p[rym=135,ry=180]
, when a player is facing west the player selector will be @p[rym=90,ry=135]
, when a player is facing south the player selector will be @p[rym=45,ry=90]
and when a player is facing east the player selector will be @p[rym=0,ry=45]
. To set the block, use the following commands:
/execute @p[rym=135,ry=180] ~ ~ ~ /setblock ~ ~ ~-1 (BLOCK FOR NORTH)
/execute @p[rym=90,ry=135] ~ ~ ~ /setblock ~-1 ~ ~ (BLOCK FOR WEST)
/execute @p[rym=45,ry=90] ~ ~ ~ /setblock ~ ~ ~1 (BLOCK FOR SOUTH)
/execute @p[rym=0,ry=45] ~ ~ ~ /setblock ~1 ~ ~ (BLOCK FOR EAST)