Advertisement
nocv

Untitled

Oct 14th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. -- Fetch beginning position.
  2. local startPos = npos.getPosition()
  3.  
  4. -- Find refuel/stop waypoint position.
  5. local forwardStart = 5
  6. for fscnt=1,forwardStart,1 do
  7. npos.move(npos.directions.FORWARD, true)
  8. end
  9. local routeWaypoint = npos.getPosition()
  10. npos.moveTo(startPos)
  11.  
  12. local exiting = false
  13.  
  14. -- Get back to our house safely.
  15. function navigateHome()
  16. npos.moveTo(routeWaypoint)
  17. npos.moveTo(startPos)
  18. end
  19.  
  20. -- Get out of our house.
  21. function exitHome()
  22. npos.moveTo(routeWaypoint)
  23. end
  24.  
  25. -- Check if we need to unload.
  26. function isUnloadRequired()
  27. for i=1,16,1 do
  28. if(turtle.getItemDetail(i) == nil) then
  29. return false
  30. end
  31. end
  32. return true
  33. end
  34.  
  35. -- Select an empty slot.
  36. function selectEmptySlot()
  37. for i=1,16,1 do
  38. if(turtle.getItemDetail(i) == nil) then
  39. turtle.select(i)
  40. return true
  41. end
  42. end
  43. return false
  44. end
  45.  
  46. -- Check our inventory/fuel status.
  47. function blockCheck()
  48. local cpos = npos.getPosition()
  49.  
  50. if(turtle.getFuelLevel() < 5000 or isUnloadRequired()) then
  51. print("Making a drop and refuel run")
  52. navigateHome()
  53.  
  54. -- Spit everything out.
  55. npos.setOrientation(npos.orientations.SOUTH)
  56. print("Dropping items...")
  57. for dx=1,16,1 do
  58. turtle.select(dx)
  59.  
  60. if(turtle.getItemDetail(dx) == nil) then
  61. print(dx .. ": Nothing here, cant drop...")
  62. else
  63. if(turtle.drop() == false) then
  64. print(dx .. ": Can't drop anymore. stopping...")
  65. exiting = true
  66. return true
  67. else
  68. print(dx .. ": Dropped")
  69. end
  70. end
  71. end
  72.  
  73. -- Check if we need to refuel.
  74. npos.setOrientation(npos.orientations.WEST)
  75. if(turtle.getFuelLevel() < 5000) then
  76. selectEmptySlot()
  77. while(turtle.getFuelLevel() < 15000) do
  78. if(turtle.suck() == true) then
  79. local refuelSuccess = false
  80. for rfi=1,16,1 do
  81. turtle.select(rfi)
  82. if(turtle.refuel()) then
  83. refuelSuccess = true
  84. end
  85. end
  86.  
  87. if(refuelSuccess == false) then
  88. print("Couldn't refuel after fetching from fuel chest")
  89. exiting = true
  90. return true
  91. end
  92. else
  93. print("Couldn't refuel anymore, stopping...")
  94. exiting = true
  95. return true
  96. end
  97. end
  98. end
  99. end
  100.  
  101. -- Resume where we left off.
  102. exitHome()
  103. npos.moveTo(cpos)
  104. npos.setOrientation(cpos.o)
  105. end
  106.  
  107. function excavateChunk()
  108. local isForward = true
  109. local startPos = npos.getPosition()
  110.  
  111. w = 16
  112. h = 16
  113. l = 16
  114.  
  115. for ch=1,16,1 do
  116. for cw=1,16,1 do
  117. for cl=1,15,1 do
  118. npos.move(npos.directions.FORWARD, true)
  119. blockCheck()
  120.  
  121. if(exiting == true) then return true end
  122. end
  123.  
  124. if(cw < w) then
  125. if(isForward) then
  126. npos.turnRight()
  127. npos.move(npos.directions.FORWARD, true)
  128. blockCheck()
  129. if(exiting == true) then return true end
  130. npos.turnRight()
  131.  
  132. isForward = false
  133. else
  134. npos.turnLeft()
  135. npos.move(npos.directions.FORWARD, true)
  136. blockCheck()
  137. if(exiting == true) then return true end
  138. npos.turnLeft()
  139.  
  140. isForward = true
  141. end
  142. end
  143. end
  144.  
  145. if(ch < h) then
  146. npos.move(npos.directions.UP, true)
  147. blockCheck()
  148. if(exiting == true) then return true end
  149. npos.turnLeft()
  150. npos.turnLeft()
  151. end
  152. end
  153.  
  154. print("Looks like we're done with this chunk, going home.")
  155. navigateHome()
  156. end
  157.  
  158. local args = { ... }
  159. local chunkForward = tonumber(args[1])
  160. local chunkLateral = tonumber(args[2])
  161.  
  162. -- Leave the comfort of our warm, warm home.
  163. exitHome()
  164.  
  165. -- Move right the given amount of chunks we're mining from here.
  166. if(chunkLateral > 0) then
  167. print("Moving laterally a chunk or so")
  168. npos.turnRight()
  169. for cl=1,chunkLateral,1 do
  170. for cli=1,16,1 do
  171. npos.move(npos.directions.FORWARD, true)
  172. end
  173. end
  174. npos.setOrientation(startPos.o)
  175. npos.turnLeft()
  176. end
  177.  
  178. -- Move forward the given amount of chunks we're mining from here.
  179. if(chunkForward > 0) then
  180. for cf=1,chunkForward,1 do
  181. print("Moving forward a chunk or so")
  182. for cfi=1,16,1 do
  183. npos.move(npos.directions.FORWARD, true)
  184. end
  185. end
  186. end
  187.  
  188. -- Move backwards our 'forward start' amount.
  189. print("Resetting to pre-forward start offset")
  190. npos.turnLeft()
  191. npos.turnLeft()
  192. for fsr=1,forwardStart,1 do npos.move(npos.directions.FORWARD, true) end
  193. npos.turnLeft()
  194. npos.turnLeft()
  195.  
  196. -- We good to go.
  197. print("Kicking off excavation...")
  198. excavateChunk()
  199. print("Done.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement