Advertisement
le_Fish

Lava collector v3

Feb 5th, 2020
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.34 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 current_task = ""
  25.  
  26. local lava_collector_data = {
  27. home = vector.new(0, 0, 0),
  28. lava_counter = 0
  29. }
  30.  
  31. function init()
  32. changeTask("Init ")
  33. print("Ender chest slot 1 & 2, pickaxe slot 3")
  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. if(read_lava_collector_data() == false) then
  42. save_lava_collector_data()
  43. end
  44. lava_turtle:read_pos()
  45. local success, data = turtle.inspectUp()
  46. if success and data.name == "EnderStorage:enderChest" then
  47. if turtle.getItemCount(1) == 0 then
  48. if not turtle.digUp() then
  49. error("Couldnt dig up")
  50. end
  51. turtle.select(3)
  52. elseif turtle.getItemCount(2) == 0 then
  53. if not turtle.digUp() then
  54. error("Couldnt dig up")
  55. end
  56. turtle.select(3)
  57. end
  58. end
  59. collectLava()
  60. end
  61.  
  62. function collectLava()
  63. while true do
  64. changeTask("Collect lava ")
  65.  
  66. if checkDown() == "lava" and getLava("down") == true then
  67. changeTask("Getting lava downwards ")
  68. repeat
  69. lava_turtle:down()
  70. printInfo()
  71. lava_turtle:save_pos()
  72. until checkDown() == "something" or getLava("down") == false
  73. goToZ(lava_collector_data.home)
  74. end
  75. -- Get lava or Turn
  76. if checkLava() == "lava" and getLava("") == true then
  77. lava_turtle:forward()
  78. printInfo()
  79. lava_turtle:save_pos()
  80. elseif checkLava() == "something" then
  81. changeTask("Turning")
  82. lava_turtle:save_pos()
  83. if lava_turtle.pos.x % 2 == 0 then
  84. lava_turtle:right()
  85. if lava_turtle:forward() then
  86. lava_turtle:save_pos()
  87. printInfo()
  88. lava_turtle:right()
  89. lava_turtle:save_pos()
  90. printInfo()
  91. else
  92. lava_turtle:left()
  93. printInfo()
  94. while 1 do
  95. lava_turtle:back()
  96. printInfo()
  97. lava_turtle:right()
  98. printInfo()
  99. if lava_turtle:forward() then
  100. printInfo()
  101. break
  102. else
  103. lava_turtle:left()
  104. printInfo()
  105. end
  106. end
  107. lava_turtle:right()
  108. printInfo()
  109.  
  110. end
  111.  
  112. lava_turtle:save_pos()
  113. else
  114. lava_turtle:left()
  115. printInfo()
  116. if lava_turtle:forward() then
  117. lava_turtle:left()
  118. printInfo()
  119. else
  120. lava_turtle:right()
  121. printInfo()
  122. while 1 do
  123. lava_turtle:back()
  124. printInfo()
  125. lava_turtle:left()
  126. printInfo()
  127. if lava_turtle:forward() then
  128. printInfo()
  129. break
  130. else
  131. lava_turtle:right()
  132. printInfo()
  133. end
  134. end
  135. lava_turtle:left()
  136. printInfo()
  137. end
  138. lava_turtle:save_pos()
  139. end
  140. else
  141. lava_turtle:forward()
  142. printInfo()
  143. lava_turtle:save_pos()
  144. end
  145. end
  146. end
  147.  
  148. function getLava(direction)
  149. turtle.select(2)
  150. local slot = 0
  151. for i = 3, 16 do
  152. local item_data = turtle.getItemDetail(i)
  153. if item_data ~= nil and item_data.name ~= "minecraft:lava_bucket" then
  154. slot = i
  155. turtle.select(slot)
  156. break
  157. end
  158. end
  159. if slot == 0 then
  160. emptyLava()
  161. turtle.select(3)
  162. end
  163.  
  164. if direction == "down" then
  165. turtle.placeDown()
  166. elseif direction == "up" then
  167. turtle.placeUp()
  168. else
  169. turtle.place()
  170. end
  171.  
  172. if slot ~= 0 and turtle.getItemDetail(slot) ~= nil and turtle.getItemDetail(slot).name ~= "minecraft:lava_bucket" then
  173. return false
  174. end
  175. return true
  176. end
  177.  
  178. function emptyLava()
  179. turtle.select(1)
  180. if turtle.getItemDetail(1) ~= nil and turtle.getItemDetail(1).name ~= "EnderStorage:enderChest" then
  181. error("Missing enderchest on spot 1")
  182. end
  183. while turtle.placeUp() == false do
  184. turtle.digUp()
  185. turtle.placeUp()
  186. end
  187. for i = 3, 16 do
  188. turtle.select(i)
  189. turtle.dropUp(1)
  190. end
  191. turtle.select(1)
  192. turtle.digUp()
  193. if turtle.getItemDetail(1) ~= nil and turtle.getItemDetail(1).name ~= "EnderStorage:enderChest" then
  194. error("Missing enderchest on spot 1")
  195. end
  196. turtle.select(2)
  197. if turtle.getItemDetail(2) ~= nil and turtle.getItemDetail(2).name ~= "EnderStorage:enderChest" then
  198. error("Missing enderchest on spot 2")
  199. end
  200. while turtle.placeUp() == false do
  201. turtle.digUp()
  202. turtle.placeUp()
  203. end
  204. for i = 3, 16 do
  205. turtle.select(i)
  206. turtle.suckUp(1)
  207. end
  208. turtle.select(2)
  209. turtle.digUp()
  210. if turtle.getItemDetail(2) ~= nil and turtle.getItemDetail(2).name ~= "EnderStorage:enderChest" then
  211. error("Missing enderchest on spot 2")
  212. end
  213.  
  214. lava_collector_data.lava_counter = lava_collector_data.lava_counter + 1
  215. save_lava_collector_data()
  216. end
  217.  
  218. function save_lava_collector_data()
  219. local h = fs.open("lava_collector_data", "w")
  220. h.write(tonumber(lava_collector_data.lava_counter))
  221. h.close()
  222. end
  223. function read_lava_collector_data()
  224. if fs.exists("lava_collector_data") then
  225. local h = fs.open("lava_collector_data", "r")
  226. lava_collector_data.lava_counter = tonumber(h.readLine())
  227. h.close()
  228. return true
  229. else
  230. return false
  231. end
  232. end
  233.  
  234. function checkLava()
  235. local success, t = turtle.inspect()
  236. if success then
  237. if string.find(t.name, "lava") ~= nil then
  238. return "lava"
  239. else
  240. return "something"
  241. end
  242. else
  243. return "nothing"
  244. end
  245. end
  246. function checkDown()
  247. local success, t = turtle.inspectDown()
  248. if success then
  249. if string.find(t.name, "lava") ~= nil then
  250. return "lava"
  251. else
  252. return "something"
  253. end
  254. else
  255. return "nothing"
  256. end
  257. end
  258. function checkUp()
  259. local success, t = turtle.inspectUp()
  260. if success then
  261. if string.find(t.name, "lava") ~= nil then
  262. return "lava"
  263. else
  264. return "something"
  265. end
  266. else
  267. return "nothing"
  268. end
  269. end
  270.  
  271. function goToZ(place)
  272. if lava_turtle.pos.z ~= place.z then
  273. if lava_turtle.pos.z > place.z then
  274. while lava_turtle.pos.z ~= place.z do
  275. lava_turtle:down()
  276. end
  277. elseif lava_turtle.pos.z < place.z then
  278. while lava_turtle.pos.z ~= place.z do
  279. lava_turtle:up()
  280. end
  281. end
  282. end
  283. end
  284.  
  285. function printInfo()
  286. clearScreen()
  287. print("---------- LAVA BOY ---------")
  288. print("X: " .. lava_turtle.pos.x )
  289. print("Y: " .. lava_turtle.pos.y)
  290. print("Z: " .. lava_turtle.pos.z)
  291. print("Facing: " .. lava_turtle.dir)
  292. print("--------------------------------")
  293. print(current_task)
  294. print("--------------------------------")
  295. print("Lava farmed: " .. lava_collector_data.lava_counter)
  296. end
  297. function clearScreen()
  298. term.clear()
  299. term.setCursorPos(1,1)
  300. end
  301. function changeTask(task)
  302. current_task = task
  303. printInfo()
  304. end
  305.  
  306. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement