Advertisement
le_Fish

Lava collector

Aug 19th, 2019
1,535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.81 KB | None | 0 0
  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.     read_lava_collector_data()
  33.     lava_turtle:read_pos()
  34.     collectLava()
  35.     -- local this_facility = facilityApi.facility:join("lava_collector")
  36.     -- if this_facility ~= false then
  37.     --     this_computer = serverApi.slave:new("lavaCollector", "lava_collector")
  38.     --     if this_computer:is_registered() == false then
  39.     --         if this_computer:register() == true then
  40.     --             print("Lava turtle has been registered")
  41.     --         else
  42.     --             error("Couldn't register Lava turtle")
  43.     --         end
  44.     --     else
  45.     --         print("Turtle seems to already be registered?")
  46.     --     end
  47.     --     read_lava_collector_data()
  48.     --     lava_turtle:read_pos()
  49.     --     collectLava()
  50.     -- end
  51. end
  52.  
  53. function collectLava()
  54.     while true do
  55.         if checkDown() == "lava" then
  56.             repeat
  57.                 getLava("down")
  58.                 lava_turtle:down()
  59.                 lava_turtle:save_pos()
  60.             until checkDown() == "something"
  61.             goToZ(lava_collector_data.home)
  62.         end
  63.         if checkLava() == "lava" then
  64.             getLava("")
  65.             lava_turtle:forward()
  66.             lava_turtle:save_pos()
  67.         elseif checkLava() == "something" then
  68.             if lava_turtle.turtle_pos.x % 2 == 0 then
  69.                 lava_turtle:left()
  70.                 lava_turtle:forward()
  71.                 lava_turtle:left()
  72.                 lava_turtle:save_pos()
  73.             else
  74.                 lava_turtle:right()
  75.                 lava_turtle:forward()
  76.                 lava_turtle:right()
  77.                 lava_turtle:save_pos()
  78.             end
  79.         else
  80.             lava_turtle:forward()
  81.             lava_turtle:save_pos()
  82.         end
  83.     end
  84. end
  85.  
  86. function getLava(direction)
  87.     turtle.select(2)
  88.     local slot = 0
  89.     for i = 3, 16 do
  90.         local item_data = turtle.getItemDetail(i)
  91.         if item_data ~= nil and item_data.name ~= "minecraft:lava_bucket" then
  92.             slot = i
  93.             turtle.select(slot)
  94.             break
  95.         end
  96.     end
  97.     if slot == 0 then
  98.         for i = 3, 16 do
  99.             turtle.select(i)
  100.             local item_data = turtle.getItemDetail(i)
  101.             if item_data ~= nil and item_data.name == "minecraft:lava_bucket" then
  102.                 bucket.drain()
  103.                 local total_lava = bucket.getFluid()
  104.                 if tonumber(total_lava.amount) == 10000 then
  105.                     lava_turtle:left()
  106.                     lava_turtle:left()
  107.                     turtle.select(1)
  108.                     turtle.place()
  109.                     while true do
  110.                         bucket.empty()
  111.                         local new_count_lava = bucket.getFluid()
  112.                         if new_count_lava == nil or tonumber(new_count_lava.amount) == 0 then
  113.                             break
  114.                         end
  115.                         sleep(0.1)
  116.                     end
  117.  
  118.                     this_computer:send_log("Added 10000 mb of lava.", "info")
  119.                     turtle.select(2)
  120.                     turtle.equipLeft()
  121.                     turtle.select(1)
  122.                     turtle.dig()
  123.                     turtle.select(2)
  124.                     turtle.equipLeft()
  125.                     bucket = peripheral.wrap("left")
  126.                     turtle.select(3)
  127.                     lava_turtle:right()
  128.                     lava_turtle:right()
  129.                     lava_collector_data.lava_counter = lava_collector_data.lava_counter + 1
  130.                     save_lava_collector_data()
  131.                 end
  132.             end
  133.         end
  134.     end
  135.  
  136.     if direction == "down" then
  137.         turtle.placeDown()
  138.     elseif direction == "up" then
  139.         turtle.placeUp()
  140.     else
  141.         turtle.place()
  142.     end
  143. end
  144.  
  145. function save_lava_collector_data()
  146.     local h = fs.open("lava_collector_data", "w")
  147.     h.write(lava_collector_data.lava_counter)
  148.     h.close()
  149. end
  150.  
  151. function read_lava_collector_data()
  152.     if fs.exists("lava_collector_data") then
  153.         local h = fs.open("lava_collector_data", "r")
  154.         lava_collector_data.lava_counter = tonumber(readLine())
  155.         h.close()
  156.         return true
  157.     else
  158.         return false
  159.     end
  160. end
  161.  
  162. function checkLava()
  163.     local success, t = turtle.inspect()
  164.     if success then
  165.         if string.find(t.name, "lava") ~= nil then
  166.             return "lava"
  167.         else
  168.             return "something"
  169.         end
  170.     else
  171.         return "nothing"
  172.     end
  173. end
  174.  
  175. function checkDown()
  176.     local success, t = turtle.inspectDown()
  177.     if success then
  178.         if string.find(t.name, "lava") ~= nil then
  179.             return "lava"
  180.         else
  181.             return "something"
  182.         end
  183.     else
  184.         return "nothing"
  185.     end
  186. end
  187.  
  188. function goToZ(place)
  189.     if lava_turtle.turtle_pos.z ~= place.z then
  190.         if lava_turtle.turtle_pos.z > place.z then
  191.             while lava_turtle.turtle_pos.z ~= place.z do
  192.                 lava_turtle:down()
  193.             end
  194.         elseif lava_turtle.turtle_pos.z < place.z then
  195.             while lava_turtle.turtle_pos.z ~= place.z do
  196.                 lava_turtle:up()
  197.             end
  198.         end
  199.     end
  200. end
  201.  
  202. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement