SHARE
TWEET

Untitled

a guest May 21st, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ---
  2. --- Created by deathsgun.
  3. --- DateTime: 2019-05-21 15:01
  4. ---
  5.  
  6. local arg1, arg2, arg3 = ...
  7. local delay = 0.25
  8.  
  9. if arg1 == nil or arg2 == nil or arg3 == nil then
  10.     print("Usage: miner <length> <height> <width>")
  11.     return false
  12. end
  13. local length = tonumber(arg1)
  14. local height = tonumber(arg2)
  15. local width = tonumber(arg3)
  16.  
  17. X = 0;
  18. Y = 0;
  19. Z = 0;
  20. ORIENTATION = 0;
  21.  
  22. function left()
  23.     turtle.turnLeft()
  24.     if ORIENTATION == 0 then
  25.         ORIENTATION = 3
  26.     else
  27.         ORIENTATION = ORIENTATION - 1
  28.     end
  29. end
  30.  
  31. function right()
  32.     turtle.turnRight()
  33.     if ORIENTATION == 3 then
  34.         ORIENTATION = 0
  35.     else
  36.         ORIENTATION = ORIENTATION + 1
  37.     end
  38. end
  39.  
  40. function up()
  41.     while not turtle.up() do
  42.         digUp()
  43.         sleep(delay)
  44.     end
  45.     Y = Y + 1
  46. end
  47.  
  48. function down(q)
  49.     if q == nil then
  50.         q = 1
  51.     end
  52.     for _ = 1, q do
  53.         while not turtle.down() do
  54.             digDown()
  55.             sleep(delay)
  56.         end
  57.     end
  58.     Y = Y - q
  59. end
  60.  
  61. function forward(q)
  62.     if q == nil then
  63.         q = 1
  64.     end
  65.     for _ = 1, q do
  66.         while not turtle.forward() do
  67.             turtle.dig()
  68.             turtle.attack()
  69.             sleep(delay)
  70.         end
  71.     end
  72.     if ORIENTATION == 0 then
  73.         X = X + q
  74.     elseif ORIENTATION == 1 then
  75.         Z = Z + q
  76.     elseif ORIENTATION == 2 then
  77.         X = X - q
  78.     elseif ORIENTATION == 3 then
  79.         Z = Z - q
  80.     end
  81. end
  82.  
  83. function orient(orient)
  84.     while orient ~= 0 do
  85.         right()
  86.     end
  87. end
  88.  
  89. function dig()
  90.     while turtle.detect() do
  91.         turtle.dig()
  92.         sleep(delay)
  93.     end
  94. end
  95.  
  96. function digUp()
  97.     while turtle.detectUp() do
  98.         turtle.digUp()
  99.         sleep(delay)
  100.     end
  101. end
  102.  
  103. function digDown()
  104.     while turtle.detectDown() do
  105.         turtle.digDown()
  106.         sleep(delay)
  107.     end
  108. end
  109.  
  110. function go(lx, ly, lz)
  111.     print("going to " .. lx .. "/" .. ly .. "/" .. lz)
  112.     if X < lx then
  113.         orient(0)
  114.         for _ = 1, (lx - X) do
  115.             forward()
  116.         end
  117.     end
  118.  
  119.     if X > lx then
  120.         orient(2)
  121.         for _ = 1, X - lx do
  122.             forward()
  123.         end
  124.     end
  125.  
  126.     if Y < ly then
  127.         for _ = 1, ly - Y do
  128.             up()
  129.         end
  130.     end
  131.  
  132.     if Y > ly then
  133.         for _ = 1, Y - ly do
  134.             down()
  135.         end
  136.     end
  137.  
  138.     if Z < lz then
  139.         orient(1)
  140.         for _ = 1, lz - Z do
  141.             forward()
  142.         end
  143.     end
  144.  
  145.     if Z > lz then
  146.         orient(3)
  147.         for _ = 1, Z - lz do
  148.             forward()
  149.         end
  150.     end
  151. end
  152.  
  153. function deposit()
  154.     for i = 2, 16 do
  155.         turtle.select(i)
  156.         while not turtle.drop() and turtle.getItemCount() ~= 0 do
  157.             -- Waits until turtle can deposit item
  158.             sleep(1)
  159.         end
  160.         turtle.drop()
  161.     end
  162.     turtle.select(1)
  163.     return true
  164. end
  165.  
  166. function check()
  167.     return turtle.getItemCount(15) == 0
  168. end
  169.  
  170. print("Creating a tunnel " .. height .. " x " .. width .. " " .. length .. " long!")
  171.  
  172. lx = X
  173. ly = Y
  174. lz = Z
  175. for _ = 1, length do
  176.     lx = X
  177.     ly = Y
  178.     lz = Z
  179.     for _ = 1, width do
  180.         forward()
  181.         for _ = 1, height do
  182.             up()
  183.         end
  184.         down(height)
  185.         if _ == 1 then
  186.             right()
  187.         elseif _ <= width then
  188.             left()
  189.             forward(width)
  190.         end
  191.     end
  192.     go(lx, ly, lz)
  193. end
  194.  
  195. go(0, 0, 0)
  196. orient(2)
  197. deposit()
  198. orient(0)
  199. print("Finished task!")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top