SHARE
TWEET

Lava collector

le_Fish Aug 19th, 2019 (edited) 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- A bot to drain as much as lava as possible from the nether world
  2.  
  3. if fs.exists("extraFuncsApi") then
  4.     os.loadAPI("extraFuncsApi")
  5. else
  6.     shell.run("pastebin", "get", "5MwHEZxB", "extraFuncsApi")
  7.     os.loadAPI("extraFuncsApi")
  8. end
  9. if fs.exists("serverApi") then
  10.     os.loadAPI("serverApi")
  11. else
  12.     shell.run("pastebin", "get", "dazENzF5", "serverApi")
  13.     os.loadAPI("serverApi")
  14. end
  15. if fs.exists("facilityApi") then
  16.     os.loadAPI("facilityApi")
  17. else
  18.     shell.run("pastebin", "get", "Eyrmtw0m", "facilityApi")
  19.     os.loadAPI("facilityApi")
  20. end
  21.  
  22. local lava_turtle = extraFuncsApi.extraFuncs:new(vector.new(0, 0, 0), "N", true)
  23.  
  24. local bucket = peripheral.wrap("left")
  25.  
  26. local lava_collector_data = {
  27.     home = vector.new(0, 0, 0),
  28.     lava_counter = 0
  29. }
  30.  
  31. function init()
  32.     local this_facility = facilityApi.facility:join("lava_collector")
  33.     if this_facility ~= false then
  34.         this_computer = serverApi.slave:new("lavaCollector", "lava_collector")
  35.         if this_computer:is_registered() == false then
  36.             if this_computer:register() == true then
  37.                 print("Lava turtle has been registered")
  38.             else
  39.                 error("Couldn't register Lava turtle")
  40.             end
  41.         else
  42.             print("Turtle seems to already be registered?")
  43.         end
  44.         read_lava_collector_data()
  45.         lava_turtle:read_pos()
  46.         collectLava()
  47.     end
  48. end
  49.  
  50. function collectLava()
  51.     while true do
  52.         if checkDown() == "lava" then
  53.             repeat
  54.                 getLava("down")
  55.                 lava_turtle:down()
  56.                 lava_turtle:save_pos()
  57.             until checkDown() == "something"
  58.             goToZ(lava_collector_data.home)
  59.         end
  60.         if checkLava() == "lava" then
  61.             getLava("")
  62.             lava_turtle:forward()
  63.             lava_turtle:save_pos()
  64.         elseif checkLava() == "something" then
  65.             if lava_turtle.turtle_pos.x % 2 == 0 then
  66.                 lava_turtle:left()
  67.                 lava_turtle:forward()
  68.                 lava_turtle:left()
  69.                 lava_turtle:save_pos()
  70.             else
  71.                 lava_turtle:right()
  72.                 lava_turtle:forward()
  73.                 lava_turtle:right()
  74.                 lava_turtle:save_pos()
  75.             end
  76.         else
  77.             lava_turtle:forward()
  78.             lava_turtle:save_pos()
  79.         end
  80.     end
  81. end
  82.  
  83. function getLava(direction)
  84.     turtle.select(2)
  85.     local slot = 0
  86.     for i = 3, 16 do
  87.         local item_data = turtle.getItemDetail(i)
  88.         if item_data ~= nil and item_data.name ~= "minecraft:lava_bucket" then
  89.             slot = i
  90.             turtle.select(slot)
  91.             break
  92.         end
  93.     end
  94.     if slot == 0 then
  95.         for i = 3, 16 do
  96.             turtle.select(i)
  97.             local item_data = turtle.getItemDetail(i)
  98.             if item_data ~= nil and item_data.name == "minecraft:lava_bucket" then
  99.                 bucket.drain()
  100.                 local total_lava = bucket.getFluid()
  101.                 if tonumber(total_lava.amount) == 10000 then
  102.                     lava_turtle:left()
  103.                     lava_turtle:left()
  104.                     turtle.select(1)
  105.                     turtle.place()
  106.                     while true do
  107.                         bucket.empty()
  108.                         local new_count_lava = bucket.getFluid()
  109.                         if new_count_lava == nil or tonumber(new_count_lava.amount) == 0 then
  110.                             break
  111.                         end
  112.                         sleep(0.1)
  113.                     end
  114.  
  115.                     this_computer:send_log("Added 10000 mb of lava.", "info")
  116.                     turtle.select(2)
  117.                     turtle.equipLeft()
  118.                     turtle.select(1)
  119.                     turtle.dig()
  120.                     turtle.select(2)
  121.                     turtle.equipLeft()
  122.                     bucket = peripheral.wrap("left")
  123.                     turtle.select(3)
  124.                     lava_turtle:right()
  125.                     lava_turtle:right()
  126.                     lava_collector_data.lava_counter = lava_collector_data.lava_counter + 1
  127.                     save_lava_collector_data()
  128.                 end
  129.             end
  130.         end
  131.     end
  132.  
  133.     if direction == "down" then
  134.         turtle.placeDown()
  135.     elseif direction == "up" then
  136.         turtle.placeUp()
  137.     else
  138.         turtle.place()
  139.     end
  140. end
  141.  
  142. function save_lava_collector_data()
  143.     local h = fs.open("lava_collector_data", "w")
  144.     h.write(lava_collector_data.lava_counter)
  145.     h.close()
  146. end
  147.  
  148. function read_lava_collector_data()
  149.     if fs.exists("lava_collector_data") then
  150.         local h = fs.open("lava_collector_data", "r")
  151.         lava_collector_data.lava_counter = tonumber(readLine())
  152.         h.close()
  153.         return true
  154.     else
  155.         return false
  156.     end
  157. end
  158.  
  159. function checkLava()
  160.     local success, t = turtle.inspect()
  161.     if success then
  162.         if string.find(t.name, "lava") ~= nil then
  163.             return "lava"
  164.         else
  165.             return "something"
  166.         end
  167.     else
  168.         return "nothing"
  169.     end
  170. end
  171.  
  172. function checkDown()
  173.     local success, t = turtle.inspectDown()
  174.     if success then
  175.         if string.find(t.name, "lava") ~= nil then
  176.             return "lava"
  177.         else
  178.             return "something"
  179.         end
  180.     else
  181.         return "nothing"
  182.     end
  183. end
  184.  
  185. function goToZ(place)
  186.     if lava_turtle.turtle_pos.z ~= place.z then
  187.         if lava_turtle.turtle_pos.z > place.z then
  188.             while lava_turtle.turtle_pos.z ~= place.z do
  189.                 lava_turtle:down()
  190.             end
  191.         elseif lava_turtle.turtle_pos.z < place.z then
  192.             while lava_turtle.turtle_pos.z ~= place.z do
  193.                 lava_turtle:up()
  194.             end
  195.         end
  196.     end
  197. end
  198.  
  199. init()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top