Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- A bot to drain as much as lava as possible from the nether world
- 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 lava_collector_data = {
- home = vector.new(0,0,0),
- lava_counter = 0
- }
- function init()
- local this_facility = facilityApi.facility:join("lava_collector")
- if this_facility.is_registered ~= nil then
- this_computer = serverApi.slave:new("lavaCollector", "lava_collector")
- if this_computer:is_registered() == false then
- if this_computer:register() == true then
- print("Lava turtle has been registered")
- local lava_turtle = extraFuncsApi.extraFuncs:new(vector.new(0, 0, 0), "N", true)
- else
- error("Couldn't register Lava turtle")
- end
- else
- error("Turtle seems to already be registered?")
- end
- read_lava_collector_data()
- lava_turtle:read_pos()
- collectLava()
- end
- end
- function collectLava()
- if checkDown() == "lava" then
- repeat
- getLava("down")
- lava_turtle:down()
- lava_turtle:save_pos()
- until checkDown() == "someting"
- goToZ(lava_collector_data.home)
- end
- if checkLava() == "lava" then
- getLava("")
- lava_turtle:forward()
- collectLava()
- elseif checkLava() == "something" then
- if lava_turtle.turtle_pos.x % 2 == 0 then
- turtle:left()
- turtle:forward()
- turtle:left()
- collectLava()
- else
- turtle:right()
- turtle:forward()
- turtle:right()
- collectLava()
- end
- else
- lava_turtle:forward()
- end
- end
- function getLava(direction)
- turtle.select(2)
- local slot = 0
- for i=2,16 do
- local item_data = turtle.getItemDetail(i)
- if string.find(item_data.name, "lava_bucket") ~= true then
- slot = i
- end
- end
- if slot == 0 then
- lave_turtle:left()
- lava_turtle:left()
- turtle.select(1)
- turtle.place()
- for i=2,16 do
- turtle.select(i)
- while turtle.place() == false do
- sleep(2)
- end
- lava_collector_data.lava_counter = lava_collector_data.lava_counter + 1
- save_lava_collector_data()
- end
- this_computer:send_log("Added " .. lava_collector_data.lava_counter .. " buckets of lava.", "info")
- turtle.select(1)
- turtle.dig()
- lava_turtle:right()
- lava_turtle:right()
- turtle.select(2)
- end
- if direction == "down" then
- local success, t = turtle.inspectDown()
- elseif direction == "up" then
- local success, t = turtle.inspectUp()
- else
- local success, t = turtle.inspect()
- end
- if success then
- if string.find(t.name, "lava") ~= nil then
- if direction == "down" then
- turtle.placeDown()
- elseif direction == "up" then
- turtle.placeUp()
- else
- turtle.place()
- end
- end
- end
- end
- function save_lava_collector_data()
- local h = fs.open("lava_collector_data", "w")
- h.write(textutils.serialize(lava_collector_data))
- h.close()
- end
- function read_lava_collector_data()
- if fs.exists("lava_collector_data") then
- local h = fs.open("lava_collector_data", "r")
- data = h.readAll()
- h.close()
- lava_collector_data = textutils.unserialize(data)
- return lava_collector_data
- else
- return false
- end
- end
- function checkLava()
- local success, t = turtle.inspect()
- if success then
- if string.find(t.name, "lava") ~= nil then
- return "lava"
- else
- return "something"
- end
- else
- return "nothing"
- end
- end
- function checkDown()
- local success, t = turtle.inspectDown()
- if success then
- if string.find(t.name, "lava") ~= nil then
- return "lava"
- else
- return "something"
- end
- else
- return "nothing"
- end
- end
- function goToZ(place)
- if this_turtle.turtle_pos.z ~= place.z then
- if this_turtle.turtle_pos.z > place.z then
- while this_turtle.turtle_pos.z ~= place.z do
- this_turtle:down()
- end
- elseif this_turtle.turtle_pos.z < place.z then
- while this_turtle.turtle_pos.z ~= place.z do
- this_turtle:up()
- end
- end
- end
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement