le_Fish

Lava collector V2

Feb 5th, 2020
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.49 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. print("Ender chest slot 1, pickaxe slot 2")
  33.  
  34. if not fs.exists("startup") then
  35. print("Making startup file")
  36. local h = fs.open("startup", "w")
  37. h.writeLine("sleep(1)")
  38. h.writeLine("shell.run('" .. shell.getRunningProgram() .. "')")
  39. h.close()
  40. end
  41.  
  42.  
  43. if(read_lava_collector_data() == false) then
  44. save_lava_collector_data()
  45. end
  46. lava_turtle:read_pos()
  47.  
  48. collectLava()
  49. end
  50.  
  51. function collectLava()
  52. while true do
  53. if checkDown() == "lava" then
  54. repeat
  55. getLava("down")
  56. lava_turtle:down()
  57. print("whent down")
  58. lava_turtle:save_pos()
  59. until checkDown() == "something"
  60. goToZ(lava_collector_data.home)
  61. end
  62. -- Get lava or Turn
  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:right()
  70. lava_turtle:forward()
  71. lava_turtle:right()
  72. lava_turtle:save_pos()
  73. else
  74. lava_turtle:left()
  75. lava_turtle:forward()
  76. lava_turtle:left()
  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. sendLava()
  88. if direction == "down" then
  89. if checkDown() == "lava" then
  90. print("Saw lava")
  91. while bucket.suckDown() == false do
  92. bucket = peripheral.wrap("left")
  93. bucket.suckDown()
  94. end
  95. print("Should've sucked")
  96. end
  97. elseif direction == "up" then
  98. if checkUp() == "lava" then
  99. print("Saw lava")
  100. while bucket.suckUp() == false do
  101. bucket = peripheral.wrap("left")
  102. bucket.suckUp()
  103. end
  104. print("Should've sucked")
  105. end
  106. else
  107. if checkLava() == "lava" then
  108. print("Saw lava")
  109. while bucket.suck() == false do
  110. bucket = peripheral.wrap("left")
  111. bucket.suck()
  112. end
  113. print("Should've sucked")
  114. end
  115. end
  116. sleep(0.2)
  117. if bucket.getFluid() ~= nil then
  118. print(tonumber(bucket.getFluid().amount))
  119. end
  120. end
  121.  
  122. function sendLava()
  123. if bucket.getFluid() ~= nil and tonumber(bucket.getFluid().amount) == 8000 then
  124. lava_turtle:left()
  125. lava_turtle:left()
  126. turtle.select(1)
  127. while turtle.placeUp() == false do
  128. turtle.digUp()
  129. turtle.suckUp()
  130. turtle.placeUp()
  131. end
  132. while tonumber(peripheral.wrap("left").getFluid().amount) ~= 0 or peripheral.wrap("left").getFluid() ~= nil do
  133. bucket = peripheral.wrap("left")
  134. bucket.emptyUp()
  135. print(tonumber(bucket.getFluid().amount))
  136. sleep(0.1)
  137. end
  138. turtle.select(2)
  139. turtle.equipLeft()
  140. turtle.select(1)
  141. turtle.digUp()
  142. turtle.select(2)
  143. turtle.equipLeft()
  144. bucket = peripheral.wrap("left")
  145. lava_turtle:right()
  146. lava_turtle:right()
  147. lava_collector_data.lava_counter = lava_collector_data.lava_counter + 1
  148. save_lava_collector_data()
  149. end
  150. end
  151.  
  152. function save_lava_collector_data()
  153. local h = fs.open("lava_collector_data", "w")
  154. h.write(tonumber(lava_collector_data.lava_counter))
  155. h.close()
  156. end
  157. function read_lava_collector_data()
  158. if fs.exists("lava_collector_data") then
  159. local h = fs.open("lava_collector_data", "r")
  160. lava_collector_data.lava_counter = tonumber(readLine())
  161. h.close()
  162. return true
  163. else
  164. return false
  165. end
  166. end
  167.  
  168. function checkLava()
  169. local success, t = turtle.inspect()
  170. if success then
  171. if string.find(t.name, "lava") ~= nil then
  172. return "lava"
  173. else
  174. return "something"
  175. end
  176. else
  177. return "nothing"
  178. end
  179. end
  180. function checkDown()
  181. local success, t = turtle.inspectDown()
  182. if success then
  183. if string.find(t.name, "lava") ~= nil then
  184. return "lava"
  185. else
  186. return "something"
  187. end
  188. else
  189. return "nothing"
  190. end
  191. end
  192. function checkUp()
  193. local success, t = turtle.inspectUp()
  194. if success then
  195. if string.find(t.name, "lava") ~= nil then
  196. return "lava"
  197. else
  198. return "something"
  199. end
  200. else
  201. return "nothing"
  202. end
  203. end
  204.  
  205. function goToZ(place)
  206. if lava_turtle.turtle_pos.z ~= place.z then
  207. if lava_turtle.turtle_pos.z > place.z then
  208. while lava_turtle.turtle_pos.z ~= place.z do
  209. lava_turtle:down()
  210. end
  211. elseif lava_turtle.turtle_pos.z < place.z then
  212. while lava_turtle.turtle_pos.z ~= place.z do
  213. lava_turtle:up()
  214. end
  215. end
  216. end
  217. end
  218.  
  219. init()
Advertisement
Add Comment
Please, Sign In to add comment