Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. if #tArgs == 0 then
  4. print("Usage: <blocks> [drop]")
  5. return
  6. end
  7.  
  8. turtle.refuel()
  9.  
  10. if turtle.getFuelLevel() == 0 then
  11. print("The turtle must have at least some fuel to start with.")
  12. return
  13. elseif turtle.getFuelLevel() == "unlimited" then
  14. print("This turtle does not use fuel to move")
  15. return
  16. end
  17.  
  18. --Number of blocks to travel to get the lava
  19. local maxDistance = tArgs[1]
  20.  
  21. --How deep to go to gather the lava
  22. local drop = 0
  23. if #tArgs >= 2 then
  24. drop = tonumber(tArgs[2])
  25. end
  26.  
  27. --local counter for how far the turtle has travle
  28. local traveled = 0
  29.  
  30. --A helper function to try and move forward, it will attempt to dig if it is blocked.
  31. local function moveForward()
  32. if turtle.forward() == false then
  33. --Failed to move, see if we can dig our way forward
  34. while turtle.dig() do
  35. --Keep digging till we can't dig any more, in case gravel is falling.
  36. end
  37. if turtle.forward() == false then
  38. print("I am either blocked or out of fuel.")
  39. return false
  40. end
  41. end
  42. return true
  43. end
  44.  
  45. --A helper function to try and move down, it will attempt to dig if it is blocked.
  46. local function moveDown()
  47. if turtle.down() == false then
  48. --Failed to move, see if we can dig our way down
  49. turtle.digDown()
  50. if turtle.down() == false then
  51. print("I am either blocked or out of fuel.")
  52. return false
  53. end
  54. end
  55. return true
  56. end
  57.  
  58. --A helper function to try and move down, it will attempt to dig if it is blocked.
  59. local function moveUp()
  60. if turtle.up() == false then
  61. --Failed to move, see if we can dig our way down
  62. while turtle.digUp() do
  63. --Keep digging till we can't dig any more, in case gravel is falling.
  64. end
  65. if turtle.up() == false then
  66. print("I am either blocked or out of fuel.")
  67. return false
  68. end
  69. end
  70. return true
  71. end
  72.  
  73. dropDone = false
  74.  
  75. --Attempt to travel to max distance for getting lava
  76. for i = 1, maxDistance do
  77. if moveForward() == false then
  78. print("Could not move forward the full requested distance, starting U-Turn early.")
  79. break
  80. end
  81. traveled = traveled + 1
  82.  
  83. --drop to the requested depth
  84. if(dropDone == false) then
  85. for j = 1, drop do
  86. if moveDown() == false then
  87. print("Could not drop the full distance")
  88. drop = j - 1
  89. end
  90. end
  91. dropDone = true
  92. end
  93.  
  94. --grab the fule
  95. turtle.placeDown()
  96. if turtle.refuel() == false then
  97. --Whatever we picked up is invalid for fuel, put it back down
  98. turtle.placeDown()
  99. end
  100. end
  101.  
  102. --Turn around move a block over and get more lava
  103. turtle.turnRight()
  104. moveForward()
  105. turtle.turnRight()
  106.  
  107. --Travel back the same number of blocks we came
  108. for i = 1, traveled do
  109. turtle.placeDown()
  110. turtle.refuel()
  111.  
  112. --Check to see if we need to go up yet
  113. if i == traveled then
  114. for j = 1, drop do
  115. moveUp()
  116. end
  117. end
  118.  
  119. if moveForward() == false then
  120. --We are stuck, attempt to go up a level to get home
  121. if drop > 0 then
  122. repeat
  123. moveUp()
  124. drop = drop - 1
  125. lastMove = moveForward()
  126. until lastMove == true or drop == 0
  127.  
  128. if lastMove == false then
  129. print("I am stuck!")
  130. end
  131. end
  132. end
  133. end
  134.  
  135. turtle.turnRight()
  136. moveForward()
  137. turtle.turnRight()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement