Advertisement
le_Fish

Lava Facility

Aug 19th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.04 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_collector_data = {
  23.     home = vector.new(0,0,0),
  24.     lava_counter = 0
  25. }
  26.  
  27. function init()
  28.     local this_facility = facilityApi.facility:join("lava_collector")
  29.     if this_facility.is_registered ~= nil then
  30.         this_computer = serverApi.slave:new("lavaCollector", "lava_collector")
  31.         if this_computer:is_registered() == false then
  32.             if this_computer:register() == true then
  33.                 print("Lava turtle has been registered")
  34.                 local lava_turtle = extraFuncsApi.extraFuncs:new(vector.new(0, 0, 0), "N", true)
  35.             else
  36.                 error("Couldn't register Lava turtle")
  37.             end
  38.         else
  39.             error("Turtle seems to already be registered?")
  40.         end
  41.         read_lava_collector_data()
  42.         lava_turtle:read_pos()
  43.         collectLava()
  44.     end
  45. end
  46.  
  47. function collectLava()
  48.     if checkDown() == "lava" then
  49.         repeat
  50.             getLava("down")
  51.             lava_turtle:down()
  52.             lava_turtle:save_pos()
  53.         until checkDown()  == "someting"
  54.         goToZ(lava_collector_data.home)
  55.     end
  56.     if checkLava() == "lava" then
  57.         getLava("")
  58.         lava_turtle:forward()
  59.         collectLava()
  60.     elseif checkLava() == "something" then
  61.         if lava_turtle.turtle_pos.x % 2 == 0 then
  62.             turtle:left()
  63.             turtle:forward()
  64.             turtle:left()
  65.             collectLava()
  66.         else
  67.             turtle:right()
  68.             turtle:forward()
  69.             turtle:right()
  70.             collectLava()
  71.         end
  72.     else
  73.         lava_turtle:forward()
  74.     end
  75. end
  76.  
  77. function getLava(direction)
  78.     turtle.select(2)
  79.     local slot = 0
  80.     for i=2,16 do
  81.         local item_data = turtle.getItemDetail(i)
  82.         if string.find(item_data.name, "lava_bucket") ~= true then
  83.             slot = i
  84.         end
  85.     end
  86.     if slot == 0 then
  87.         lave_turtle:left()
  88.         lava_turtle:left()
  89.         turtle.select(1)
  90.         turtle.place()
  91.         for i=2,16 do
  92.             turtle.select(i)
  93.             while turtle.place() == false do
  94.                 sleep(2)
  95.             end
  96.             lava_collector_data.lava_counter = lava_collector_data.lava_counter + 1
  97.             save_lava_collector_data()
  98.         end
  99.         this_computer:send_log("Added " .. lava_collector_data.lava_counter .. " buckets of lava.", "info")
  100.         turtle.select(1)
  101.         turtle.dig()
  102.         lava_turtle:right()
  103.         lava_turtle:right()
  104.         turtle.select(2)
  105.     end
  106.  
  107.     if direction == "down" then
  108.         local success, t = turtle.inspectDown()
  109.     elseif direction == "up" then
  110.         local success, t = turtle.inspectUp()
  111.     else
  112.         local success, t = turtle.inspect()
  113.     end
  114.  
  115.     if success then
  116.         if string.find(t.name, "lava") ~= nil then
  117.             if direction == "down" then
  118.                 turtle.placeDown()
  119.             elseif direction == "up" then
  120.                 turtle.placeUp()
  121.             else
  122.                 turtle.place()
  123.             end
  124.         end
  125.     end
  126. end
  127.  
  128. function save_lava_collector_data()
  129.     local h = fs.open("lava_collector_data", "w")
  130.     h.write(textutils.serialize(lava_collector_data))
  131.     h.close()
  132. end
  133.  
  134. function read_lava_collector_data()
  135.     if fs.exists("lava_collector_data") then
  136.         local h = fs.open("lava_collector_data", "r")
  137.         data = h.readAll()
  138.         h.close()
  139.         lava_collector_data = textutils.unserialize(data)
  140.         return lava_collector_data
  141.     else
  142.         return false
  143.     end
  144. end
  145.  
  146. function checkLava()
  147.     local success, t = turtle.inspect()
  148.     if success then
  149.         if string.find(t.name, "lava") ~= nil then
  150.             return "lava"
  151.         else
  152.             return "something"
  153.         end
  154.     else
  155.         return "nothing"
  156.     end
  157. end
  158.  
  159. function checkDown()
  160.     local success, t = turtle.inspectDown()
  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 goToZ(place)
  173.     if this_turtle.turtle_pos.z ~= place.z then
  174.         if this_turtle.turtle_pos.z > place.z then
  175.             while this_turtle.turtle_pos.z ~= place.z do
  176.                 this_turtle:down()
  177.             end
  178.         elseif this_turtle.turtle_pos.z < place.z then
  179.             while this_turtle.turtle_pos.z ~= place.z do
  180.                 this_turtle:up()
  181.             end
  182.         end
  183.     end
  184. end
  185.  
  186. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement