Advertisement
ConnorNguyen

Untitled

Jun 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 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. turtle.refuel()
  91. while turtle.back() do end
  92.  
  93. while not turtle.detect() do
  94. offset = offset + 1
  95. turtle.turnRight()
  96. turtle.forward()
  97. turtle.turnLeft()
  98. end
  99. print("Offset is " .. tostring(offset))
  100.  
  101. pitstop()
  102. mine()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement