Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1,1)
  3.  
  4. local collected = 0
  5. local turn = 0
  6.  
  7. function collect()
  8. collected = collected+1
  9. if math.fmod(collected, 25) == 0 then
  10. print("Mined "..collected.." items.")
  11. end
  12. end
  13.  
  14. function dig()
  15. if turtle.detectDown() then
  16. turtle.digDown()
  17. collect()
  18. sleep(0.5)
  19. else
  20. return false
  21. end
  22. return true
  23. end
  24.  
  25. function select()
  26. for i = 1,4 do
  27. if turtle.getItemCount(i) > 0 then
  28. turtle.select(i)
  29. return true
  30. else
  31. return false
  32. end
  33. end
  34. end
  35.  
  36. function place()
  37. if not turtle.detectDown() then
  38. if select() then
  39. turtle.placeDown()
  40. else
  41. print("No more blocks")
  42.  
  43. local function blocks()
  44. for s = 1, 4 do
  45. if turtle.getItemCount(s) > 0 then
  46. return true
  47. else
  48. return false
  49. end
  50. end
  51. end
  52.  
  53. while true do
  54. if blocks() then
  55. turtle.placeDown()
  56. break
  57. end
  58. end
  59. end
  60. else
  61. dig()
  62. end
  63. end
  64.  
  65. function forward()
  66. refuel()
  67. if turtle.detect() then
  68. turn()
  69. else
  70. turtle.forward()
  71. sleep(0.5)
  72. end
  73. end
  74.  
  75. function turn()
  76. if turtle.detect() then
  77. if turn == 0 then
  78. turtle.turnLeft()
  79. turtle.forward()
  80. turtle.turnLeft()
  81. turn = 1
  82. elseif turn == 1 then
  83. turtle.turnRight()
  84. turtle.forward()
  85. turtle.turnRight()
  86. turn = 0
  87. end
  88. end
  89. end
  90.  
  91. function refuel()
  92. local fuelLevel = turtle.getFuelLevel()
  93. if fuelLevel == "unlimited" or fuelLevel > 0 then
  94. return
  95. end
  96.  
  97. local function tryRefuel()
  98. for n=1,16 do
  99. if turtle.getItemCount(n) > 0 then
  100. turtle.select(n)
  101. if turtle.refuel(1) then
  102. turtle.select(1)
  103. return true
  104. end
  105. end
  106. end
  107. turtle.select(1)
  108. return false
  109. end
  110.  
  111. if not tryRefuel() then
  112. print( "Add more fuel to continue." )
  113. while not tryRefuel() do
  114. sleep(1)
  115. end
  116. print( "Resuming Tunnel." )
  117. end
  118. end
  119.  
  120. local function init()
  121. while true do
  122. sleep(0)
  123. place()
  124. forward()
  125. end
  126. end
  127.  
  128. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement