andwmi

HappyTime

Dec 17th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.91 KB | None | 0 0
  1. --[[Tunneler Beta]]--
  2. --[[by Burton]]--
  3. --Fuel Slot is 16
  4. --Torch slot is 15
  5.  
  6. --To do
  7. --Variable height and width
  8. --Optional walls
  9. --Block off water/lava
  10.  
  11. --Set default variables
  12. local distance = 0
  13. local torches = -1
  14. local TD = nil
  15. local length = nil
  16.  
  17. --User set variables
  18. term.clear()
  19. term.setCursorPos(4,7)
  20.     print("**Welcome to Tunneler by Burton**")
  21. term.setCursorPos(12,13)
  22.     print("*Tunneler Beta*")
  23. os.sleep(2)
  24. term.clear()
  25. term.setCursorPos(3,2)
  26.     print("Place empty chest behind turtle")
  27. term.setCursorPos(3,4)
  28.     print("Place Chest with fuel to left of turtle")
  29. term.setCursorPos(3,6)
  30.     print("Place Chest with Torches to right of turtle")
  31. term.setCursorPos(3,8)
  32.     print("Place fuel in slot 16")
  33. term.setCursorPos(3,10)
  34.     print("Place torches in slot 15")
  35. os.sleep(5)
  36. term.clear()
  37. term.setCursorPos(1,1)
  38. while not length do
  39.     print("Tunnel length?")
  40.     length = tonumber(read())
  41.     if not length then
  42.         print("Please enter a Integer 1,2,3...")
  43.     end
  44. end
  45. while not TD do
  46.     print("Blocks between torches?")
  47.     TD = tonumber(read())
  48.     if not TD then
  49.         print("Please enter a Integer 1,2,3...")
  50.     end
  51. end
  52. term.clear()
  53. term.setCursorPos(1,1)
  54. local torchNum = turtle.getItemCount(15)
  55.     print("Ok starting tunnel...")
  56. term.setCursorPos(1,3)
  57.     print(length .. " blocks long torches every " .. (TD)+1 ..  " blocks")
  58. term.setCursorPos(1,5)
  59.     print("Hold Ctrl + T at any time to cancel")
  60. os.sleep(1)
  61. term.setCursorPos(1,7)
  62. turtle.select(1)
  63.  
  64. --Custom dig function
  65. function d()
  66.     while turtle.detect(true) do
  67.         turtle.dig()
  68.     end
  69. end
  70.  
  71. --Custom digUp function
  72. function du()
  73.     while turtle.detectUp(true) do
  74.         turtle.digUp()
  75.     end
  76. end
  77.  
  78. --Custom forward function
  79. function mf()
  80.     while not turtle.forward() do
  81.       if not turtle.dig() then
  82.         turtle.attack()
  83.       end
  84.     end
  85. end
  86.  
  87. --Custom up function
  88. function mu()
  89.     while not turtle.up() do
  90.         if not turtle.digUp() then
  91.             turtle.attackUp()
  92.         end
  93.     end
  94. end
  95.  
  96. --Custom down function
  97. function md()
  98.   while not turtle.down() do
  99.     if not turtle.digDown() then
  100.         turtle.attackDown()
  101.     end
  102.   end
  103. end
  104.  
  105. --Return function
  106. function back()
  107.     if distance ~= nil then
  108.         distance = tonumber(distance)
  109.         while turtle.getFuelLevel() < distance do
  110.             refuel()
  111.         end
  112.         for i = 1, distance do
  113.             mf()
  114.         end
  115.     end
  116. end
  117.  
  118.  
  119. --Empty function
  120. function empty()
  121.     if turtle.getItemCount(14) ~= 0 then
  122.         mu()
  123.         mu()
  124.         turtle.turnRight()
  125.         turtle.turnRight()
  126.         back()
  127.         md()
  128.         md()
  129.         for i = 1,14 do
  130.             turtle.select(i)
  131.             if turtle.detect(true) then
  132.                 turtle.drop()
  133.             end
  134.         end
  135.         mu()
  136.         mu()
  137.         turtle.turnRight()
  138.         turtle.turnRight()
  139.         back()
  140.         md()
  141.         md()
  142.         turtle.select(1)
  143.     end
  144. end
  145.    
  146. --Refuel function
  147. function refuel()
  148.     while tonumber(turtle.getFuelLevel()) < tonumber(length) do
  149.         for i = 1,14 do
  150.             turtle.select(i)
  151.             if turtle.compareTo(16) then
  152.                 turtle.transferTo(16)
  153.                 turtle.select(1)
  154.             end
  155.         end
  156.         turtle.select(16)
  157.         if turtle.refuel(0) then
  158.             print("Fuel level low ...Refuelling.")
  159.             turtle.refuel(1)
  160.             turtle.select(1)
  161.         else
  162.             mu()
  163.             mu()
  164.             turtle.turnRight()
  165.             turtle.turnRight()
  166.             back()
  167.             md()
  168.             md()
  169.             turtle.turnRight()
  170.             turtle.select(16)
  171.             turtle.suck(64)
  172.             if turtle.getItemCount(16) == 0 then
  173.                 local i = 0
  174.                 print("FUEL LEVEL LOW")
  175.                 print("Place fuel in slot 16 and press ENTER")
  176.                 while i == 0 do
  177.                     local sEvent, keystroke = os.pullEvent("key")
  178.                     if sEvent == "key" then
  179.                         if keystroke == 28 then
  180.                             refuel()
  181.                             i = 1
  182.                         end
  183.                     end
  184.                 end
  185.             end
  186.             turtle.select(1)
  187.             turtle.turnRight()
  188.             mu()
  189.             mu()
  190.             back()
  191.             md()
  192.             md()
  193.         end
  194.     end
  195. end
  196.  
  197. --Torch placing function
  198. function placeTorch()
  199.     if torchNum > 0 then
  200.         if tonumber(TD) == tonumber(torches) then
  201.             turtle.turnLeft()
  202.             turtle.turnLeft()
  203.             turtle.select(15)
  204.             turtle.place()
  205.             torchNum = torchNum - 1
  206.             turtle.select(1)
  207.             turtle.turnLeft()
  208.             turtle.turnLeft()
  209.             torches = -1
  210.             print("Fuel level is " .. turtle.getFuelLevel())
  211.         end
  212.     else
  213.         mu()
  214.         mu()
  215.         turtle.turnRight()
  216.         turtle.turnRight()
  217.         back()
  218.         md()
  219.         md()
  220.         turtle.turnLeft()
  221.         turtle.select(15)
  222.         turtle.suck(64)
  223.         if turtle.getItemCount(15) == 0 then
  224.             local i = 0
  225.             print("No Torches")
  226.             print("Place Torches in slot 15 and press ENTER")
  227.             while i == 0 do
  228.                 local sEvent, keystroke = os.pullEvent("key")
  229.                 if sEvent == "key" then
  230.                     if keystroke == 28 then
  231.                         i = 1
  232.                     end
  233.                 end
  234.             end
  235.         end
  236.         turtle.select(1)
  237.         turtle.turnLeft()
  238.         mu()
  239.         mu()
  240.         back()
  241.         md()
  242.         md()
  243.     end
  244. end
  245.  
  246. --Main Loop
  247. while tonumber(distance) < tonumber(length) do
  248.     placeTorch()
  249.     refuel()
  250.     empty()
  251.     d()
  252.     mf()
  253.     torches = torches + 1
  254.     distance = distance + 1
  255.     print("Tunneled " .. distance .. " blocks")
  256.     du()
  257.     turtle.turnLeft()
  258.     d()
  259.     mu()
  260.     du()
  261.     d()
  262.     du()
  263.     mu()
  264.     d()
  265.     turtle.turnRight()
  266.     turtle.turnRight()
  267.     d()
  268.     md()
  269.     d()
  270.     md()
  271.     d()
  272.     turtle.turnLeft()
  273.     turtle.turnLeft()
  274.     d()
  275.     turtle.turnRight()
  276. end
  277.  
  278. --Empty inventory when done
  279. mu()
  280. mu()
  281. turtle.turnRight()
  282. turtle.turnRight()
  283. back()
  284. md()
  285. md()
  286. for i = 1,14 do
  287.     turtle.select(i)
  288.     if turtle.detect(true) then
  289.         turtle.drop()
  290.     end
  291. end
  292. turtle.turnRight()
  293. turtle.turnRight()
  294. term.clear()
  295. term.setCursorPos(1,1)
  296. print("Tunnel Complete " .. distance .. " blocks long")
Add Comment
Please, Sign In to add comment