Advertisement
Guest User

tunneltest1234

a guest
Dec 5th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.16 KB | None | 0 0
  1. local dn = 15
  2. local length, walk = ...
  3. local delay = 0.25
  4. if length == nil then
  5.     print("No length argument was given")
  6.     return false -- Closes Program
  7. end
  8.  
  9. if walk == 'true' then
  10.     walk = true
  11. else
  12.     walk = false
  13. end
  14.  
  15. X = 0
  16. Y = 0
  17. Z = 0
  18. O = 0
  19.  
  20. function left(q)
  21.     if q == nil then q = 1 end
  22.     for i=1,q do
  23.         turtle.turnLeft()
  24.         if O == 0 then
  25.             O = 3
  26.         else
  27.             O = O - 1
  28.         end
  29.     end
  30.     return true
  31. end
  32.  
  33. function right(q)
  34.     if q == nil then q = 1 end
  35.     for i=1,q do
  36.         turtle.turnRight()
  37.         if O == 3 then
  38.             O = 0
  39.         else
  40.             O = O + 1
  41.         end
  42.     end
  43.     return true
  44. end
  45.  
  46. function up(q)
  47.     if q == nil then q = 1 end
  48.     for i=1,q do
  49.         while not turtle.up() do
  50.             digUp()
  51.             turtle.up()
  52.             sleep(delay)
  53.         end
  54.         Y = Y + 1
  55.     end
  56.     return true
  57. end
  58.  
  59. function down(q)
  60.     if q == nil then q = 1 end
  61.     for i=1,q do
  62.         while not turtle.down() do
  63.             digDown()
  64.             turtle.attackDown()
  65.             sleep(delay)
  66.         end
  67.         Y = Y - 1
  68.     end
  69.     return true
  70. end
  71.  
  72. function forward(q)
  73.     if q == nil then q = 1 end
  74.     for i=1,q do
  75.         while not turtle.forward() do
  76.             turtle.dig()
  77.             turtle.attack()
  78.             sleep(delay)
  79.         end
  80.         if O == 0 then
  81.             X = X + 1
  82.         elseif O == 1 then
  83.             Z = Z + 1
  84.         elseif O == 2 then
  85.             X = X - 1
  86.         elseif O == 3 then
  87.             Z = Z - 1
  88.         end
  89.     end
  90.     return true
  91. end
  92.  
  93. function back()
  94.     right()
  95.     right()
  96.     forward()
  97.     left()
  98.     left()
  99.     return true
  100. end
  101.  
  102. function orient(arg1)
  103.     while arg1 ~= O do
  104.             right()
  105.     end
  106.     return true
  107. end
  108.  
  109. function dig()
  110.     while turtle.detect() do
  111.         turtle.dig()
  112.         sleep(delay)
  113.     end
  114.     return true
  115. end
  116.  
  117. function digUp()
  118.     while turtle.detectUp() do
  119.         turtle.digUp()
  120.         sleep(delay)
  121.     end
  122.     return true
  123. end
  124.  
  125. function digDown()
  126.     while turtle.detectDown() do
  127.         turtle.digDown()
  128.         sleep(delay)
  129.     end
  130.     return true
  131. end
  132.  
  133. function go(lx,ly,lz)
  134.     if X < lx then
  135.         orient(0)
  136.         for i=1,(lx-X) do
  137.             forward()
  138.         end
  139.     end
  140.    
  141.     if X > lx then
  142.         orient(2)
  143.         for i=1,X-lx do
  144.             forward()
  145.         end
  146.     end
  147.    
  148.     if Y < ly then
  149.         for i=1,ly-Y do
  150.             up()
  151.         end
  152.     end
  153.    
  154.     if Y > ly then
  155.         for i=1,Y-ly do
  156.             down()
  157.         end
  158.     end
  159.    
  160.     if Z < lz then
  161.         orient(1)
  162.         for i=1,lz-Z do
  163.             forward()
  164.         end
  165.     end
  166.    
  167.     if Z > lz then
  168.         orient(3)
  169.         for i=1,Z-lz do
  170.             forward()
  171.         end
  172.     end
  173. end
  174.  
  175.  
  176.  
  177. function deposit()
  178.     for i=1,16 do
  179.         turtle.select(i)
  180.         while turtle.drop() == false and turtle.getItemCount() ~= 0 do
  181.             sleep(1)
  182.         end
  183.         turtle.drop()
  184.     end
  185.     turtle.select(1)
  186.     return true
  187. end
  188.  
  189.  
  190. function mine()
  191.     dig()
  192.     forward()
  193.     digUp()
  194.     digDown()
  195.     up()
  196.     left()
  197.     dig()
  198.     right(2)
  199.     dig()
  200.     down()
  201.     dig()
  202.     left(2)
  203.     dig()
  204.     down()
  205.     dig()
  206.     right(2)
  207.     dig()
  208.     left()
  209.     up()
  210. end
  211.  
  212.  
  213. function check()
  214.     if turtle.getItemCount(15) == 0 then
  215.         return false
  216.     else
  217.         return true
  218.     end
  219. end
  220.  
  221. function notify(include)
  222.     if X % dn == 0 and X ~= 0 then
  223.         print("The turtle has traveled "..X.."/"..length+include.." blocks so far")
  224.     end
  225.     return true
  226. end
  227.  
  228. local dni = 0
  229. if walk then
  230.     while turtle.detect() == false do
  231.         forward()
  232.         dni = dni + 1
  233.         notify(dni) -- Notifies Distance
  234.     end
  235. end
  236.  
  237. for i=1,length do
  238.     mine()
  239.     notify(dni) -- Notifies Distance
  240.     if check() then -- Checks if turtle should deposit items
  241.         local lx,ly,lz = X,Y,Z
  242.         go(0,0,0)
  243.         orient(2) -- Faces Chest
  244.         deposit()
  245.         orient(0)
  246.         go(lx,ly,lz)
  247.     end
  248. end
  249.  
  250. go(0,0,0)
  251. orient(2)
  252. deposit()
  253. orient(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement