Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 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. end
  61. end
  62.  
  63. function forward()
  64. refuel()
  65. if turtle.detect() then
  66. turn()
  67. else
  68. turtle.forward()
  69. sleep(0.5)
  70. end
  71. end
  72.  
  73. function turn()
  74. if turtle.detect() then
  75. if turn == 0 then
  76. turtle.turnLeft()
  77. turtle.forward()
  78. turtle.turnLeft()
  79. turn = 1
  80. elseif turn == 1 then
  81. turtle.turnRight()
  82. turtle.forward()
  83. turtle.turnRight()
  84. turn = 0
  85. end
  86. end
  87. end
  88.  
  89. function refuel()
  90. local fuelLevel = turtle.getFuelLevel()
  91. if fuelLevel == "unlimited" or fuelLevel > 0 then
  92. return
  93. end
  94.  
  95. local function tryRefuel()
  96. for n=1,16 do
  97. if turtle.getItemCount(n) > 0 then
  98. turtle.select(n)
  99. if turtle.refuel(1) then
  100. turtle.select(1)
  101. return true
  102. end
  103. end
  104. end
  105. turtle.select(1)
  106. return false
  107. end
  108.  
  109. if not tryRefuel() then
  110. print( "Add more fuel to continue." )
  111. while not tryRefuel() do
  112. sleep(1)
  113. end
  114. print( "Resuming Tunnel." )
  115. end
  116. end
  117.  
  118. local function init()
  119. while true do
  120. sleep(0)
  121. place()
  122. forward()
  123. end
  124. end
  125.  
  126. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement