-- places dirt blocks and torches local mv = require("movement") local function placeBehind(name) mv.turnAround() mv.placeItem(name, turtle.place) mv.turnAround() end local function placeDirt() local success, data = turtle.inspectDown() if not success then mv.placeItem("dirt", turtle.placeDown) elseif not data.name:find("dirt") then mv.digDown() mv.placeItem("dirt", turtle.placeDown) end end local function placeSlab() local success, data = turtle.inspectUp() if not success then mv.placeItem("slab", turtle.placeUp) end end local function prepareSpot() placeDirt() mv.nTimes(6, mv.up) placeSlab() mv.nTimes(5, mv.down) mv.placeItem("sapling", turtle.placeDown) mv.forward() mv.down() end local function treeRow(n) for i=1,n do prepareSpot() if i ~= n then mv.nTimes(3, mv.forward) end end mv.turnRight() mv.nTimes(2, mv.forward) mv.turnRight() end local function torchRow(n) for i=1,n do mv.nTimes(4, mv.forward) placeBehind("torch") end mv.forward() mv.turnLeft() mv.nTimes(2, mv.forward) mv.turnLeft() end local function plantTrees(n,m) mv.forward() for i=1,m do treeRow(n) if i ~= m then torchRow(n-1) end end end local function goBack(n,m) mv.nTimes((n-1)*4+2, mv.forward) mv.turnRight() mv.nTimes((m-1)*4+2, mv.forward) mv.turnRight() end local function tryDigTree() while true do local success, data = turtle.inspectUp() if success and data.name:find("log") then mv.up() else break end end end local function justPlant(n, m) -- todo: harvest with cube 33 5 28 for i=0,m-1 do for j=0,n-1 do if i % 2 == 0 then mv.goBackTo(1 + j*4, 1, i*4) else mv.goBackTo(1 + (n-j-1)*4, 1, i*4) end mv.digDown() mv.placeItem("sapling", turtle.placeDown) tryDigTree() end end mv.goBackTo(0,1,0) mv.goBackTo(0,0,0) mv.face(1, 0) end local function main(n, m, just_plant) local needSaplings = n*m local hasSaplings = turtle.getItemCount(mv.findItem("sapling")) if needSaplings <= 64 and hasSaplings < needSaplings then print(string.format("err: need %d sapling, but only %d found", needSaplings, hasSaplings)) return end if just_plant then justPlant(n,m) else plantTrees(n,m) goBack(n,m) end end local function parseArgv(args) local new_method = false if args[1] == "plant" then args = {table.unpack(args, 2)} new_method = true end main(tonumber(args[1] or 5), tonumber(args[2] or 5), new_method) end local args = {...} parseArgv(args)