-- Created by Jef Roosens -- -- This program lets you dig out a rectangle -- TODO return to surface option -- TODO arbitrary height instead of multiple of 3 -- TODO item storage solution local logger = require("jlib.log").Logger:new{level = 3, filename = "dig.log"} local input = require("jlib.input") input.logger = logger local move = require("jlib.move").move move.logger = logger local fuel = require("jlib.fuel") fuel.logger = logger local function layer(width, depth, offset) for i = 1, width do -- Mine slice move('f', depth - 1, { turtle.digUp, turtle.digDown }) -- Move to next slice if i < width then dir = (i + offset) % 2 if dir == 0 then turtle.turnLeft() else turtle.turnRight() end move('f', 1, { turtle.digUp, turtle.digDown }) if dir == 0 then turtle.turnLeft() else turtle.turnRight() end end end end local function dig(width, depth, height, dir) -- Dig initial blocks turtle.digUp() turtle.digDown() local layers = height / 3 for j = 1, layers do local offset = 0 if j % 2 == 0 and width % 2 == 0 then offset = 1 end layer(width, depth, offset) -- Move down a layer if j < layers then move(dir, 3) if dir == 'd' then turtle.digDown() else turtle.digUp() end turtle.turnLeft() turtle.turnLeft() end end end local function main(args) -- Take inputs local width = tonumber(args[1]) or input.read_int("Width: ") local depth = tonumber(args[2]) or input.read_int("Depth: ") local height = tonumber(args[3]) or input.read_int("Height: ") -- TODO add check for dir local dir = args[4] -- Make sure height is valid -- TODO make program work with any height if height % 3 ~= 0 then return logger:log(3, "Height is not a multiple of 3.") end -- Check fuel level -- The + 2 accounts for the moving between layers local fuel_needed = (depth * width + 3) * (height / 3) if not fuel.check(fuel_needed) then return logger:log(1, "Insufficient fuel.") end -- Do the dig dig(width, depth, height, dir) logger:close() end main({...})