Advertisement
nocv

Untitled

Oct 12th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 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. for dx=1,16,1 do
  33. turtle.select(dx)
  34. if(turtle.drop() == false) then
  35. print("Can't drop anymore. stopping...")
  36. exiting = true
  37. return true
  38. end
  39. end
  40.  
  41. -- Check if we need to refuel.
  42. npos.setOrientation(npos.orientations.WEST)
  43. if(turtle.getFuelLevel() < 5000) then
  44. selectEmptySlot()
  45. while(turtle.getFuelLevel() < 15000) do
  46. if(turtle.suck() == true) then
  47. turtle.refuel()
  48. else
  49. print("Couldn't refuel anymore, stopping...")
  50. exiting = true
  51. return true
  52. end
  53. end
  54. end
  55. end
  56.  
  57. -- Resume where we left off.
  58. npos.moveTo(cpos)
  59. npos.setOrientation(cpos.o)
  60. end
  61.  
  62. function excavateChunk()
  63. local isForward = true
  64. local startPos = npos.getPosition()
  65.  
  66. w = 16
  67. h = 16
  68. l = 16
  69.  
  70. for ch=1,16,1 do
  71. for cw=1,16,1 do
  72. for cl=1,15,1 do
  73. npos.move(npos.directions.FORWARD, true)
  74. blockCheck()
  75.  
  76. if(exiting == true) then return true end
  77. end
  78.  
  79. if(cw < w) then
  80. if(isForward) then
  81. npos.turnRight()
  82. npos.move(npos.directions.FORWARD, true)
  83. blockCheck()
  84. if(exiting == true) then return true end
  85. npos.turnRight()
  86.  
  87. isForward = false
  88. else
  89. npos.turnLeft()
  90. npos.move(npos.directions.FORWARD, true)
  91. blockCheck()
  92. if(exiting == true) then return true end
  93. npos.turnLeft()
  94.  
  95. isForward = true
  96. end
  97. end
  98. end
  99.  
  100. if(ch < h) then
  101. npos.move(npos.directions.UP, true)
  102. blockCheck()
  103. if(exiting == true) then return true end
  104. npos.turnLeft()
  105. npos.turnLeft()
  106. end
  107. end
  108.  
  109. for rl=1,h-1,1 do
  110. npos.move(npos.directions.DOWN, true)
  111. end
  112.  
  113. npos.setOrientation(startPos.o)
  114.  
  115. if(curX ~= startPos.x) then
  116. npos.turnLeft()
  117. for rsw=1,w-1,1 do npos.move(npos.directions.FORWARD, true) end
  118. npos.turnLeft()
  119. for rsl=1,l-1,1 do npos.move(npos.directions.FORWARD, true) end
  120. npos.setOrientation(startPos.o)
  121. end
  122. end
  123.  
  124. print("Kicking off excavation...")
  125. excavateChunk()
  126. print("Done.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement