Minecraft command block teleportion runaway

minecraft-commandsminecraft-java-edition

I am trying to make a moving airship in vanilla 1.16.1 minecraft. Before, you could just use /clone to move the ship and then teleport the players, but now if you have the ship clone itself the command blocks in the cloned ship also clone themselves, leading to a runaway reaction where the ship moves until it exits render distance. That would be nice if I also didn't want to be able to control the ship.

I've tried using /clone move, which runs until it exits render distance, then I switch to having one command block with /clone replace and then a second command block with /set air, and that setup runs a few times before it finally stops, which is closer to what I want but still out of control. I can get the specific commands if you need them.

What is the current way to make a controllable moving command block structure?

Best Answer

So after some finangling, I figured out that I should use execute to test whether the previous ship has been deleted to stop the runaway reaction, and I am going to post the commands I used so that anyone else suffering through this spaghetti will also be able to do this.

I used a chain of 3 command blocks with the following commands:

/execute if block ~-6 ~-3 ~1 minecraft:air run clone ~-2 ~-9 ~-2 ~24 ~9 ~4 ~28 ~-9 ~-2 replace

/execute if block ~-6 ~-2 ~1 minecraft:air run execute as @a[distance=..25] at @s run tp @s ~30 ~ ~

/fill ~-6 ~-6 ~-2 ~-32 ~11 ~4 minecraft:air

The coordinates in the execute statement is a block in the build that was easy to reach. I don't know if this will work with the /clone move command but I'm happy with just using the 3 command blocks and calling it a day.