-- farmland plot -- (i'm not sure how hoes work) local mv = require("movement") local what_to_plant = "2crops" local function dropStuffOff(start_from) local prev_pos,prev_face = mv.getPosition() mv.goBackTo(-1,1,0) mv.face(0, 1) mv.down() mv.dumpInventory(start_from or 4) mv.up() mv.goBackTo(prev_pos.x, 1, prev_pos.z) 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(8) end end local function hoe() turtle.digUp("right") end local function placeOneDirt() superDig() mv.placeItem("dirt", turtle.placeDown) end local function hoeOneDirt() mv.forward() hoe() end local function cubeLayer(action, width, depth) for i=1,width do mv.nTimes(depth-1, action) local turn = mv.turnLeft if i%2 == 0 then turn = mv.turnRight end if i ~= width then turn() action() turn() end end end local function placeChains() turtle.select(mv.findItem("chain")) local i = 0 while turtle.up() do i = i + 1 end for j=1,i do turtle.down() turtle.placeUp() end end local function tillDirtLayer(pos) mv.down() mv.digDown() mv.goBackTo(pos.x, pos.y-2, pos.z) mv.face(1,0) hoe() cubeLayer(hoeOneDirt, 9, 9) mv.goBackTo(pos.x+4, pos.y-2, pos.z-4) mv.goBackTo(pos.x+4, pos.y, pos.z-4) end local function placeDirtLayer() mv.face(1,0) mv.digDown() mv.placeItem("dirt", turtle.placeDown) local pos,_ = mv.getPosition() cubeLayer(placeOneDirt, 9, 9) mv.goBackTo(pos.x+4, pos.y, pos.z-4) mv.down() mv.placeItem("dirt", turtle.placeDown) mv.placeItem("water", turtle.placeDown) tillDirtLayer(pos) -- no longer place the dirt there -- instead use a hole to stop the water flooding the basement mv.placeItem("slab", turtle.placeDown) mv.up() mv.placeItem("lantern", turtle.placeDown) mv.goBackTo(pos.x, pos.y+1, pos.z) placeChains() mv.digUp() mv.placeItem("lantern", turtle.placeUp) mv.goBackTo(-1,1,-1) mv.down() mv.placeItem("minecraft:bucket", turtle.placeDown) mv.goBackTo(0,0,0) mv.face(1,0) end local function placeGrid(n,m) local dirt_needed = m*n*9*9/64 print(string.format("we will need %d stacks of dirt", dirt_needed)) for i=0,n-1 do for j=0,m-1 do mv.goBackTo(1+i*9,1,-j*9) local success, data = turtle.inspectDown() if success and data.state.age ~= nil then print(string.format("skipping plot at position (%d, %d)", i, j)) else mv.down() placeDirtLayer() end end end end local function growOnePlant() local success, data = turtle.inspectDown() if success and data.name:find("lantern") then mv.forward() return end if success and data.state.age == 7 then mv.digDown() if mv.isInventoryFull() then dropStuffOff() end elseif success and data.state.age < 7 then mv.forward() return end turtle.select(mv.findItem(what_to_plant)) turtle.placeDown() mv.forward() end local function growInPlane(n,m) mv.goBackTo(1,1,0) mv.face(1,0) cubeLayer(growOnePlant, n*9, m*9) mv.goBackTo(0,1,0) mv.goBackTo(0,0,0) mv.face(1,0) end local function main(args) if #args == 0 then placeGrid(2, 2) elseif args[1] == "grow" then growInPlane(tonumber(args[2] or 2), tonumber(args[3] or 2)) elseif #args == 2 then placeGrid(tonumber(args[1]), tonumber(args[2])) else print("usage: farmland [grow|dig] [depth] [width]") print("got the wrong number of args...") end end local args = {...} main(args)