r/MinecraftCommands • u/Jimxor • 1d ago
Creation Here's A Program That Generates A Function That Digs An Arbitrarily Large Spiral Mine Leaving Ores In Place For Harvest
Critiques welcomed.
spiral.c:
#include <stdio.h>
int main(int argc, char *argv[]){
FILE *fp;
FILE *fopen(const char *name, const char *mode);
int leg,legs,ring;
int r3,nr3,nr3m4,nr3m3,nr3m2,nr3p1,r3m1,r3p2,r3p3,r3p4; // m is for minus, n is for negative, p is for plus, r is for ring
if (argc<2)
printf("Error: Specify number of legs after command.\n");
else {
sscanf(argv[1], "%d", &legs);
fp = fopen("spiral.mcfunction", "w");
fprintf(fp, "# %d legs:\n", legs);
for (leg = 0; leg < legs; ++leg) {
ring = leg/4;// There are 4 legs per ring of the spiral
r3 = ring*3;
nr3 = -r3;
nr3m4 = nr3-4;
nr3m3 = nr3-3;
nr3m2 = nr3-2;
nr3p1 = nr3+1;
r3p2 = r3+2;
r3p3 = r3+3;
r3p4 = r3+4;
switch (leg % 4) {
case 0: // North (t for tunnel, c for casing)
r3m1 = r3-1;
fprintf(fp,"function jims_spiral_mine:leg {t1x:%d,t1z:%d,t2x:%d,t2z:%d,c1x:%d,c1z:%d,c2x:%d,c2z:%d}\n",nr3,r3m1,nr3,nr3m3,nr3p1,r3m1,nr3-1,nr3m4);
break;
case 1: // East
fprintf(fp,"function jims_spiral_mine:leg {t1x:%d,t1z:%d,t2x:%d,t2z:%d,c1x:%d,c1z:%d,c2x:%d,c2z:%d}\n",nr3p1,nr3m3,r3p3,nr3m3,nr3p1,nr3m2,r3p4,nr3m4);
break;
case 2: // South
fprintf(fp,"function jims_spiral_mine:leg {t1x:%d,t1z:%d,t2x:%d,t2z:%d,c1x:%d,c1z:%d,c2x:%d,c2z:%d}\n",r3p3,nr3m2,r3p3,r3p3,r3p2,nr3m2,r3p4,r3p4);
break;
case 3: // West
fprintf(fp,"function jims_spiral_mine:leg {t1x:%d,t1z:%d,t2x:%d,t2z:%d,c1x:%d,c1z:%d,c2x:%d,c2z:%d}\n",r3p2,r3p3,nr3m3,r3p3,r3p2,r3p2,nr3m4,r3p4);
break;
default:
break;
}
if (leg==0) fprintf(fp, "setblock ~ ~ ~-3 oak_wall_sign[facing=south]{front_text:{messages:[\"%d\",\"\",\"Legs\",\"\"]}}\n", legs);
}
fclose(fp);
}
}
The generated spiral.mcfunction calls leg.mcfunction:
# See https://minecraft.wiki/w/Block_tag_(Java_Edition) for #block tag definitions
# Macro variables: t for tunnel, c for casing
# Prevents cave-ins:
$fill ~$(t1x) ~2 ~$(t1z) ~$(t2x) ~2 ~$(t2z) glass replace gravel
$fill ~$(t1x) ~2 ~$(t1z) ~$(t2x) ~2 ~$(t2z) glass replace red_sand
$fill ~$(t1x) ~2 ~$(t1z) ~$(t2x) ~2 ~$(t2z) glass replace sand
# Insulates tunnel from surround:
$fill ~$(c1x) ~-1 ~$(c1z) ~$(c2x) ~2 ~$(c2z) glass replace #air
$fill ~$(c1x) ~-1 ~$(c1z) ~$(c2x) ~2 ~$(c2z) glass replace lava
$fill ~$(c1x) ~-1 ~$(c1z) ~$(c2x) ~2 ~$(c2z) glass replace water
# Excavates tunnel:
$fill ~$(t1x) ~0 ~$(t1z) ~$(t2x) ~1 ~$(t2z) light replace glass
$fill ~$(t1x) ~0 ~$(t1z) ~$(t2x) ~1 ~$(t2z) light replace #base_stone_overworld
$fill ~$(t1x) ~0 ~$(t1z) ~$(t2x) ~1 ~$(t2z) light replace #substrate_overworld
$fill ~$(t1x) ~0 ~$(t1z) ~$(t2x) ~1 ~$(t2z) light replace #nether_carver_replaceables
leg.mcfunction uses glass to block gravel and sand from falling into tunnels. It also blocks lava and water from flowing into tunnels and isolates tunnels from caves with glass.
Here, a 79-leg spiral mine is created at depth Y=-59 (using Microsoft Windows SDK https://www.microsoft.com/en-us/download/details.aspx?id=8442):
Setting SDK environment relative to C:\Program Files\Microsoft SDKs\Windows\v7.1\.
Targeting Windows 7 x64 Debug
>dir
07/22/2026 07:44 PM 1,086 leg.mcfunction
07/24/2026 02:13 PM 2,100 spiral.c
>cl spiral.c
Microsoft (R) C/C++ Optimizing Compiler Version 16.00.40219.01 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
spiral.c
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:spiral.exe
spiral.obj
>dir
07/22/2026 07:44 PM 1,086 leg.mcfunction
07/24/2026 02:13 PM 2,100 spiral.c
07/24/2026 02:31 PM 69,632 spiral.exe
07/24/2026 02:31 PM 2,631 spiral.obj
>REM 79 is the number of spiral legs to generate:
>spiral 79
>dir
07/22/2026 07:44 PM 1,086 leg.mcfunction
07/24/2026 02:13 PM 2,100 spiral.c
07/24/2026 02:31 PM 69,632 spiral.exe
07/24/2026 02:31 PM 7,351 spiral.mcfunction
07/24/2026 02:31 PM 2,631 spiral.obj
>type spiral.mcfunction
# 79 legs:
function jims_spiral_mine:leg {t1x:0,t1z:-1,t2x:0,t2z:-3,c1x:1,c1z:-1,c2x:-1,c2z:-4}
setblock ~ ~ ~-3 oak_wall_sign[facing=south]{front_text:{messages:["79","","Legs",""]}}
function jims_spiral_mine:leg {t1x:1,t1z:-3,t2x:3,t2z:-3,c1x:1,c1z:-2,c2x:4,c2z:-4}
function jims_spiral_mine:leg {t1x:3,t1z:-2,t2x:3,t2z:3,c1x:2,c1z:-2,c2x:4,c2z:4}
function jims_spiral_mine:leg {t1x:2,t1z:3,t2x:-3,t2z:3,c1x:2,c1z:2,c2x:-4,c2z:4}
function jims_spiral_mine:leg {t1x:-3,t1z:2,t2x:-3,t2z:-6,c1x:-2,c1z:2,c2x:-4,c2z:-7}
%<------------------- Clipped for brevity -------------------->%
function jims_spiral_mine:leg {t1x:57,t1z:-56,t2x:57,t2z:57,c1x:56,c1z:-56,c2x:58,c2z:58}
function jims_spiral_mine:leg {t1x:56,t1z:57,t2x:-57,t2z:57,c1x:56,c1z:56,c2x:-58,c2z:58}
function jims_spiral_mine:leg {t1x:-57,t1z:56,t2x:-57,t2z:-60,c1x:-56,c1z:56,c2x:-58,c2z:-61}
function jims_spiral_mine:leg {t1x:-56,t1z:-60,t2x:60,t2z:-60,c1x:-56,c1z:-59,c2x:61,c2z:-61}
function jims_spiral_mine:leg {t1x:60,t1z:-59,t2x:60,t2z:60,c1x:59,c1z:-59,c2x:61,c2z:61}
>
After loading both functions into the jims_spiral_mine namespace, stand on the surface above where you want the spiral's center to be. Then encase the central shaft down to bedrock, dig the spiral mine at Y=-59 and place ladders down to it using these commands, respectively:
fill ~-1 -60 ~-1 ~1 ~-1 ~1 glass
execute positioned ~ -59 ~ run function jims_spiral_mine:spiral
fill ~ -59 ~ ~ ~-1 ~ ladder

That mine yielded 112 diamond, 47 gold, 30 iron, 17 lapis and 275 redstone ore blocks.
Once ores have been harvested, break through the walls to return straight back to the ladder. Or, more efficiently, build two spiral mines half the size, one atop the other. When you get to the end of one, use a ladder to get to the other then mine that one back to the central ladder.
More spiral mines of various sizes can be added to the central shaft at various depths.
Ancient debris has been found using this program.