os.loadAPI("/apis/storage") os.loadAPI("/apis/position") os.loadAPI("/apis/sane") os.loadAPI("/apis/digsafe") local db = storage sane.hook() table.insert(digsafe.blacklist, "torch") table.insert(digsafe.blacklist, "Thaumcraft") digsafe.hook() local t = turtle local r = 62 local q = math.ceil(r / 2) db.set("resume", "pitmine") function border (x, z) return (3 == x or 3 == r - x) and ( z < q + 7 and 3 == z % 7 or z > q and 3 == (r - z) % 7) end local d = math.sqrt(85) local a = math.atan(1 / 13) + math.pi / 4 function torch () local x, z = position.get.X(), position.get.Z() - 1 -- rotation matrix whee local xr, zr = x * math.cos(a) - z * math.sin(a), x * math.sin(a) + z * math.cos(a) if ( border(x, z) or border(z, x) or .5 > xr % d and .5 > zr % d ) then t.placeDown() end end function printcoords () local p = position print(p.get.X(), "/", p.get.Y(), "/", p.get.Z(), "/", p.get.F()) end --[[ local function digAround () while t.detectUp() or not t.up() do t.digUp() end while t.detect() do t.dig() end while t.detectDown() or not t.down() do t.digDown() end while t.detectDown() or not t.down() do t.digDown() end while t.detect() or not t.forward() do t.dig() end while t.detect() or not t.forward() do t.dig() end while t.detectUp() or not t.up() do t.digUp() end while t.detectUp() do t.digUp() end while t.detect() do t.dig() end end ]]-- function dig3_p2 (n) while t.digUp() do end while t.digDown() do end t.suckDown() t.suckUp() torch() end function dig3 (n) for i = n, 1, -1 do while t.detect() or not t.forward() do t.dig() end dig3_p2() end end local turn = db.get("turn") or false function doTurn () if turn then t.turnRight() else t.turnLeft() end end function levelDone () local f = position.get.F() return ({ r, 0 })[ 0 == f % 3 and 1 or 2] == ({ position.get.Z() - 1, position.get.X() })[f % 2 + 1] end function turnAround_p2 () local x, z, f = position.get.X(), position.get.Z() - 1, position.get.F() if levelDone() then doTurn() local down = db.get("down") or 3 for i = down, 1, -1 do db.set("down", i) t.down() if t.detectDown() then t.digDown() end end db.clear("down") else dig3(1) end doTurn() turn = not turn db.set("turn", turn) db.clear("turning") end function turnAround () db.set("turning", true) doTurn() turnAround_p2() end -- resume turn if we were interrupted if db.get("turning") then turnAround_p2() end dig3_p2() -- clean above and below -- also triggers sane (inv/torches) local x, z = position.get.X(), position.get.Z() - 1 dig3(({ -- to the end of this row r - z, x, z, r - x })[position.get.F() + 1]) repeat turnAround() dig3(r) until cows_come_home --]]