Advertisement
xmann110

miner

Feb 13th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. function has_value (tab, val)
  2.     for index, value in ipairs(tab) do
  3.         if value == val then
  4.             return true
  5.         end
  6.     end
  7.  
  8.     return false
  9. end
  10.  
  11. function refuel()
  12.     if turtle.getFuelLevel() < 10 then
  13.         print("Refueling")
  14.         turtle.select(1)
  15.         turtle.refuel(1)
  16.     end
  17. end
  18.  
  19. retrace = {}
  20. rares = {"minecraft:diamond_ore"}
  21.  
  22. print("Excavating ore vein")
  23. while true do
  24.     refuel()
  25.  
  26.     path_found = false
  27.  
  28.     a, b = turtle.inspect()
  29.     if a then print("Forward found " .. b.name) end
  30.  
  31.     if a and has_value(rares, b.name) then
  32.         print("Ore found forwards")
  33.         turtle.dig()
  34.         turtle.forward()
  35.         table.insert(retrace, "back")
  36.         path_found = true
  37.     else
  38.         a, b = turtle.inspectUp()
  39.         if a then print("Up found " .. b.name) end
  40.  
  41.         if a and has_value(rares, b.name) then
  42.             print("Ore found up")
  43.             turtle.digUp()
  44.             turtle.up()
  45.             table.insert(retrace, "down")
  46.             path_found = true
  47.         else
  48.             a, b = turtle.inspectDown()
  49.             if a then print("Down found " .. b.name) end
  50.  
  51.             if a and has_value(rares, b.name) then
  52.                 print("Ore found down")
  53.                 turtle.digDown()
  54.                 turtle.down()
  55.                 table.insert(retrace, "up")
  56.                 path_found = true
  57.             end
  58.         end
  59.     end
  60. end
  61.  
  62. for i, command in ipairs(retrace) do
  63.     print("Retracing, command: " .. command)
  64.     refuel()
  65.     if command == "up" then turtle.up() end
  66.     if command == "down" then turtle.down() end
  67.     if command == "left" then turtle.left() end
  68.     if command == "right" then turtle.right() end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement