Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Load different API's
- if fs.exists("extraFuncsApi") then
- os.loadAPI("extraFuncsApi")
- else
- shell.run("pastebin", "get", "5MwHEZxB", "extraFuncsApi")
- os.loadAPI("extraFuncsApi")
- end
- if fs.exists("serverApi") then
- os.loadAPI("serverApi")
- else
- shell.run("pastebin", "get", "dazENzF5", "serverApi")
- os.loadAPI("serverApi")
- end
- if fs.exists("facilityApi") then
- os.loadAPI("facilityApi")
- else
- shell.run("pastebin", "get", "Eyrmtw0m", "facilityApi")
- os.loadAPI("facilityApi")
- end
- local feederUpgrade = peripheral.wrap("left")
- -- Set data table
- local farm_positions = {
- home = vector.new(-68, 321, 50),
- home_dir = "S",
- start_dir = "W",
- sectors = {
- {vector.new(-69, 322, 50 ), vector.new(-96, 323, 50)},
- {vector.new(-69, 327, 50 ), vector.new(-96, 328, 50)},
- {vector.new(-69, 332, 50 ), vector.new(-96, 333, 50)},
- {vector.new(-69, 337, 50 ), vector.new(-96, 338, 50)},
- {vector.new(-69, 342, 50 ), vector.new(-96, 343, 50)},
- }
- }
- local current_task = ""
- local current_farm = 1
- local harvested = 0
- function pumpkinFarm()
- turtle.select(2)
- while true do
- for i=current_farm,5 do
- changeTask("Go to sector " .. i)
- goToY(farm_positions.sectors[i][1])
- goToX(farm_positions.sectors[i][1])
- changeTask("Starting sector " .. i)
- runStrip(farm_positions.sectors[i])
- changeTask("done with sector" .. i)
- current_farm = current_farm + 1
- end
- current_farm = 1
- iddle()
- end
- end
- function runStrip(place)
- face(farm_positions.start_dir)
- local bad_counter = 0
- farm()
- while this_turtle.pos.x ~= place[2].x do
- if not this_turtle:forward() then
- bad_counter = bad_counter + 1
- else
- printInfo()
- end
- if bad_counter == 10 then
- changeTask("Something went wrong with farming... trying to fix this")
- for i=1,4 do
- this_turtle:back()
- end
- getGps()
- pumpkinFarm()
- end
- farm()
- end
- this_turtle:left()
- printInfo()
- this_turtle:forward()
- printInfo()
- this_turtle:left()
- printInfo()
- local bad_counter = 0
- farm()
- while this_turtle.pos.x ~= place[1].x do
- if not this_turtle:forward() then
- bad_counter = bad_counter + 1
- else
- printInfo()
- end
- if bad_counter == 10 then
- changeTask("Something went wrong with farming... trying to fix this")
- for i=1,4 do
- this_turtle:back()
- end
- getGps()
- pumpkinFarm()
- end
- farm()
- end
- end
- function farm()
- changeTask("Farming sector " .. current_farm)
- local success, t = turtle.inspectDown()
- if success then
- if string.find(t.name, "pumpkin") ~= nil and string.find(t.name, "stem") == nil then
- turtle.digDown()
- harvested = harvested + 1
- end
- end
- checkInv()
- end
- function checkInv()
- if turtle.getItemCount(16) > 50 then
- changeTask("Going to empty inventory")
- local back_pos = this_turtle.pos
- local direction = this_turtle.dir
- while this_turtle.pos:tostring() ~= farm_positions.home:tostring() do
- getGps()
- goToX(farm_positions.home)
- goToY(farm_positions.home)
- end
- emptyInventory()
- changeTask("Going back to original place before emptying inventory")
- while this_turtle.pos:tostring() ~= back_pos:tostring() do
- getGps()
- goToX(back_pos)
- goToY(back_pos)
- end
- face(direction)
- end
- end
- function emptyInventory()
- changeTask("Empty inventory")
- turtle.select(1)
- if peripheral.getType("right") ~= "workbench" and peripheral.getType("left") ~= "workbench" then
- turtle.equipLeft()
- end
- if peripheral.getType("right") ~= "workbench" and peripheral.getType("left") ~= "workbench" then
- print("NO WORKBENCH FOUND")
- do return end
- end
- for i=2,16 do
- if turtle.getItemCount(i) ~= 0 then
- if turtle.getItemDetail(i).name == "minecraft:pumpkin_seeds" then
- turtle.dropDown()
- elseif turtle.getItemDetail(i).name ~= "minecraft:pumpkin" then
- face("E")
- turtle.drop()
- end
- end
- end
- face("N")
- turtle.select(1) turtle.drop()
- for x = 2, 16 do turtle.select(x) turtle.dropUp() end
- turtle.select(2)
- for i = 2, 16 do
- turtle.suckUp()
- while turtle.getItemCount(2) ~= 0 and turtle.getItemDetail(2).name == "minecraft:pumpkin" do
- turtle.craft()
- turtle.select(3) turtle.dropDown()
- end
- turtle.select(2)
- end
- turtle.select(1) turtle.suck()
- if peripheral.getType("right") ~= "modem" and peripheral.getType("left") ~= "modem" then
- turtle.equipLeft()
- end
- if peripheral.getType("right") ~= "modem" and peripheral.getType("left") ~= "modem" then
- print("NO MODEM FOUND")
- do return end
- end
- turtle.select(2)
- end
- -- go to pos
- function goToY(place)
- local place = place:round()
- if this_turtle.pos.y ~= place.y then
- if this_turtle.pos.y < place.y then
- while this_turtle.dir ~= "S" do
- this_turtle:left()
- end
- elseif this_turtle.pos.y > place.y then
- while this_turtle.dir ~= "N" do
- this_turtle:right()
- end
- end
- local bad_counter = 0
- while this_turtle.pos.y ~= place.y do
- if not this_turtle:forward() then
- bad_counter = bad_counter + 1
- else
- printInfo()
- end
- if bad_counter == 10 then
- changeTask("Something went wrong with farming... trying to fix this")
- for i=1,4 do
- this_turtle:back()
- end
- getGps()
- goToY(place)
- end
- end
- end
- end
- function goToX(place)
- local place = place:round()
- if this_turtle.pos.x ~= place.x then
- if this_turtle.pos.x > place.x then
- while this_turtle.dir ~= "W" do
- this_turtle:left()
- end
- elseif this_turtle.pos.x < place.x then
- while this_turtle.dir ~= "E" do
- this_turtle:right()
- end
- end
- local bad_counter = 0
- while this_turtle.pos.x ~= place.x do
- if not this_turtle:forward() then
- bad_counter = bad_counter + 1
- else
- printInfo()
- end
- if bad_counter == 10 then
- changeTask("Something went wrong with farming... trying to fix this")
- for i=1,4 do
- this_turtle:back()
- end
- getGps()
- goToX(place)
- end
- end
- end
- end
- function goToZ(place)
- if this_turtle.pos.z ~= place.z then
- if this_turtle.pos.z > place.z then
- while this_turtle.pos.z ~= place.z do
- this_turtle:down()
- end
- elseif this_turtle.pos.z < place.z then
- while this_turtle.pos.z ~= place.z do
- this_turtle:up()
- end
- end
- end
- end
- function face(direction)
- while this_turtle.dir ~= direction do
- this_turtle:right()
- printInfo()
- end
- end
- function getGps()
- if peripheral.getType("right") ~= "modem" and peripheral.getType("left") ~= "modem" then
- turtle.equipLeft()
- end
- if peripheral.getType("right") ~= "modem" and peripheral.getType("left") ~= "modem" then
- print("NO MODEM FOUND")
- do return end
- else
- this_turtle:get_dir()
- this_turtle:get_gps()
- end
- printInfo()
- end
- -- Init and start function
- function start()
- changeTask("Starting")
- turtle.select(1)
- getGps()
- if not fs.exists("startup") then
- changeTask("Making startup file")
- local h = fs.open("startup", "w")
- h.writeLine("sleep(1)")
- h.writeLine("shell.run('" .. shell.getRunningProgram() .. "')")
- h.close()
- current_farm = 1
- changeTask("Making folder 'pumpkinFolder'")
- fs.makeDir("pumpkinFolder")
- changeTask("Saving counter variables in 'pumpkinFolder/harvested'")
- local h = fs.open("pumpkinFolder/harvested", "w")
- h.writeLine(harvested)
- h.close()
- pumpkinFarm()
- else
- changeTask("Seems I crashed, try to fix this.")
- crashFunction()
- changeTask("Going to farm " .. current_farm)
- pumpkinFarm()
- end
- end
- -- function init()
- -- this_facility = facilityApi.facility:new("PumpkinFarm")
- -- if this_facility:is_registered() == false then
- -- error("Facility doesn't exists, make before running this script")
- -- else
- -- slave_turtle = serverApi.slave:new("PumpkinFarmSlave", "PumpkinFarm")
- -- if this_computer:is_registered() == false then
- -- if this_computer:register() == true then
- -- print("Slave has been registered")
- -- this_turtle = extraFuncsApi.extraFuncs:new(vector.new(0, 0, 0), "N", true)
- -- farm_poistions.home = this_turtle:get_gps()
- -- farm_positions.home_dir = this_turtle:get_dir()
- -- print("Init function okay")
- -- sleep(1)
- -- else
- -- error("Couldn't register slave")
- -- end
- -- else
- -- error("Turtle seems to already be registered?")
- -- end
- -- end
- -- end
- function crashFunction()
- getGps()
- checkInv()
- current_farm = 1
- for key,val in pairs(farm_positions.sectors) do
- if this_turtle.pos.y == val[1].y or this_turtle.pos.y == val[2].y then
- current_farm = key
- end
- end
- changeTask("Reading counter variables")
- local h = fs.open("pumpkinFolder/harvested", "r")
- harvested = tonumber(h.readLine())
- h.close()
- end
- function printInfo()
- clearScreen()
- print("---------- PUMPKIN BOY ---------")
- print("X: " .. this_turtle.pos.x )
- print("Y: " .. this_turtle.pos.y)
- print("Z: " .. this_turtle.pos.z)
- print("Facing: " .. this_turtle.dir)
- print("--------------------------------")
- print(current_task)
- print("--------------------------------")
- print("Home X: " .. farm_positions.home.x)
- print("Home Y: " .. farm_positions.home.y)
- print("Home Z: " .. farm_positions.home.z)
- print("Home direction: " .. farm_positions.home_dir)
- end
- function clearScreen()
- term.clear()
- term.setCursorPos(1,1)
- end
- function changeTask(task)
- current_task = task
- printInfo()
- end
- function printIddleInfo(sleep_timer)
- clearScreen()
- print("Waiting " .. sleep_timer .. " seconds to start farming again")
- print("---------------------------------------")
- print("Pumpkins harvested: " .. harvested)
- end
- function iddle()
- local timer = 60
- while timer ~= 0 do
- printIddleInfo(timer)
- timer = timer - 1
- sleep(1)
- end
- end
- function saveCounters()
- local h = fs.open("pumpkinFolder/harvested", "w")
- h.writeLine(harvested)
- h.close()
- end
- this_turtle = extraFuncsApi.extraFuncs:new(vector.new(0, 0, 0), "N", true)
- start()
Advertisement
Add Comment
Please, Sign In to add comment