Self-Carving Algorithmic Labyrinth

An autonomous glowing beacon carves and backtracks through a solid deepslate grid using live depth-first search until a complete labyrinth stands lit.

Java EditionComplex Contraptions & CinematicsExpert24 commandsTested on a real 26.2 & 26.3 server
A glowing beacon carves a deepslate labyrinth, turning orange shroomlight paths into blue sea lanterns. Download the GIF Video & GIF © www.9minecraft.net

Self-building StructuresTechnologyMysticOrangeBlueCyanBuilding ToolLearningMini-gameItem displaysSmooth animation (interpolation)Block building (fill/setblock/clone)Rotation math21+ commands

A solid 19x19 block of deepslate_bricks capped with deepslate_tile_slab sits on the platform while a glowing beacon display entity autonomously tunnels through it. As the beacon explores, it leaves an active path of warm shroomlight along its recursion stack.

Whenever the carver reaches a dead end, it reverses course and follows the shroomlight trail back toward open branches, converting finished corridors into cool sea_lantern blocks until every cell is connected into a complete, solvable labyrinth.

1. Setup - type these once 10 commands

  1. /scoreboard objectives add c9_state dummy
  2. /fill ~-10 ~-1 ~-10 ~10 ~-1 ~10 polished_deepslate
  3. /fill ~-9 ~ ~-9 ~9 ~1 ~9 deepslate_bricks
  4. /fill ~-9 ~2 ~-9 ~9 ~2 ~9 deepslate_tile_slab
  5. /fill ~ ~ ~ ~ ~2 ~ air
  6. /setblock ~ ~-1 ~ shroomlight
  7. /fill ~ ~ ~-9 ~ ~2 ~-9 air
  8. /fill ~ ~ ~9 ~ ~2 ~9 air
  9. /execute align xz positioned ~0.5 ~ ~0.5 run summon item_display ~ ~ ~ {Tags:["c9_head"],item:{id:"minecraft:beacon",count:1},Glowing:1b,glow_color_override:16755200,teleport_duration:2,brightness:{sky:15,block:15},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],translation:[0f,1.6f,0f],scale:[1.3f,1.3f,1.3f]}}
  10. /scoreboard players set @e[type=item_display,tag=c9_head] c9_state 0

2. Loop - one repeating command block each (Always Active) 14 commands

  1. /execute as @e[tag=c9_head,scores={c9_state=2},distance=..0.8] run scoreboard players set @s c9_state 3
  2. /execute as @e[tag=c9_head,scores={c9_state=2}] at @s unless block ^ ^-1 ^1 shroomlight run tp @s ~ ~ ~ ~90 0
  3. /execute as @e[tag=c9_head,scores={c9_state=2}] at @s if block ^ ^-1 ^1 shroomlight run scoreboard players set @s c9_state 1
  4. /execute as @e[tag=c9_head,scores={c9_state=0}] store result entity @s Rotation[0] float 90 run random value 0..3
  5. /execute as @e[tag=c9_head,scores={c9_state=0}] at @s unless block ^ ^ ^2 deepslate_bricks run tp @s ~ ~ ~ ~90 0
  6. /execute as @e[tag=c9_head,scores={c9_state=0}] at @s unless block ^ ^ ^2 deepslate_bricks run tp @s ~ ~ ~ ~90 0
  7. /execute as @e[tag=c9_head,scores={c9_state=0}] at @s unless block ^ ^ ^2 deepslate_bricks run tp @s ~ ~ ~ ~90 0
  8. /execute as @e[tag=c9_head,scores={c9_state=0}] at @s unless block ^ ^ ^2 deepslate_bricks run scoreboard players set @s c9_state 2
  9. /execute as @e[tag=c9_head,scores={c9_state=0..1}] at @s run tp @s ^ ^ ^2
  10. /execute at @e[tag=c9_head,scores={c9_state=0}] run fill ^ ^-1 ^-1 ^ ^-1 ^ shroomlight
  11. /execute at @e[tag=c9_head,scores={c9_state=0}] run fill ^ ^ ^-1 ^ ^2 ^ air
  12. /execute at @e[tag=c9_head,scores={c9_state=1}] run fill ^ ^-1 ^-2 ^ ^-1 ^-1 sea_lantern
  13. /scoreboard players set @e[tag=c9_head,scores={c9_state=1}] c9_state 0
  14. /execute at @e[tag=c9_head] run particle dust{color:[0.2,0.95,1.0],scale:1.8} ~ ~1.8 ~ 0.6 0.8 0.6 0 12

How it works

Frames from the test run

Self-Carving Algorithmic Labyrinth - frame 1Self-Carving Algorithmic Labyrinth - frame 2Self-Carving Algorithmic Labyrinth - frame 3

Recorded on our own test server: 69 frames at about 9.8 fps. Our image check saw: A glowing beacon entity moves through a carved deepslate brick maze, converting paths of orange shroomlight into blue sea lanterns while emitting cyan particles.

Commands, video and screenshots: tested and recorded by www.9minecraft.net © 9Minecraft. Sharing a video or screenshot? Please credit www.9minecraft.net.

Build it in your world

  1. Clear a flat 25x25 area of grass or stone and stand at the exact center block.
  2. Run all 10 setup commands once in order using chat or impulse command blocks positioned at the center.
  3. Place 14 always-active repeating command blocks (or 1 repeating followed by 13 chain conditional-false blocks) in order for the loop commands.
  4. Make sure the repeating block executes positioned at the center of the labyrinth so the origin distance check works properly.
  5. Watch the glowing beacon carve and backtrack until it returns to the center and stops.

Remove it again 4 commands

  1. /kill @e[tag=c9_head]
  2. /scoreboard objectives remove c9_state
  3. /fill ~-10 ~ ~-10 ~10 ~3 ~10 air
  4. /fill ~-10 ~-1 ~-10 ~10 ~-1 ~10 grass_block

FAQ

How does the labyrinth backtrack without storing coordinates on an entity stack?

The <code>shroomlight</code> floor blocks act as the stack in the world itself. Since a depth-first maze has no loops, each cell being backtracked out of has only one adjacent <code>shroomlight</code> bridge leading back to its parent.

Is the finished maze guaranteed to be solvable between the north and south entrances?

Yes. Depth-first search creates a spanning tree across all 81 interior cells, so there is exactly one valid path connecting every cell—including the north and south openings.

Commands used

/execute/fill/particle/random/scoreboard/setblock/summon/tp

Similar creations

Join 9Minecraft News & Guides