Advertisement
LostMiner

Untitled

Oct 27th, 2016
68
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.     if t.detect() then
  43.         t.dig()
  44.         t.forward()
  45.     else
  46.         t.forward()
  47.     end
  48.     t.turnRight()
  49. end
  50. function dright()
  51.     t.turnRight()
  52.     if t.detect() then
  53.         t.dig()
  54.         t.forward()
  55.     else
  56.         t.forward()
  57.     end
  58.     t.turnLeft()
  59. end
  60. function dback()
  61.     turnAround()
  62.     if t.detect() then
  63.         t.dig()
  64.         t.forward()
  65.     else
  66.         t.forward()
  67.     end
  68.     turnAround()
  69. end
  70. function dforward()
  71.     if t.detect() then
  72.         t.dig()
  73.         t.forward()
  74.     else
  75.         t.forward()
  76.     end
  77. end
  78. function mineLayer(module)
  79.     if module == 2 or module == 4 or module == 6 or module == 8 then
  80.         turn(module/2)
  81.         dleft()
  82.         dforward()
  83.         dback()
  84.         dback()
  85.         dright()
  86.         dright()
  87.         dforward()
  88.         dforward()
  89.         dback()
  90.         dleft()
  91.     else
  92.         turn((module+1)/2)
  93.         dforward()
  94.         dright()
  95.         dback()
  96.         dback()
  97.         dleft()
  98.         dleft()
  99.         dforward()
  100.         dright()
  101.     end
  102. end
  103. function mine(distance)
  104.     module = 0
  105.     while distance > 0 do
  106.         module = modulo(distance)
  107.         mineLayer(module)
  108.         t.up()
  109.         distance = distance - 1
  110.     end
  111. end
  112. function spiral()
  113.     distance = distanceInput()
  114.     fuel(distance)
  115.     print("3x3 Spiral Initiated; No further input required")
  116.     hole(distance)
  117.     mine(distance)
  118. end
  119.  
  120. spiral()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement