Advertisement
Guest User

Untitled

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