Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local seedMap = {}
- seedMap["minecraft:wheat"] = "minecraft:wheat_seeds"
- seedMap["minecraft:beetroots"] = "minecraft:beetroot_seeds"
- seedMap["minecraft:carrots"] = "minecraft:carrot"
- seedMap["minecraft:potatoes"] = "minecraft:potato"
- seedMap["minecraft:potatoes"] = "minecraft:potato"
- seedMap["farmersdelight:cabbages"] = "farmersdelight:cabbage_seeds"
- seedMap["farmersdelight:onions"] = "farmersdelight:onion"
- local maxAgeMap = {}
- maxAgeMap["minecraft:wheat"] = 7
- maxAgeMap["minecraft:beetroots"] = 3
- maxAgeMap["minecraft:carrots"] = 7
- maxAgeMap["minecraft:potatoes"] = 7
- maxAgeMap["farmersdelight:cabbages"] = 7
- maxAgeMap["farmersdelight:onions"] = 7
- local function fastFail(success)
- if not success then
- print("An unexpected error has occured! Aborting.")
- exit()
- end
- end
- local function refuel(amount)
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" then
- return true
- end
- turtle.select(16)
- while turtle.getItemCount(16) > 0 and turtle.getFuelLevel() < amount do
- if not turtle.refuel(1) then
- return false
- end
- end
- if turtle.getFuelLevel() < amount then
- return false
- else
- return true
- end
- end
- local function waitForFuel(amount)
- if not refuel(amount) then
- print("Please put fuel in slot 16")
- while not refuel(amount) do
- sleep(0.5)
- end
- print("Received sufficient fuel. Continuing...")
- end
- end
- local function selectItem(name)
- for i=15, 1, -1 do
- itemDetail = turtle.getItemDetail(i)
- if itemDetail and itemDetail.name == name then
- turtle.select(i)
- return true
- end
- end
- return false
- end
- local function countItem(name)
- num = 0
- for i=1, 15 do
- itemDetail = turtle.getItemDetail(i)
- if itemDetail and itemDetail.name == name then
- num = num + itemDetail.count
- end
- end
- return num
- end
- local function waitForItem(name, amount)
- if countItem(name) < amount then
- print("Please provide more " .. name)
- while countItem(name) < amount do
- sleep(0.5)
- end
- print("Received sufficient " .. name .. ". Continuing...")
- end
- selectItem(name)
- end
- local function waitForDrop()
- if turtle.getItemCount() > 0 and not turtle.drop() then
- print("Please make room for turtle to drop")
- while turtle.getItemCount() > 0 and not turtle.drop() do
- sleep(0.5)
- end
- print("Turtle successfully dropped. Continuing...")
- end
- end
- local function waitForDropDown()
- if turtle.getItemCount() > 0 and not turtle.dropDown() then
- print("Please make room for turtle to drop")
- while turtle.getItemCount() > 0 and not turtle.dropDown() do
- sleep(0.5)
- end
- print("Turtle successfully dropped. Continuing...")
- end
- end
- local function waitForDropUp()
- if turtle.getItemCount() > 0 and not turtle.dropUp() then
- print("Please make room for turtle to drop")
- while turtle.getItemCount() > 0 and not turtle.dropUp() do
- sleep(0.5)
- end
- print("Turtle successfully dropped. Continuing...")
- end
- end
- local function containerRefuel(amount)
- turtle.select(16)
- waitForDropDown() -- Edit this line to when changing refuel direction
- turtle.suckDown() -- Edit this line to when changing refuel direction
- if not refuel(amount) then
- print("Waiting for fuel...")
- sleep(0.5)
- while not refuel(amount) do
- sleep(0.5)
- waitForDropDown() -- Edit this line to when changing refuel direction
- turtle.suckDown() -- Edit this line to when changing refuel direction
- end
- end
- end
- local function getBlock()
- local hasBlock, data = turtle.inspect()
- if hasBlock then
- return data.name
- else
- return "minecraft:air"
- end
- end
- local function getBlockDown()
- local hasBlock, data = turtle.inspectDown()
- if hasBlock then
- return data.name
- else
- return "minecraft:air"
- end
- end
- local function getBlockUp()
- local hasBlock, data = turtle.inspectUp()
- if hasBlock then
- return data.name
- else
- return "minecraft:air"
- end
- end
- local function tryForward()
- waitForFuel(1)
- return turtle.forward()
- end
- local function tryBack()
- waitForFuel(1)
- return turtle.back()
- end
- local function tryDown()
- waitForFuel(1)
- return turtle.down()
- end
- local function tryUp()
- waitForFuel(1)
- return turtle.up()
- end
- local function repeatForward(amount)
- for i=1, amount do
- fastFail(tryForward())
- end
- end
- local function repeatBack(amount)
- for i=1, amount do
- fastFail(tryBack())
- end
- end
- local function repeatDown(amount)
- for i=1, amount do
- fastFail(tryDown())
- end
- end
- local function repeatUp(amount)
- for i=1, amount do
- fastFail(tryUp())
- end
- end
- local function isInTransportColumn()
- local hasBlock, data = turtle.inspectUp()
- if not hasBlock or data.name == "minecraft:cobblestone" then
- return true
- else
- return false
- end
- end
- local function recenter()
- while not isInTransportColumn() do
- if not tryForward() then
- turtle.turnRight()
- end
- end
- while getBlock() ~= "minecraft:chest" and getBlock() ~= "minecraft:hopper" do
- turtle.turnLeft()
- end
- while getBlock() ~= "minecraft:chest" do
- tryUp()
- end
- end
- local function tryPlant(name)
- if countItem(name) > 0 then
- selectItem(name)
- turtle.placeDown()
- return true
- else
- return false
- end
- end
- local function doRow()
- local rowSeed = nil
- local hasMissing = false
- local hasBlock, data = turtle.inspectDown()
- if hasBlock then
- local seed = seedMap[data.name]
- if seed then
- rowSeed = seed
- if data.state.age == maxAgeMap[data.name] then
- turtle.digDown()
- tryPlant(seed)
- end
- end
- elseif rowSeed then
- if not tryPlant(rowSeed) then
- hasMissing = true
- end
- else
- hasMissing = true
- end
- for i=1, 13 do
- fastFail(tryForward())
- local hasBlock, data = turtle.inspectDown()
- if hasBlock then
- local seed = seedMap[data.name]
- if seed then
- rowSeed = seed
- if data.state.age == maxAgeMap[data.name] then
- turtle.digDown()
- tryPlant(seed)
- end
- end
- elseif rowSeed then
- if not tryPlant(rowSeed) then
- hasMissing = true
- end
- else
- hasMissing = true
- end
- end
- if hasMissing and rowSeed then
- for i=1, 13 do
- fastFail(tryBack())
- if not turtle.detectDown() then
- tryPlant(rowSeed)
- end
- end
- repeatForward(13)
- end
- end
- recenter()
- if not fs.isDir("/stateFiles") then
- fs.delete("/stateFiles")
- fs.makeDir("/stateFiles")
- end
- if fs.isDir("/stateFiles/farmResetDown") then
- fs.delete("/stateFiles/farmResetDown")
- end
- if fs.exists("/stateFiles/farmResetDown") then
- while not turtle.detectDown() do
- tryDown()
- end
- fs.delete("/stateFiles/farmResetDown")
- end
- while true do
- if getBlockDown() == "minecraft:barrel" then
- containerRefuel(2048)
- end
- sleep(3*60) -- adjust based on the number of layers, make it around 10 minutes per full cycle
- turtle.turnRight()
- fastFail(tryForward())
- doRow()
- turtle.turnRight()
- fastFail(tryForward())
- turtle.turnRight()
- doRow()
- for i=1, 6 do
- turtle.turnLeft()
- fastFail(tryForward())
- turtle.turnLeft()
- doRow()
- turtle.turnRight()
- fastFail(tryForward())
- turtle.turnRight()
- doRow()
- end
- recenter()
- for i=1, 15 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- waitForDrop()
- end
- end
- turtle.select(16)
- if not turtle.refuel(0) then
- waitForDrop()
- end
- if getBlockUp() == "minecraft:air" then
- repeatUp(3)
- else
- local file = fs.open("/stateFiles/farmResetDown", "w")
- file.close()
- while not turtle.detectDown() do
- tryDown()
- end
- fs.delete("/stateFiles/farmResetDown")
- end
- end
Add Comment
Please, Sign In to add comment