Advertisement
LostMiner

Untitled

Oct 27th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. t = turtle
  2.  
  3. function distanceInput()
  4.     print("Input Distance")
  5.     num = io.read()
  6.     num = tonumber(num)
  7.     return num
  8. end
  9. function fuel(distance)
  10.     t.refuel()
  11. end
  12. function hole(distance)
  13.     while distance > 0 do
  14.         if t.detectDown() then
  15.             t.digDown()
  16.             t.down()
  17.         else
  18.             t.down()
  19.         end
  20.     distance = distance - 1
  21.     end
  22. end
  23. function modulo(tile)
  24.     while tile > 8 do
  25.         tile = tile - 8
  26.     end
  27.     print("Currently at tile: ", tile)
  28.     return tile
  29. end
  30. function turn(num)
  31.     while num > 0 do
  32.         t.turnRight()
  33.         num = num - 1
  34.     end
  35. end
  36. function turnAround()
  37.     t.turnLeft()
  38.     t.turnLeft()
  39. end
  40. function dleft()
  41.     t.turnLeft()
  42.     print("Left")
  43.     if t.detect() then
  44.         t.dig()
  45.         t.forward()
  46.     else
  47.         t.forward()
  48.     end
  49.     t.turnRight()
  50. end
  51. function dright()
  52.     t.turnRight()
  53.     print("Right")
  54.     if t.detect() then
  55.         t.dig()
  56.         t.forward()
  57.     else
  58.         t.forward()
  59.     end
  60.     t.turnLeft()
  61. end
  62. function dback()
  63.     turnAround()
  64.     print("Backward")
  65.     if t.detect() then
  66.         t.dig()
  67.         t.forward()
  68.     else
  69.         t.forward()
  70.     end
  71.     turnAround()
  72. end
  73. function dforward()
  74.     print("Forward")
  75.     if t.detect() then
  76.         t.dig()
  77.         t.forward()
  78.     else
  79.         t.forward()
  80.     end
  81. end
  82. function mineLayer(module)
  83.     if module == 2 or module == 4 or module == 6 or module == 8 then
  84.         turn(module/2)
  85.         dleft()
  86.         dforward()
  87.         dback()
  88.         dback()
  89.         dright()
  90.         dright()
  91.         dforward()
  92.         dforward()
  93.         dback()
  94.         dleft()
  95.     else
  96.         turn((module+1)/2)
  97.         dforward()
  98.         dright()
  99.         dback()
  100.         dback()
  101.         dleft()
  102.         dleft()
  103.         dforward()
  104.         dright()
  105.     end
  106. end
  107. function mine(distance)
  108.     module = 0
  109.     while distance > 0 do
  110.         module = modulo(distance)
  111.         mineLayer(module)
  112.         t.up()
  113.         distance = distance - 1
  114.     end
  115. end
  116. function spiral()
  117.     distance = distanceInput()
  118.     fuel(distance)
  119.     print("3x3 Spiral Initiated; No further input required")
  120.     hole(distance)
  121.     mine(distance)
  122. end
  123.  
  124. spiral()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement