Advertisement
nocv

Untitled

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