Advertisement
Guest User

digger

a guest
Sep 20th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.92 KB | None | 0 0
  1. local distance = 0
  2. local torches = -1
  3. local TD = nil
  4. local length = nil
  5. term.clear()
  6. term.setCursorPos(4,7)
  7.     print("**Minenassist Scrayos**")
  8. term.setCursorPos(12,15)
  9.     print("*ALPHA*")
  10. os.sleep(2)
  11. term.clear()
  12. term.setCursorPos(1,1)
  13. while not length do
  14.     print("Tunnel length?")
  15.     length = tonumber(read())
  16.     if not length then
  17.         print("Please enter a Integer 1,2,3...")
  18.     end
  19. end
  20. while not TD do
  21.     print("Blocks between torches?")
  22.     TD = tonumber(read())
  23.     if not TD then
  24.         print("Please enter a Integer 1,2,3...")
  25.     end
  26. end
  27. term.clear()
  28. term.setCursorPos(1,1)
  29. local torchNum = turtle.getItemCount(15)
  30.     print("Ok starting tunnel...")
  31. term.setCursorPos(1,3)
  32.     print(length .. " blocks long torches every " .. (TD)+1 ..  " blocks")
  33. term.setCursorPos(1,5)
  34.     print("Hold Ctrl + T at any time to cancel")
  35. os.sleep(1)
  36. term.setCursorPos(1,7)
  37. turtle.select(1)
  38.  
  39. function d()
  40.     while turtle.detect(true) do
  41.         turtle.dig()
  42.     end
  43. end
  44.  
  45. --Custom digUp function
  46. function du()
  47.     while turtle.detectUp(true) do
  48.         turtle.digUp()
  49.     end
  50. end
  51.  
  52. --Custom forward function
  53. function mf()
  54.     while not turtle.forward() do
  55.       if not turtle.dig() then
  56.         turtle.attack()
  57.       end
  58.     end
  59. end
  60.  
  61. --Custom up function
  62. function mu()
  63.     while not turtle.up() do
  64.         if not turtle.digUp() then
  65.             turtle.attackUp()
  66.         end
  67.     end
  68. end
  69.  
  70. --Custom down function
  71. function md()
  72.   while not turtle.down() do
  73.     if not turtle.digDown() then
  74.         turtle.attackDown()
  75.     end
  76.   end
  77. end
  78.  
  79. --Return function
  80. function back()
  81.     if distance ~= nil then
  82.         distance = tonumber(distance)
  83.         while turtle.getFuelLevel() < distance do
  84.             refuel()
  85.         end
  86.         for i = 1, distance do
  87.             mf()
  88.         end
  89.     end
  90. end
  91.  
  92.  
  93. --Empty function
  94. function empty()
  95.     if turtle.getItemCount(14) ~= 0 then
  96.         mu()
  97.         mu()
  98.         turtle.turnRight()
  99.         turtle.turnRight()
  100.         back()
  101.         md()
  102.         md()
  103.         for i = 1,14 do
  104.             turtle.select(i)
  105.             if turtle.detect(true) then
  106.                 turtle.drop()
  107.             end
  108.         end
  109.         mu()
  110.         mu()
  111.         turtle.turnRight()
  112.         turtle.turnRight()
  113.         back()
  114.         md()
  115.         md()
  116.         turtle.select(1)
  117.     end
  118. end
  119.    
  120. --Refuel function
  121. function refuel()
  122. end
  123. --Torch placing function
  124. function placeTorch()
  125.     if torchNum > 0 then
  126.         if tonumber(TD) == tonumber(torches) then
  127.             turtle.turnLeft()
  128.             turtle.turnLeft()
  129.             turtle.select(15)
  130.             turtle.place()
  131.             torchNum = torchNum - 1
  132.             turtle.select(1)
  133.             turtle.turnLeft()
  134.             turtle.turnLeft()
  135.             torches = -1
  136.             print("Fuel level is " .. turtle.getFuelLevel())
  137.         end
  138.     else
  139.          local i = 0
  140.          print("NO TORCHES")
  141.          print("Place torches in slot 15 and press ENTER")
  142.          while i == 0 do
  143.             local sEvent, keystroke = os.pullEvent("key")
  144.             if sEvent == "key" then
  145.                 if keystroke == 28 then
  146.                     torchNum = tonumber(turtle.getItemCount(15))
  147.                     placeTorch()
  148.                     i = 1
  149.                 end
  150.             end
  151.         end
  152.     end
  153. end
  154.  
  155. --Main Loop
  156. while tonumber(distance) < tonumber(length) do
  157.     placeTorch()
  158.     refuel()
  159.     empty()
  160.     d()
  161.     mf()
  162.     torches = torches + 1
  163.     distance = distance + 1
  164.     print("Tunneled " .. distance .. " blocks")
  165.     du()
  166.     turtle.turnLeft()
  167.     d()
  168.     mu()
  169.     du()
  170.     d()
  171.     du()
  172.     mu()
  173.     d()
  174.     turtle.turnRight()
  175.     turtle.turnRight()
  176.     d()
  177.     md()
  178.     d()
  179.     md()
  180.     d()
  181.     turtle.turnLeft()
  182.     turtle.turnLeft()
  183.     d()
  184.     turtle.turnRight()
  185. end
  186.  
  187. --Empty inventory when done
  188. mu()
  189. mu()
  190. turtle.turnRight()
  191. turtle.turnRight()
  192. back()
  193. md()
  194. md()
  195. for i = 1,14 do
  196.     turtle.select(i)
  197.     if turtle.detect(true) then
  198.         turtle.drop()
  199.     end
  200. end
  201. turtle.turnRight()
  202. turtle.turnRight()
  203. term.clear()
  204. term.setCursorPos(1,1)
  205. print("Tunnel Complete " .. distance .. " blocks long")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement