{"tool":"voxel.exec","input":{"code":"// ============================================================\n// MineBench Build: A Choo-Choo Train (v9 - cab-first ordering)\n// ============================================================\n\n// --- Helpers ---\nfunction cyl(cx, cy, cz, r, h, type) {\n  let r2 = r * r;\n  for (let dy = -r; dy <= r; dy++) {\n    for (let dx = -r; dx <= r; dx++) {\n      if (dx * dx + dy * dy <= r2) {\n        for (let dz = -Math.floor(r); dz <= Math.floor(r); dz++) {\n          block(cx + dx, cy + dy, cz + dz, type);\n        }\n      }\n    }\n  }\n}\n\nfunction cylZ(cx, cy, cz, r, h, type) {\n  let r2 = r * r;\n  for (let dx = -r; dx <= r; dx++) {\n    for (let dz = -r; dz <= r; dz++) {\n      if (dx * dx + dz * dz <= r2) {\n        for (let dy = 0; dy < h; dy++) {\n          block(cx + dx, cy + dy, cz + dz, type);\n        }\n      }\n    }\n  }\n}\n\nfunction sphere(cx, cy, cz, r, type) {\n  let r2 = r * r;\n  for (let dy = -r; dy <= r; dy++) {\n    for (let dx = -r; dx <= r; dx++) {\n      for (let dz = -r; dz <= r; dz++) {\n        if (dx * dx + dy * dy + dz * dz <= r2) {\n          block(cx + dx, cy + dy, cz + dz, type);\n        }\n      }\n    }\n  }\n}\n\nfunction wheel(wx, wy, wz, r, edgeType, hubType) {\n  let r2 = r * r;\n  for (let dy = -r; dy <= r; dy++) {\n    for (let dx = -r; dx <= r; dx++) {\n      const dist = dx * dx + dy * dy;\n      if (dist <= r2) {\n        const isSpoke = Math.abs(dx) <= 1 || Math.abs(dy) <= 1;\n        if (Math.abs(dx) <= 2 && Math.abs(dy) <= 2) {\n          block(wx + dx, wy + dy, wz, hubType || 'iron_block');\n        } else if (dist >= (r - 1) * (r - 1)) {\n          block(wx + dx, wy + dy, wz, edgeType || 'iron_block');\n        } else if (isSpoke) {\n          block(wx + dx, wy + dy, wz, 'iron_block');\n        } else {\n          block(wx + dx, wy + dy, wz, 'gray_wool');\n        }\n      }\n    }\n  }\n}\n\n// --- Palette ---\nconst BLACK = 'black_wool';\nconst GRAY = 'gray_wool';\nconst IRON = 'iron_block';\nconst STONE = 'stone';\nconst BRICKS = 'bricks';\nconst OAK = 'oak_planks';\nconst OAK_LOG = 'oak_log';\nconst GLASS = 'glass';\nconst GLOW = 'glowstone';\nconst GOLD = 'gold_block';\nconst WHITE = 'white_wool';\nconst SAND = 'sand';\nconst DIRT = 'dirt';\nconst LEAVES = 'oak_leaves';\nconst BROWN_WOOL = 'brown_wool';\nconst RED_WOOL = 'red_wool';\nconst GREEN_WOOL = 'green_wool';\n\n// --- Scenery: trees (ty=0 so trunk reaches y=0, grounded) ---\nfunction tree(tx, ty, tz) {\n  for (let dy = 0; dy < 9; dy++) {\n    block(tx, ty + dy, tz, OAK_LOG);\n  }\n  sphere(tx, ty + 8, tz, 3, LEAVES);\n  sphere(tx - 1, ty + 7, tz, 2, LEAVES);\n  sphere(tx + 1, ty + 7, tz, 2, LEAVES);\n  sphere(tx, ty + 9, tz, 2, LEAVES);\n}\n\ntree(60, 0, 100);\ntree(68, 0, 106);\ntree(185, 0, 95);\ntree(192, 0, 100);\ntree(55, 0, 55);\ntree(180, 0, 50);\n\n// --- Ground plane (full coverage: z=45 to 120) ---\nfor (let x = 50; x <= 210; x++) {\n  for (let dz = 45; dz <= 120; dz++) {\n    box(x, 0, dz, x, 0, dz, DIRT);\n  }\n}\nfor (let x = 50; x <= 210; x++) {\n  for (let dz = 45; dz <= 120; dz++) {\n    box(x, 1, dz, x, 1, dz, GREEN_WOOL);\n  }\n}\n\n// --- Track bed ---\nconst LZ = 85;\nconst YG = 1;\n\nfor (let x = 50; x <= 210; x++) {\n  for (let dz = -5; dz <= 5; dz++) {\n    box(x, YG, LZ + dz, x, YG, LZ + dz, SAND);\n  }\n}\nfor (let x = 53; x <= 207; x += 2) {\n  for (let dz = -3; dz <= 3; dz++) {\n    box(x, YG, LZ + dz, x, YG, LZ + dz, OAK);\n  }\n}\nfor (let x = 50; x <= 210; x++) {\n  box(x, YG + 1, LZ - 2, x, YG + 1, LZ - 2, IRON);\n  box(x, YG + 1, LZ + 2, x, YG + 1, LZ + 2, IRON);\n}\n\n// --- Water tower (far -Z side, legs at corners, grounded)\nconst wtx = 75, wtz = 45;\nfor (let dy = 0; dy < 19; dy++) {\n  block(wtx - 2, dy, wtz - 2, IRON);\n  block(wtx + 2, dy, wtz - 2, IRON);\n  block(wtx - 2, dy, wtz + 2, IRON);\n  block(wtx + 2, dy, wtz + 2, IRON);\n}\nfor (let dy = 4; dy < 19; dy += 6) {\n  line(wtx - 2, dy, wtz - 2, wtx + 2, dy + 3, wtz + 2, IRON);\n  line(wtx + 2, dy, wtz - 2, wtx - 2, dy + 3, wtz + 2, IRON);\n}\ncyl(wtx, 19, wtz, 4, 6, GRAY);\nbox(wtx - 4, 19, wtz - 1, wtx + 4, 19, wtz + 1, GRAY);\nbox(wtx - 4, 24, wtz - 1, wtx + 4, 24, wtz + 1, GRAY);\ncylZ(wtx, 25, wtz, 3, 1, BRICKS);\ncylZ(wtx, 0, wtz, 1, 19, IRON);\n\n// --- Locomotive ---\nconst LX = 128;\nconst front = LX + 30;\nconst back = LX - 25;\nconst top = 22;\nconst bot = 4;\nconst Z = LZ;\n\n// Smokebox\ncyl(front + 2, 12, Z, 7, 10, GRAY);\ncyl(front + 2, 12, Z, 6, 10, BLACK);\n\n// Smokestack (body extends to y=20 to touch gold trim at y=21)\ncylZ(front + 10, bot, Z, 3, 17, BLACK);\ncylZ(front + 10, top - 1, Z, 4, 1, GOLD);\ncylZ(front + 10, top + 1, Z, 2, 1, GOLD);\ncylZ(front + 10, bot - 1, Z, 4, 1, IRON);\n\n// Boiler (tapered)\nfor (let x = front - 4; x <= back + 2; x++) {\n  let t = (x - (front - 4)) / ((back + 2) - (front - 4));\n  let r = 7 + 2 * (1 - t);\n  cyl(x, 12, Z, Math.round(r), 1, GRAY);\n  cyl(x, 12, Z, Math.round(r) - 1, 1, BLACK);\n}\n\n// Cab (built FIRST so dome/trim sit on top of it)\nbox(back - 4, bot, Z - 5, back + 6, top - 1, Z + 5, BLACK);\ncyl(back + 1, top - 1, Z - 5, 3, 14, BLACK);\ncyl(back + 1, top - 1, Z + 5, 3, 14, BLACK);\ncyl(back + 1, top, Z - 3, 2, 10, BLACK);\nbox(back, top - 4, Z - 5, back + 4, top - 2, Z - 5, GLASS);\nbox(back, top - 4, Z + 5, back + 4, top - 2, Z + 5, GLASS);\n\n// Boiler dome (sits on cab top: cab ends y=21, dome starts y=21, BLACK to connect to cab)\ncylZ(LX - 2, top - 1, Z, 2, 3, BLACK);\nbox(LX - 2, top + 3, Z - 1, LX - 2, top + 3, Z + 1, GOLD);\n\n// Water tank behind cab (connects cab to tender)\nbox(back + 7, bot + 1, Z - 4, back + 12, bot + 6, Z + 4, GRAY);\nbox(back + 7, bot + 7, Z - 3, back + 12, bot + 7, Z + 3, GRAY);\nfor (let y = bot + 1; y <= bot + 7; y++) {\n  box(back + 12, y, Z - 4, back + 12, y, Z - 4, IRON);\n}\n\n// Bell\ncylZ(LX, top + 1, Z, 1, 2, GOLD);\nbox(LX - 1, top + 3, Z - 1, LX + 1, top + 3, Z + 1, GOLD);\n\n// Whistle\ncylZ(front + 6, bot + 4, Z, 1, 4, GOLD);\nbox(front + 6, bot + 7, Z - 1, front + 6, bot + 7, Z + 1, GOLD);\n\n// Cowcatcher\nfor (let dy = 0; dy < 4; dy++) {\n  let w = 3 + dy;\n  box(front + 10 + dy, bot + dy, Z - w, front + 10 + dy, bot + dy, Z + w, IRON);\n}\nbox(front + 13, bot, Z - 3, front + 13, bot, Z + 3, STONE);\nbox(front + 13, bot + 1, Z, front + 13, bot + 1, Z, GLOW);\n\n// --- Wheels ---\nwheel(front + 2, 8, Z - 5, 8, 'iron_block', 'gold_block');\nwheel(front + 2, 8, Z + 5, 8, 'iron_block', 'gold_block');\nwheel(LX, 8, Z - 5, 8, 'iron_block', 'gold_block');\nwheel(LX, 8, Z + 5, 8, 'iron_block', 'gold_block');\n\nfunction sWheel(wx, wy, wz) {\n  wheel(wx, wy, wz, 5, 'iron_block', 'iron_block');\n}\nsWheel(front - 10, 5, Z - 5);\nsWheel(front - 10, 5, Z + 5);\nsWheel(back - 6, 5, Z - 5);\nsWheel(back - 6, 5, Z + 5);\n\n// Connecting rods\nfor (let x = front - 8; x <= front + 10; x++) {\n  box(x, 8, Z - 6, x, 8, Z + 6, IRON);\n}\nfor (let x = LX - 6; x <= front + 10; x++) {\n  box(x, 8, Z - 6, x, 8, Z + 6, IRON);\n}\nfor (let y = 8; y <= 14; y++) {\n  box(front + 4, y, Z - 1, front + 4, y, Z + 1, IRON);\n}\nbox(front + 2, 10, Z - 2, front + 2, 14, Z + 2, GRAY);\n\n// --- Tender ---\nconst tBack = back - 32;\nconst tFront = back - 2;\nbox(tFront, bot, Z - 5, tBack, bot, Z + 5, BLACK);\nbox(tFront, bot + 1, Z - 4, tBack, bot + 1, Z + 4, OAK);\nbox(tFront, top - 2, Z - 4, tBack, top - 2, Z + 4, OAK);\nbox(tFront, bot, Z - 5, tFront, top - 2, Z + 5, BLACK);\nbox(tBack, bot, Z - 5, tBack, top - 2, Z + 5, BLACK);\n// Tender coupling (sturdy, 3-block-wide)\nfor (let x = tBack; x <= back - 4; x++) {\n  box(x, bot + 1, Z - 1, x, bot + 3, Z + 1, IRON);\n}\n\n// Coal pile (mounded)\ncylZ((tFront + tBack) / 2, bot + 2, Z, 4, 4, BROWN_WOOL);\ncylZ((tFront + tBack) / 2, bot + 5, Z, 3, 2, BROWN_WOOL);\nsphere((tFront + tBack) / 2, bot + 7, Z, 2, BROWN_WOOL);\n\n// --- Headlight ---\nbox(front + 9, 14, Z - 1, front + 9, 14, Z + 1, GLOW);\nbox(front + 10, 14, Z - 1, front + 10, 14, Z + 1, GLASS);\nbox(front + 8, 13, Z - 2, front + 8, 15, Z + 2, IRON);\n\n// --- Station building (on +Z side of track) ---\nconst stZ = LZ + 10;\nbox(165, 2, stZ, 165, 11, stZ + 25, BRICKS);\nbox(165, 2, stZ + 25, 180, 11, stZ + 25, BRICKS);\nbox(180, 2, stZ, 180, 11, stZ + 25, BRICKS);\nbox(163, 12, stZ - 2, 182, 13, stZ + 27, BRICKS);\nbox(164, 13, stZ - 1, 181, 14, stZ + 26, RED_WOOL);\nbox(165, 2, stZ + 13, 165, 7, stZ + 17, OAK_LOG);\nbox(165, 6, stZ + 3, 165, 8, stZ + 7, GLASS);\nbox(165, 6, stZ + 18, 165, 8, stZ + 22, GLASS);\nbox(165, 11, stZ + 10, 165, 11, stZ + 19, GOLD);\n\n// Station sign\nblock(170, 14, stZ + 12, GLOW);\nblock(175, 14, stZ + 12, GLOW);\n\n// --- Station platform (on -Z side of track, clear of track) ---\nfor (let x = 75; x <= 165; x++) {\n  for (let dz = LZ - 12; dz <= LZ - 3; dz++) {\n    box(x, 2, dz, x, 3, dz, OAK);\n  }\n}\nfor (let x = 75; x <= 165; x++) {\n  box(x, 3, LZ - 13, x, 3, LZ - 13, BRICKS);\n}\nfor (let x = 85; x <= 155; x += 12) {\n  cylZ(x, 4, LZ - 8, 1, 10, OAK_LOG);\n}\nbox(80, 14, LZ - 12, 160, 14, LZ - 3, OAK);\nbox(80, 15, LZ - 10, 160, 15, LZ - 5, RED_WOOL);\n\n// Walkway from platform area to station building\nfor (let x = 165; x <= 185; x++) {\n  for (let dz = LZ - 3; dz <= stZ; dz++) {\n    box(x, 2, dz, x, 2, dz, OAK);\n  }\n}\n\n// --- Steam clouds (intentionally floating) ---\nsphere(front + 14, 26, Z, 3, WHITE);\nsphere(front + 17, 29, Z - 1, 2, WHITE);\nsphere(front + 20, 31, Z, 2, WHITE);\nsphere(front + 16, 33, Z + 1, 2, WHITE);\nsphere(front + 22, 28, Z - 2, 1, WHITE);\nsphere(front + 13, 30, Z + 2, 2, WHITE);\nsphere(front + 19, 34, Z - 1, 1, WHITE);\nsphere(front + 25, 30, Z + 1, 1, WHITE);\n\n// --- Boiler detail bands ---\nfor (let dx = -1; dx <= 1; dx++) {\n  for (let dz = -1; dz <= 1; dz++) {\n    box(LX - 5, 12 + dx, Z + dz, LX - 5, 12 + dx, Z + dz, GOLD);\n    box(LX + 5, 12 + dx, Z + dz, LX + 5, 12 + dx, Z + dz, GOLD);\n  }\n}\n\n// --- Cab roof trim (sits on cab at y=top=22, within cab footprint, BLACK to connect) ---\nfor (let dx = -4; dx <= 4; dx++) {\n  for (let dz = -4; dz <= 4; dz++) {\n    box(back + 1 + dx, top, Z + dz, back + 1 + dx, top, Z + dz, BLACK);\n  }\n}\n\n// --- Gravel detail ---\nfor (let x = 55; x <= 205; x++) {\n  for (let dz = -5; dz <= 5; dz++) {\n    if ((x * 7 + dz * 13) % 5 === 0) {\n      box(x, YG + 1, LZ + dz, x, YG + 1, LZ + dz, STONE);\n    }\n  }\n}\n\n// --- Rocks (on ground: y=1) ---\nsphere(70, 1, 115, 2, STONE);\nsphere(175, 1, 110, 1, STONE);\nsphere(155, 1, 160, 2, STONE);\n","gridSize":256,"palette":"simple","seed":123}}