Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- base = require "turtle_base"
- base.init(true, {left = base.validTools.pickaxe, right = base.validTools.modem})
- seeds = {
- {block = "minecraft:wheat", item = "minecraft:wheat_seeds", age = 7},
- {block = "minecraft:beetroots", item = "minecraft:beetroot_seeds", age = 3},
- {block = "minecraft:carrots", item = "minecraft:carrot", age = 7},
- {block = "minecraft:sweet_berry_bush", item = "minecraft:sweet_berries", age = 3},
- {block = "minecraft:potatoes", item = "minecraft:potato", age = 7}
- }
- settings.load("settings")
- rows = settings.get("turtleRows", 0)
- columns = settings.get("turtleColumns", 0)
- function initSettings()
- -- init rows
- if rows == 0 then
- showInfo("Requesting Rows")
- term.clear()
- term.setCursorPos(1,1)
- io.write("Rows: ")
- rows = tonumber(io.read())
- settings.set("turtleRows", rows)
- end
- -- init columns
- if columns == 0 then
- showInfo("Requesting Columns")
- term.clear()
- term.setCursorPos(1,1)
- io.write("Columns: ")
- columns = tonumber(io.read())
- settings.set("turtleColumns", columns)
- end
- settings.save("settings")
- end
- function farm()
- while true do
- returnHome()
- base.refuel()
- doFarming()
- sleep(60)
- end
- end
- function noSpaceLeft()
- showInfo("No Space Left")
- returnHome()
- base.returnToWork()
- end
- function returnHome()
- showInfo("Returning Home")
- base.returnHome()
- dumpInv()
- end
- function dumpInv()
- showInfo("Dumping Inventory")
- base.minifyStacks()
- base.rotateTo(2)
- for k, v in pairs(seeds) do
- base.dumpExtraStacks(v.item)
- end
- for k, v in pairs(base.fuel) do
- base.dumpExtraStacks(v)
- end
- base.rotateTo(0)
- end
- function moveNorth()
- finalLoc = base.convertToLocal(base.home.x, base.home.z).z + rows -1
- while base.convertToLocal().z < finalLoc do
- showInfo("Moving North")
- print("finalLoc: ".. finalLoc)
- print("current Loc: ".. base.convertToLocal().z)
- if not base.checkSpace() then
- noSpaceLeft()
- end
- handleCrop()
- base.moveForward()
- end
- end
- function moveSouth()
- finalLoc = base.convertToLocal(base.home.x, base.home.z).z
- while base.convertToLocal().z > finalLoc do
- showInfo("Moving South")
- print("finalLoc: ".. finalLoc)
- print("current Loc: ".. base.convertToLocal().z)
- if not base.checkSpace() then
- noSpaceLeft()
- end
- handleCrop()
- base.moveForward()
- end
- end
- function doFarming()
- for xPos = base.offsetFromHome().x, columns-1, 1 do
- if xPos % 2 == 0 then
- moveNorth()
- else
- moveSouth()
- end
- if not base.checkSpace() then
- returnHome()
- end
- base.refuel()
- if x ~= columns-1 then nextColumn(xPos) end
- end
- end
- function nextColumn(xPos)
- showInfo("Moving to next Column")
- if xPos % 2 == 0 then
- base.rotateTo(1)
- handleCrop()
- base.moveForward()
- base.rotateTo(2)
- else
- base.rotateTo(1)
- handleCrop()
- base.moveForward()
- base.rotateTo(0)
- end
- end
- function getSeedBlock(name)
- for k, v in pairs(seeds) do
- if v.block == name then return v end
- end
- return nil
- end
- function handleCrop()
- local success, data = turtle.inspectDown()
- seed = getSeedBlock(data.name)
- if seed and seed.age == data.state.age then
- showInfo("Harvesting ".. seed.item)
- turtle.digDown()
- local foundItem = true
- while foundItem do
- foundItem = turtle.suckDown()
- end
- item = base.findItem(seed.item)
- if #item > 0 then
- turtle.select(item[1])
- turtle.placeDown()
- end
- end
- end
- function showInfo(status)
- term.clear()
- term.setCursorPos(1,1)
- print(base.currentPosition())
- print("status: ", status)
- base.sendStatus(status)
- end
- initSettings()
- farm()
Add Comment
Please, Sign In to add comment