-- dig a cube -- starts from the bottom-left-front corner (not in the cube) local mv = require("movement") local function dropStuffOff() local prev_pos,prev_face = mv.getPosition() mv.goBackTo(0,0,0) mv.face(0, -1) mv.dumpInventory() mv.goBackTo(prev_pos.x, prev_pos.y, prev_pos.z) mv.face(prev_face.x, prev_face.z) end local function superDig() mv.dig() mv.forward() mv.digUp() mv.digDown() if mv.isInventoryFull() then dropStuffOff() end end local function doFullLayer(width, depth) for i=1,width do mv.nTimes(depth-1, superDig) local turn = mv.turnLeft if i%2 == 1 then turn = mv.turnRight end if i ~= width then turn() superDig() turn() end end if width%2 == 1 then mv.turnAround() mv.nTimes(depth-1, mv.forward) end mv.turnRight() mv.nTimes(width-1, mv.forward) mv.turnRight() end local function digCube(depth, height, width) local gid_down = height < 0 if gid_down then height = -height end -- fun fact: -3 is exactly the same as +3 if height < 3 or width <= 0 or depth <= 0 then print("sorry, your cube is too small") return end local need_space = width*height*depth/64 print(string.format("we will need %d free slots", need_space)) local function digLayers(up) for i=1,height/3 do if i ~= 1 then up() end up() doFullLayer(width, depth) up() end if height%3 > 0 then if height%3 == 2 then up() end doFullLayer(width, depth) up() end mv.goBackTo(0,0,0) mv.face(1,0) dropStuffOff() end mv.forward() if gid_down then while not turtle.detectDown() and height > 3 do mv.down() height = height - 1 end mv.up() mv.up() digLayers(mv.down) else digLayers(mv.up) end end local function main(args) if #args == 0 then digCube(8,8,8) elseif #args == 1 then local n = tonumber(args[1]) digCube(n,n,n) elseif #args == 3 then digCube(tonumber(args[1]), tonumber(args[2]), tonumber(args[3])) else print("usage: cube [depth] [height] [width]") print("got the wrong number of args...") end end local args = {...} main(args)