Self-Carving Labyrinth Generator

Watch a glowing soul-fire cursor carve a randomized labyrinth out of a solid deepslate monolith right before your eyes using depth-first search.

Java EditionComplex Contraptions & CinematicsHard25 commandsTested on a real 26.2 & 26.3 server
A glowing soul-fire cursor carves corridors through a deepslate brick and sea lantern labyrinth. Download the GIF Video & GIF © www.9minecraft.net

Self-building StructuresMysticDarkTechnologyCyanBlackBuilding ToolMini-gameLearningArmor standsBlock building (fill/setblock/clone)Rotation math21+ commands

The Self-Carving Labyrinth Generator creates a working maze from scratch right before your eyes. First, a massive 23x23 monolith of deepslate bricks and glowing sea lantern trim rises from a dark prismarine foundation. Then, an automated glowing soul-fire cursor spawns at the center and begins carving out connected corridors.

It uses a physical randomized depth-first search algorithm with marker entities: the cursor probes four directions, tunnels through the wall toward an unvisited cell, lays a sea lantern trail, and backtracks along its path whenever it hits a dead end until the entire labyrinth is hollow.

1. Setup - type these once 9 commands

  1. /scoreboard objectives add c9_t dummy
  2. /fill ~-12 ~-1 ~-12 ~12 ~-1 ~12 dark_prismarine
  3. /fill ~-11 ~ ~-11 ~11 ~3 ~11 deepslate_bricks
  4. /fill ~-11 ~3 ~-11 ~11 ~3 ~11 sea_lantern
  5. /fill ~-10 ~ ~-10 ~10 ~3 ~10 deepslate_tiles
  6. /fill ~-1 ~ ~-1 ~1 ~3 ~1 air
  7. /setblock ~ ~-1 ~ sea_lantern
  8. /summon armor_stand ~ ~ ~ {Tags:["c9_gen"],NoGravity:1b,Invisible:1b,Glowing:1b,equipment:{head:{id:"minecraft:soul_lantern",count:1}}}
  9. /summon marker ~ ~ ~ {Tags:["c9_node"]}

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

  1. /scoreboard players add #tick c9_t 1
  2. /execute if score #tick c9_t matches 3.. run scoreboard players set #tick c9_t 0
  3. /execute at @e[tag=c9_gen] run particle soul_fire_flame ~ ~1.8 ~ 0.3 0.6 0.3 0.04 12 force
  4. /execute at @e[tag=c9_gen] run particle sonic_boom ~ ~1.5 ~ 0 0 0 1 1 force
  5. /execute if score #tick c9_t matches 1 at @e[tag=c9_gen] run summon marker ~3 ~ ~ {Tags:["c9_dir"]}
  6. /execute if score #tick c9_t matches 1 at @e[tag=c9_gen] run summon marker ~-3 ~ ~ {Tags:["c9_dir"]}
  7. /execute if score #tick c9_t matches 1 at @e[tag=c9_gen] run summon marker ~ ~ ~3 {Tags:["c9_dir"]}
  8. /execute if score #tick c9_t matches 1 at @e[tag=c9_gen] run summon marker ~ ~ ~-3 {Tags:["c9_dir"]}
  9. /execute if score #tick c9_t matches 1 as @e[tag=c9_dir] at @s unless block ~ ~ ~ deepslate_tiles run kill @s
  10. /execute if score #tick c9_t matches 2 as @e[tag=c9_dir,sort=random,limit=1] at @s facing entity @e[tag=c9_gen,limit=1] feet positioned ^ ^ ^1.5 run fill ~-1 ~ ~-1 ~1 ~3 ~1 air
  11. /execute if score #tick c9_t matches 2 as @e[tag=c9_dir,sort=random,limit=1] at @s run tp @e[tag=c9_gen,limit=1] ~ ~ ~
  12. /execute if score #tick c9_t matches 2 at @e[tag=c9_gen] unless entity @e[tag=c9_node,distance=..1] run setblock ~ ~-1 ~ sea_lantern
  13. /execute if score #tick c9_t matches 2 at @e[tag=c9_gen] unless entity @e[tag=c9_node,distance=..1] run summon marker ~ ~ ~ {Tags:["c9_node"]}
  14. /execute if score #tick c9_t matches 2 run execute unless entity @e[tag=c9_dir] at @e[tag=c9_gen] run kill @e[tag=c9_node,distance=..1]
  15. /execute if score #tick c9_t matches 2 run execute unless entity @e[tag=c9_dir] as @e[tag=c9_node,sort=random,limit=1] at @s run tp @e[tag=c9_gen,limit=1] ~ ~ ~
  16. /execute if score #tick c9_t matches 2 run kill @e[tag=c9_dir]

How it works

Frames from the test run

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

Recorded on our own test server: 59 frames at about 9.8 fps. Our image check saw: A deepslate brick labyrinth with sea lantern borders and prismarine flooring is actively being carved out by a glowing soul-fire cursor.

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. Stand in the center of a flat open area with at least 13 blocks of space in every direction.
  2. Run each of the 9 setup commands once in chat to build the deepslate monolith and spawn the carving cursor at the center.
  3. Place a column or chain of 16 command blocks nearby: set the first to Repeat and Always Active, and the remaining 15 to Chain and Always Active.
  4. Paste the 16 loop commands in order from first to last.
  5. Watch from above as the sonic boom and soul-fire cursor carves corridors and illuminates the labyrinth floor with sea lanterns.
  6. To generate a fresh maze pattern, re-run the setup commands after cleaning up the old markers.

Use it with real players

The maze generator runs automatically on its own once spawned. To trigger a brand-new maze around yourself on demand, execute the setup commands /execute at @p run ... from a button or trigger command block, and walk into the labyrinth once the cursor finishes backtracking and stops moving.

Remove it again 6 commands

  1. /kill @e[tag=c9_gen]
  2. /kill @e[tag=c9_node]
  3. /kill @e[tag=c9_dir]
  4. /scoreboard objectives remove c9_t
  5. /fill ~-12 ~ ~-12 ~12 ~4 ~12 air
  6. /fill ~-12 ~-1 ~-12 ~12 ~-1 ~12 grass_block

FAQ

Why did the previous version leave an uncarved grid of pillars?

Previously the cursor jumped 4 blocks and only carved a 3x3 room at its destination without clearing the wall in between, and old probe markers were never cleared on tick 2. Using a 3-block stride and filling halfway between the cursor and target carves continuous corridors.

Can I make the labyrinth larger?

Yes! Increase the fill coordinates of the outer deepslate brick border and inner deepslate tiles by multiples of 3 (for example, from 10 to 13 or 16) so the 3-block step size aligns cleanly with the outer walls.

Commands used

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

Similar creations

Join 9Minecraft News & Guides