Advertisement
Guest User

Untitled

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