Advertisement
nocv

Untitled

Oct 14th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. local startPos = npos.getPosition()
  2. local exiting = false
  3.  
  4. function isUnloadRequired()
  5. for i=1,16,1 do
  6. if(turtle.getItemDetail(i) == nil) then
  7. return false
  8. end
  9. end
  10. return true
  11. end
  12.  
  13. function selectEmptySlot()
  14. for i=1,16,1 do
  15. if(turtle.getItemDetail(i) == nil) then
  16. turtle.select(i)
  17. return true
  18. end
  19. end
  20. return false
  21. end
  22.  
  23. function blockCheck()
  24. local cpos = npos.getPosition()
  25.  
  26. if(turtle.getFuelLevel() < 5000 or isUnloadRequired()) then
  27. print("Making a drop and refuel run")
  28. npos.moveTo(startPos)
  29.  
  30. -- Spit everything out.
  31. npos.setOrientation(npos.orientations.SOUTH)
  32. print("Dropping items...")
  33. for dx=1,16,1 do
  34. turtle.select(dx)
  35.  
  36. if(turtle.getItemDetail(dx) == nil) then
  37. print(dx .. ": Nothing here, cant drop...")
  38. else
  39. if(turtle.drop() == false) then
  40. print(dx .. ": Can't drop anymore. stopping...")
  41. exiting = true
  42. return true
  43. else
  44. print(dx .. ": Dropped")
  45. end
  46. end
  47. end
  48.  
  49. -- Check if we need to refuel.
  50. npos.setOrientation(npos.orientations.WEST)
  51. if(turtle.getFuelLevel() < 5000) then
  52. selectEmptySlot()
  53. while(turtle.getFuelLevel() < 15000) do
  54. if(turtle.suck() == true) then
  55. local refuelSuccess = false
  56. for rfi=1,16,1 do
  57. turtle.select(rfi)
  58. if(turtle.refuel()) then
  59. refuelSuccess = true
  60. end
  61. end
  62.  
  63. if(refuelSuccess == false) then
  64. print("Couldn't refuel after fetching from fuel chest")
  65. exiting = true
  66. return true
  67. end
  68. else
  69. print("Couldn't refuel anymore, stopping...")
  70. exiting = true
  71. return true
  72. end
  73. end
  74. end
  75. end
  76.  
  77. -- Resume where we left off.
  78. npos.moveTo(cpos)
  79. npos.setOrientation(cpos.o)
  80. end
  81.  
  82. function excavateChunk()
  83. local isForward = true
  84. local startPos = npos.getPosition()
  85.  
  86. w = 16
  87. h = 16
  88. l = 16
  89.  
  90. for ch=1,16,1 do
  91. for cw=1,16,1 do
  92. for cl=1,15,1 do
  93. npos.move(npos.directions.FORWARD, true)
  94. blockCheck()
  95.  
  96. if(exiting == true) then return true end
  97. end
  98.  
  99. if(cw < w) then
  100. if(isForward) then
  101. npos.turnRight()
  102. npos.move(npos.directions.FORWARD, true)
  103. blockCheck()
  104. if(exiting == true) then return true end
  105. npos.turnRight()
  106.  
  107. isForward = false
  108. else
  109. npos.turnLeft()
  110. npos.move(npos.directions.FORWARD, true)
  111. blockCheck()
  112. if(exiting == true) then return true end
  113. npos.turnLeft()
  114.  
  115. isForward = true
  116. end
  117. end
  118. end
  119.  
  120. if(ch < h) then
  121. npos.move(npos.directions.UP, true)
  122. blockCheck()
  123. if(exiting == true) then return true end
  124. npos.turnLeft()
  125. npos.turnLeft()
  126. end
  127. end
  128.  
  129. for rl=1,h-1,1 do
  130. npos.move(npos.directions.DOWN, true)
  131. end
  132.  
  133. npos.setOrientation(startPos.o)
  134.  
  135. if(curX ~= startPos.x) then
  136. npos.turnLeft()
  137. for rsw=1,w-1,1 do npos.move(npos.directions.FORWARD, true) end
  138. npos.turnLeft()
  139. for rsl=1,l-1,1 do npos.move(npos.directions.FORWARD, true) end
  140. npos.setOrientation(startPos.o)
  141. end
  142. end
  143.  
  144. local args = { ... }
  145. local chunkForward = tonumber(args[1])
  146. local chunkLateral = tonumber(args[2])
  147.  
  148. if(chunkForward > 0) then
  149. for cf=1,chunkForward,1 do
  150. print("Moving forward a chunk")
  151. for cfi=1,16,1 do
  152. npos.move(npos.directions.FORWARD, true)
  153. end
  154. end
  155. end
  156.  
  157. if(chunkLateral > 0) then
  158. print("Moving laterally a chunk")
  159. npos.turnRight()
  160. for cl=1,chunkLateral,1 do
  161. for cli=1,16,1 do
  162. npos.move(npos.directions.FORWARD, true)
  163. end
  164. end
  165. npos.setOrientation(startPos.o)
  166. end
  167.  
  168. print("Kicking off excavation...")
  169. excavateChunk()
  170. print("Done.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement