Advertisement
ConnorNguyen

Untitled

Jun 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. t
  2. -- Offset from the left
  3. -- Will be set at bottom of code
  4. offset = 0
  5.  
  6. -- How far forward the turtle has gone
  7. distance = 0
  8.  
  9. turtle.turnAround = function()
  10. turtle.turnRight()
  11. turtle.turnRight()
  12. end
  13.  
  14. function forwardButWait(dist)
  15. -- Go forward the given distance, but wait for other things to get out of the way
  16. local goal = dist
  17. while goal > 0 do
  18. if turtle.forward() then
  19. print(goal)
  20. goal = goal - 1
  21. end
  22. end
  23. end
  24.  
  25. function forwardAndMine(dist)
  26. -- Go forward the given distance, mining things in the way
  27. local goal = dist
  28. while goal > 0 do
  29. turtle.dig()
  30. if turtle.forward() then
  31. goal = goal - 1
  32. end
  33. end
  34. end
  35.  
  36. function unload()
  37. for i=1,16 do
  38. turtle.select(i)
  39. turtle.drop()
  40. end
  41. end
  42.  
  43. function pitstop()
  44. turtle.turnAround()
  45. forwardAndMine(distance)
  46.  
  47. turtle.turnRight()
  48. forwardButWait(offset)
  49.  
  50. turtle.turnLeft()
  51. unload()
  52. turtle.turnRight()
  53.  
  54. turtle.suck()
  55. turtle.refuel()
  56. turtle.turnAround()
  57. forwardButWait(offset)
  58.  
  59. turtle.forward()
  60. offset = offset + 1
  61. distance = 0
  62.  
  63. turtle.turnLeft()
  64. end
  65.  
  66. function invfull()
  67. for i=1,16 do
  68. if turtle.getItemCount(i) == 0 then
  69. return false
  70. end
  71. end
  72. return true
  73. end
  74.  
  75. function check()
  76. print("Fuel: " .. tostring(turtle.getFuelLevel()))
  77. if distance > 500 or (turtle.getFuelLevel() <= distance + offset) or invfull() then
  78. print("Going for a pitstop!")
  79. pitstop()
  80. end
  81. end
  82.  
  83. function mine()
  84. while true do
  85. check()
  86. turtle.dig()
  87. turtle.digUp()
  88. turtle.digDown()
  89. if turtle.forward() then
  90. distance = distance + 1
  91. end
  92. end
  93. end
  94.  
  95. print("Mining begun.")
  96.  
  97. turtle.refuel()
  98. while turtle.back() do end
  99. turtle.turnLeft()
  100. while turtle.forward() do end
  101. turtle.turnLeft()
  102. unload()
  103. turle.turnRight()
  104. turtle.suck()
  105. turtle.refuel()
  106.  
  107. print("Initial refuel done.")
  108.  
  109. turtle.turnAround()
  110. while not turtle.detect() do
  111. offset = offset + 1
  112. turtle.forward()
  113. end
  114. turtle.dig()
  115. turtle.forward()
  116. offset = offset + 1
  117. turtle.turnLeft()
  118.  
  119. print("Offset is " .. tostring(offset) .. ".")
  120.  
  121. mine()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement