Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. local status = "Idle"
  2. local cycles = 0
  3. local cyclesDone = 0
  4.  
  5. -- Continuiesly updates terminal to inform user of status
  6. function uiLoop()
  7. while true do
  8. term.clear()
  9. term.setCursorPos(1, 1)
  10. print("AutoMiner - tedski999, 2019")
  11. print("===========================")
  12. print("")
  13. print("Status: " .. status)
  14. print("Fuel: " .. turtle.getFuelLevel())
  15. print("Cycles: " .. cyclesDone .. "/" .. cycles)
  16. sleep(0.5)
  17. end
  18. end
  19.  
  20. -- Main loop controlling the turtles actions
  21. function minerLoop()
  22. for i = 1, cycles do
  23. checkFuelSufficient()
  24. mineSlice()
  25. mineCorridor()
  26. cyclesDone = cyclesDone + 1
  27. end
  28. status = "Done!"
  29. end
  30.  
  31. -- Refuel if needed to ... movements required per cycle: 34
  32. function checkFuelSufficient()
  33. while turtle.getFuelLevel() < 35 do
  34. turtle.select(16)
  35. if turtle.refuel(0) then
  36. turtle.refuel(1)
  37. else
  38. status = "Out of Fuel!"
  39. while not turtle.refuel(0) do
  40. sleep(0.5)
  41. end
  42. end
  43. end
  44. end
  45.  
  46. -- Mines a strip on either side of the main corridor
  47. function mineSlice()
  48. status = "Mining slice..."
  49. turtle.dig()
  50. attemptForward()
  51. turtle.turnLeft()
  52. repeatMineForward(6)
  53. endLeftStrip()
  54. repeatMineForward(13)
  55. endRightStrip()
  56. repeatMineForward(6)
  57. turtle.digUp()
  58. attemptForward()
  59. turtle.digUp()
  60. turtle.turnRight()
  61. end
  62.  
  63. -- Continue main corridor
  64. function mineCorridor()
  65. status = "Continuing main corridor..."
  66. mine3YForward()
  67. turtle.turnRight()
  68. mine3YForward()
  69. turtle.turnLeft()
  70. mine3YForward()
  71. turtle.turnLeft()
  72. mine3YForward()
  73. turtle.turnRight()
  74. turtle.turnRight()
  75. placeTorchForward()
  76. turtle.turnLeft()
  77. end
  78.  
  79. -- Place a torch and turn around at the end of the left side stip
  80. function endLeftStrip()
  81. turtle.dig()
  82. placeTorchForward()
  83. turtle.digDown()
  84. attemptDown()
  85. turtle.dig()
  86. turtle.turnLeft()
  87. turtle.turnLeft()
  88. end
  89.  
  90. -- Place a torch and turn around at the end of the right side stip
  91. function endRightStrip()
  92. turtle.dig()
  93. turtle.digUp()
  94. attemptUp()
  95. turtle.dig()
  96. placeTorchForward()
  97. turtle.turnLeft()
  98. turtle.turnLeft()
  99. end
  100.  
  101. -- Mines forward i times
  102. function repeatMineForward(i)
  103. for i = 1, i do
  104. turtle.dig()
  105. attemptForward()
  106. end
  107. end
  108.  
  109. -- Mines a 1x3x1 column in front and moves into it
  110. function mine3YForward()
  111. turtle.dig()
  112. attemptForward()
  113. turtle.digUp()
  114. turtle.digDown()
  115. end
  116.  
  117. -- Places a torch directly in front
  118. function placeTorchForward()
  119. if turtle.getItemCount(15) < 1 then
  120. status = "Out of Torches!"
  121. while turtle.getItemCount(15) < 1 do
  122. sleep(0.5)
  123. end
  124. end
  125. turtle.select(15)
  126. turtle.place()
  127. end
  128.  
  129. -- Gravel/Sand proof movement
  130. function attemptForward()
  131. while not turtle.forward() do
  132. turtle.dig()
  133. end
  134. end
  135.  
  136. -- Gravel/Sand proof movement
  137. function attemptUp()
  138. while not turtle.up() do
  139. turtle.digUp()
  140. end
  141. end
  142.  
  143. -- Gravel/Sand proof movement
  144. function attemptDown()
  145. while not turtle.down() do
  146. turtle.digDown()
  147. end
  148. end
  149.  
  150. ---- START POINT ----
  151.  
  152. -- Initialization
  153. while true do
  154. term.clear()
  155. term.setCursorPos(1, 1)
  156. term.write("Enter number of cycles to be done: ")
  157. cycles = tonumber(read())
  158. if cycles == nil then
  159. print("Sorry, that's not a number!")
  160. elseif cycles > 20 then
  161. print("Sorry, max of 20 cycles!")
  162. elseif cycles < 1 then
  163. print("Sorry, input must be greater than 0!")
  164. else
  165. break
  166. end
  167. sleep(1)
  168. end
  169.  
  170. -- Start main loop
  171. parallel.waitForAny(uiLoop, minerLoop)
  172.  
  173. -- End
  174. term.clear()
  175. term.setCursorPos(1, 1)
  176. print("Completed " .. cycles .. " cycles.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement