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_turtle = extraFuncsApi.extraFuncs:new(vector.new(0, 0, 0), "N", true)
- local bucket = peripheral.wrap("left")
- local lava_collector_data = {
- home = vector.new(0, 0, 0),
- lava_counter = 0
- }
- function init()
- read_lava_collector_data()
- lava_turtle:read_pos()
- collectLava()
- -- local this_facility = facilityApi.facility:join("lava_collector")
- -- if this_facility ~= false 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")
- -- else
- -- error("Couldn't register Lava turtle")
- -- end
- -- else
- -- print("Turtle seems to already be registered?")
- -- end
- -- read_lava_collector_data()
- -- lava_turtle:read_pos()
- -- collectLava()
- -- end
- end
- function collectLava()
- while true do
- if checkDown() == "lava" then
- repeat
- getLava("down")
- lava_turtle:down()
- lava_turtle:save_pos()
- until checkDown() == "something"
- goToZ(lava_collector_data.home)
- end
- if checkLava() == "lava" then
- getLava("")
- lava_turtle:forward()
- lava_turtle:save_pos()
- elseif checkLava() == "something" then
- if lava_turtle.turtle_pos.x % 2 == 0 then
- lava_turtle:left()
- lava_turtle:forward()
- lava_turtle:left()
- lava_turtle:save_pos()
- else
- lava_turtle:right()
- lava_turtle:forward()
- lava_turtle:right()
- lava_turtle:save_pos()
- end
- else
- lava_turtle:forward()
- lava_turtle:save_pos()
- end
- end
- end
- function getLava(direction)
- turtle.select(2)
- local slot = 0
- for i = 3, 16 do
- local item_data = turtle.getItemDetail(i)
- if item_data ~= nil and item_data.name ~= "minecraft:lava_bucket" then
- slot = i
- turtle.select(slot)
- break
- end
- end
- if slot == 0 then
- for i = 3, 16 do
- turtle.select(i)
- local item_data = turtle.getItemDetail(i)
- if item_data ~= nil and item_data.name == "minecraft:lava_bucket" then
- bucket.drain()
- local total_lava = bucket.getFluid()
- if tonumber(total_lava.amount) == 10000 then
- lava_turtle:left()
- lava_turtle:left()
- turtle.select(1)
- turtle.place()
- while true do
- bucket.empty()
- local new_count_lava = bucket.getFluid()
- if new_count_lava == nil or tonumber(new_count_lava.amount) == 0 then
- break
- end
- sleep(0.1)
- end
- this_computer:send_log("Added 10000 mb of lava.", "info")
- turtle.select(2)
- turtle.equipLeft()
- turtle.select(1)
- turtle.dig()
- turtle.select(2)
- turtle.equipLeft()
- bucket = peripheral.wrap("left")
- turtle.select(3)
- lava_turtle:right()
- lava_turtle:right()
- lava_collector_data.lava_counter = lava_collector_data.lava_counter + 1
- save_lava_collector_data()
- end
- end
- end
- end
- if direction == "down" then
- turtle.placeDown()
- elseif direction == "up" then
- turtle.placeUp()
- else
- turtle.place()
- end
- end
- function save_lava_collector_data()
- local h = fs.open("lava_collector_data", "w")
- h.write(lava_collector_data.lava_counter)
- h.close()
- end
- function read_lava_collector_data()
- if fs.exists("lava_collector_data") then
- local h = fs.open("lava_collector_data", "r")
- lava_collector_data.lava_counter = tonumber(readLine())
- h.close()
- return true
- 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 lava_turtle.turtle_pos.z ~= place.z then
- if lava_turtle.turtle_pos.z > place.z then
- while lava_turtle.turtle_pos.z ~= place.z do
- lava_turtle:down()
- end
- elseif lava_turtle.turtle_pos.z < place.z then
- while lava_turtle.turtle_pos.z ~= place.z do
- lava_turtle:up()
- end
- end
- end
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement