How would one go about placing a block and having command blocks place blocks relative to the initial block placed?

Solution 1:

I have not tested this method but it should work fine anyway.

Step 1: set up a scoreboard objective that detects when you place a block.

/scoreboard objectives add dirt minecraft.used:minecraft.dirt

Step 2: let the commands know what block to target when you place a dirt block. We will do this by detecting the first four blocks for dirt, then summoning an armor stand at the dirt.

/execute as @a[scores={dirt=1}] at @s if block ^ ^ ^1 dirt run summon armor_stand ~ ~ ~ {CustomName:"\"this is a dirt block\""}

Repeat this command four times, but replacing the third ^ number with 2 3 and 4, to reach four blocks.

Step 3: finish off the machine by resetting the player's dirt score.

/scoreboard players reset @a dirt

Does this help?


EDIT: If you use the machine above it will keep going past the block, not good for if you're not changing the block into something else. To avoid this, just run the commands like this:

/execute as @a[tag=!dirtscores={dirt=1}] at @s if block ^ ^ ^1 dirt run summon armor_stand ~ ~ ~ {CustomName:"\"this is a dirt block\""}

/execute as @a[scores={dirt=1}] at @s if block ^ ^ ^1 dirt run tag @s add dirt

That will tag the player with a tag that prevents the machine from going any further with detecting blocks. Just copy it four times and replace the 1 in the tildes with 2 3 and 4.