-- wget https://mc.cortan122.de/cc/flatten.lua local mv = require("movement") local function placeTorch() mv.turnAround() mv.placeItem("torch", turtle.place) mv.turnAround() end local function placeFloor() local success, data = turtle.inspectDown() if not success then mv.placeItem("minecraft:cobblestone", turtle.placeDown) elseif data.name:find("torch") then turtle.digDown() mv.placeItem("minecraft:cobblestone", turtle.placeDown) end end local function digWithFloor() turtle.dig() mv.forward() turtle.digUp() placeFloor() end local function clearOneRow(n, torches, rotate) for i=1,n do digWithFloor() if torches and i % 7 == 1 then placeTorch() end end rotate() digWithFloor() if torches and (n+1) % 7 == 1 then placeTorch() end rotate() end local function clearSquare(n, m) if not (n % 7 == 1) then n = math.ceil(n/7)*7+1 end if not (m % 7 == 1) then m = math.ceil(m/7)*7+1 end local area = n*m local perimeter = n+m local torches = area/7/7 + perimeter/7 + 1 print(string.format("flattening %dx%d area", n, m)) print(string.format("we need %d torches", torches)) for i=1,m do if i % 2 == 1 then clearOneRow(n-1, i % 7 == 1, turtle.turnRight) else clearOneRow(n-1, i % 7 == 1, turtle.turnLeft) end end end local args = {...} print("program called with", table.concat(args, ", ")) print("note: n and m will be rounded up") clearSquare(args[1], args[2])