Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. -- TODO: fill liquid/air and remove falling blocks
  2.  
  3. local status = "Idle"
  4. local cycles = 1
  5. local cyclesDone = 0
  6. local blocksBroken = 0
  7. local blocksPlaced = 0
  8.  
  9. -- Continuiesly updates terminal to inform user of status
  10. function uiLoop()
  11. while true do
  12. term.clear()
  13. term.setCursorPos(1, 1)
  14. term.write("Status: " .. status .. "\n")
  15. term.write("Fuel: " .. turtle.getFuelLevel() .. "\n")
  16. term.write("Cycles: " .. cyclesDone .. "/" .. cycles .. "\n")
  17. sleep(1)
  18. end
  19. end
  20.  
  21. -- Main loop controlling the turtles actions
  22. function minerLoop()
  23. for i = 1, cycles do
  24. checkFuelSufficient()
  25. mineSlice()
  26. mineCorridor()
  27. cyclesDone = cyclesDone + 1
  28. end
  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(1)
  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. turtle.forward()
  51. turtle.turnLeft()
  52. repeatMineForward(6)
  53. endLeftStrip()
  54. repeatMineForward(13)
  55. endRightStrip()
  56. repeatMineForward(6)
  57. turtle.digUp()
  58. turtle.forward()
  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. turtle.down()
  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. turtle.up()
  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. turtle.forward()
  106. end
  107. end
  108.  
  109. -- Mines a 1x3x1 column in front and moves into it
  110. function mine3YForward()
  111. turtle.dig()
  112. turtle.forward()
  113. turtle.digUp()
  114. turtle.digDown()
  115. end
  116.  
  117. -- Places a torch directly in front
  118. function placeTorchForward()
  119. turtle.select(15)
  120. turtle.place()
  121. end
  122.  
  123. ---- START POINT ----
  124.  
  125. -- Initialization
  126. while true do
  127. term.clear()
  128. term.setCursorPos(1, 1)
  129. term.write("Enter number of cycles to be done: ")
  130. cycles = tonumber(read())
  131. if (cycles == nil) then
  132. term.write("That's not a number!\n")
  133. sleep(1)
  134. else
  135. break
  136. end
  137. end
  138.  
  139. -- Start main loop
  140. parallel.waitForAny(uiLoop, minerLoop)
  141.  
  142. -- End
  143. term.clear()
  144. term.setCursorPos(1, 1)
  145. term.write("AutoMiner Done.\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement