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 current_task = ""
- local lava_collector_data = {
- home = vector.new(0, 0, 0),
- lava_counter = 0
- }
- function init()
- changeTask("Init ")
- print("Ender chest slot 1 & 2, pickaxe slot 3")
- if not fs.exists("startup") then
- print("Making startup file")
- local h = fs.open("startup", "w")
- h.writeLine("sleep(1)")
- h.writeLine("shell.run('" .. shell.getRunningProgram() .. "')")
- h.close()
- end
- if(read_lava_collector_data() == false) then
- save_lava_collector_data()
- end
- lava_turtle:read_pos()
- local success, data = turtle.inspectUp()
- if success and data.name == "EnderStorage:enderChest" then
- if turtle.getItemCount(1) == 0 then
- if not turtle.digUp() then
- error("Couldnt dig up")
- end
- turtle.select(3)
- elseif turtle.getItemCount(2) == 0 then
- if not turtle.digUp() then
- error("Couldnt dig up")
- end
- turtle.select(3)
- end
- end
- collectLava()
- end
- function collectLava()
- while true do
- changeTask("Collect lava ")
- if checkDown() == "lava" and getLava("down") == true then
- changeTask("Getting lava downwards ")
- repeat
- lava_turtle:down()
- printInfo()
- lava_turtle:save_pos()
- until checkDown() == "something" or getLava("down") == false
- goToZ(lava_collector_data.home)
- end
- -- Get lava or Turn
- if checkLava() == "lava" and getLava("") == true then
- lava_turtle:forward()
- printInfo()
- lava_turtle:save_pos()
- elseif checkLava() == "something" then
- changeTask("Turning")
- lava_turtle:save_pos()
- if lava_turtle.pos.x % 2 == 0 then
- lava_turtle:right()
- if lava_turtle:forward() then
- lava_turtle:save_pos()
- printInfo()
- lava_turtle:right()
- lava_turtle:save_pos()
- printInfo()
- else
- lava_turtle:left()
- printInfo()
- while 1 do
- lava_turtle:back()
- printInfo()
- lava_turtle:right()
- printInfo()
- if lava_turtle:forward() then
- printInfo()
- break
- else
- lava_turtle:left()
- printInfo()
- end
- end
- lava_turtle:right()
- printInfo()
- end
- lava_turtle:save_pos()
- else
- lava_turtle:left()
- printInfo()
- if lava_turtle:forward() then
- lava_turtle:left()
- printInfo()
- else
- lava_turtle:right()
- printInfo()
- while 1 do
- lava_turtle:back()
- printInfo()
- lava_turtle:left()
- printInfo()
- if lava_turtle:forward() then
- printInfo()
- break
- else
- lava_turtle:right()
- printInfo()
- end
- end
- lava_turtle:left()
- printInfo()
- end
- lava_turtle:save_pos()
- end
- else
- lava_turtle:forward()
- printInfo()
- 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
- emptyLava()
- turtle.select(3)
- end
- if direction == "down" then
- turtle.placeDown()
- elseif direction == "up" then
- turtle.placeUp()
- else
- turtle.place()
- end
- if slot ~= 0 and turtle.getItemDetail(slot) ~= nil and turtle.getItemDetail(slot).name ~= "minecraft:lava_bucket" then
- return false
- end
- return true
- end
- function emptyLava()
- turtle.select(1)
- if turtle.getItemDetail(1) ~= nil and turtle.getItemDetail(1).name ~= "EnderStorage:enderChest" then
- error("Missing enderchest on spot 1")
- end
- while turtle.placeUp() == false do
- turtle.digUp()
- turtle.placeUp()
- end
- for i = 3, 16 do
- turtle.select(i)
- turtle.dropUp(1)
- end
- turtle.select(1)
- turtle.digUp()
- if turtle.getItemDetail(1) ~= nil and turtle.getItemDetail(1).name ~= "EnderStorage:enderChest" then
- error("Missing enderchest on spot 1")
- end
- turtle.select(2)
- if turtle.getItemDetail(2) ~= nil and turtle.getItemDetail(2).name ~= "EnderStorage:enderChest" then
- error("Missing enderchest on spot 2")
- end
- while turtle.placeUp() == false do
- turtle.digUp()
- turtle.placeUp()
- end
- for i = 3, 16 do
- turtle.select(i)
- turtle.suckUp(1)
- end
- turtle.select(2)
- turtle.digUp()
- if turtle.getItemDetail(2) ~= nil and turtle.getItemDetail(2).name ~= "EnderStorage:enderChest" then
- error("Missing enderchest on spot 2")
- end
- lava_collector_data.lava_counter = lava_collector_data.lava_counter + 1
- save_lava_collector_data()
- end
- function save_lava_collector_data()
- local h = fs.open("lava_collector_data", "w")
- h.write(tonumber(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(h.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 checkUp()
- local success, t = turtle.inspectUp()
- 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.pos.z ~= place.z then
- if lava_turtle.pos.z > place.z then
- while lava_turtle.pos.z ~= place.z do
- lava_turtle:down()
- end
- elseif lava_turtle.pos.z < place.z then
- while lava_turtle.pos.z ~= place.z do
- lava_turtle:up()
- end
- end
- end
- end
- function printInfo()
- clearScreen()
- print("---------- LAVA BOY ---------")
- print("X: " .. lava_turtle.pos.x )
- print("Y: " .. lava_turtle.pos.y)
- print("Z: " .. lava_turtle.pos.z)
- print("Facing: " .. lava_turtle.dir)
- print("--------------------------------")
- print(current_task)
- print("--------------------------------")
- print("Lava farmed: " .. lava_collector_data.lava_counter)
- end
- function clearScreen()
- term.clear()
- term.setCursorPos(1,1)
- end
- function changeTask(task)
- current_task = task
- printInfo()
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement