Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #!/usr/bin/lua5.3
  2.  
  3. function main(arg)
  4. validateInput(arg)
  5. startMining(math.floor(arg[1]))
  6. end
  7.  
  8. function validateInput(arg)
  9. if #arg < 1
  10. then
  11. print("Too few arguments!")
  12. showUsage()
  13. elseif #arg > 1
  14. then
  15. print("Too many arguments!")
  16. showUsage()
  17. elseif not tonumber(arg[1])
  18. then
  19. print("The parameter you provided was not numeric!")
  20. showUsage()
  21. elseif (tonumber(arg[1]) ~= math.floor(arg[1]))
  22. then
  23. print("Only whole numbers are allowed!")
  24. showUsage()
  25. elseif tonumber(arg[1]) < 1
  26. then
  27. print("No work to do! Enter a number greater than 0!")
  28. showUsage()
  29. end
  30. end
  31.  
  32. function showUsage()
  33. print("Usage: spiral " .. "<int number of complete cycles>")
  34. os.exit()
  35. end
  36.  
  37. function checkFuel()
  38. if turtle.getFuelLevel() == 0
  39. then
  40. burnFuel()
  41. end
  42. end
  43.  
  44. function burnFuel()
  45. for i = 1, 16, 1
  46. do
  47. turtle.select(i)
  48. if turtle.refuel(1)
  49. then
  50. break
  51. end
  52. end
  53. if turtle.getFuelLevel() == 0
  54. then
  55. print("Fatal Error: Out of fuel")
  56. os.exit()
  57. end
  58. end
  59.  
  60. function digOut()
  61. turtle.turnLeft()
  62. while turtle.detect()
  63. do
  64. turtle.dig()
  65. end
  66. turtle.turnRight()
  67. turtle.turnRight()
  68. while turtle.detect()
  69. do
  70. turtle.dig()
  71. end
  72. turtle.turnLeft()
  73. while turtle.detectDown()
  74. do
  75. turtle.digDown()
  76. end
  77. while turtle.detectUp()
  78. do
  79. turtle.digUp()
  80. end
  81. while turtle.detect()
  82. do
  83. turtle.dig()
  84. end
  85. checkFuel()
  86. while not turtle.forward()
  87. do
  88. turtle.dig()
  89. end
  90. end
  91.  
  92. function startMining(cycles)
  93. local n = 0
  94. local c = 3
  95. while n < cycles
  96. do
  97. for i = 1, 4, 1
  98. do
  99. for j = 1, c, 1
  100. do
  101. digOut()
  102. end
  103. c = c + 3
  104. turtle.turnRight()
  105. end
  106. n = n + 1
  107. end
  108. end
  109.  
  110.  
  111. args = {...}
  112. main(args)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement