Minecraft – How to swap two blocks with /clone

minecraft-java-edition

I'm making a map in which you switch blocks around, but depending on the order you do it, I can't use /setblock or else it might set the wrong block. I know I can use /clone to clone one block and place it in another spot, but is it possible to do this to two blocks at the same time to switch their positions?

Best Answer

Use a temporary spot.

Designate a certain space (really anywhere, preferably underground in a spawn chunk) for the swap space. Then:

  1. /clone block A into the swap space.

  2. Clone block B into the spot where A was.

  3. Clone A into the spot where B was at the start.

Quick diagram (with clearing the swap space at the end)

_ A B
A A B
A B B
A B A
_ B A

Note: I say underground in a spawn chunk for 2 reasons:

  • Underground hopefully won't let anybody near it (idk if entities in the spot will break /clone.

  • If you don't place it in a loaded chunk, then it will have to load the chunk every time you move the block (causing lag). The spawn chunks are already loaded (permanently), so this won't cause a problem.