Advertisement
ConnorNguyen

Untitled

Jun 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1.  
  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. goal = goal - 1
  20. end
  21. end
  22. end
  23.  
  24. function forwardAndMine(dist)
  25. -- Go forward the given distance, mining things in the way
  26. local goal = dist
  27. while goal > 0 do
  28. turtle.dig()
  29. if turtle.forward() then
  30. goal = goal - 1
  31. end
  32. end
  33. end
  34.  
  35. function pitstop()
  36. turtle.turnAround()
  37. forwardAndMine(distance)
  38.  
  39. turtle.turnRight()
  40. forwardButWait(offset)
  41.  
  42. turtle.turnLeft()
  43. for i=1,16 do
  44. turtle.select(i)
  45. turtle.drop()
  46. end
  47. turtle.turnRight()
  48.  
  49. turtle.suck()
  50. turtle.refuel()
  51. turtle.turnAround()
  52. forwardButWait(offset)
  53.  
  54. turtle.forward()
  55. offset = offset + 1
  56. distance = 0
  57.  
  58. turtle.turnLeft()
  59. end
  60.  
  61. function invfull()
  62. for i=1,16 do
  63. if turtle.getItemCount(i) == 0 then
  64. return false
  65. end
  66. end
  67. return true
  68. end
  69.  
  70. function check()
  71. print("Fuel: " .. tostring(turtle.getFuelLevel()))
  72. if (turtle.getFuelLevel() <= distance + offset) or invfull() then
  73. print("Going for a pitstop!")
  74. pitstop()
  75. end
  76. end
  77.  
  78. function mine()
  79. while true do
  80. check()
  81. turtle.dig()
  82. turtle.digUp()
  83. turtle.digDown()
  84. if turtle.forward() then
  85. distance = distance + 1
  86. end
  87. end
  88. end
  89.  
  90. print("Mining begun.")
  91.  
  92. turtle.refuel()
  93. while turtle.back() do end
  94. turtle.turnLeft()
  95. while turtle.forward() do end
  96. turtle.suck()
  97. turtle.refuel()
  98.  
  99. print("Initial refuel done.")
  100.  
  101. turtle.turnAround()
  102. while not turtle.detect() do
  103. offset = offset + 1
  104. turtle.forward()
  105. end
  106. turtle.dig()
  107. turtle.forward()
  108. offset = offset + 1
  109. turtle.turnLeft()
  110.  
  111. print("Offset is " .. tostring(offset) .. ".")
  112.  
  113. mine()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement