Advertisement
nocv

Untitled

Oct 12th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. local startPos = npos.getPosition()
  2. local exiting = false
  3.  
  4. function isUnloadRequired()
  5. for i=0,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=0,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. for ch=1,16,1 do
  67. for cw=1,16,1 do
  68. for cl=1,15,1 do
  69. npos.move(npos.directions.FORWARD, true)
  70. blockCheck()
  71.  
  72. if(exiting == true) then return true end
  73. end
  74.  
  75. if(cw < w) then
  76. if(isForward) then
  77. npos.turnRight()
  78. npos.move(npos.directions.FORWARD, true)
  79. blockCheck()
  80. if(exiting == true) then return true end
  81. npos.turnRight()
  82.  
  83. isForward = false
  84. else
  85. npos.turnLeft()
  86. npos.move(npos.directions.FORWARD, true)
  87. blockCheck()
  88. if(exiting == true) then return true end
  89. npos.turnLeft()
  90.  
  91. isForward = true
  92. end
  93. end
  94. end
  95.  
  96. if(ch < h) then
  97. npos.move(npos.directions.UP, true)
  98. blockCheck()
  99. if(exiting == true) then return true end
  100. npos.turnLeft()
  101. npos.turnLeft()
  102. end
  103. end
  104.  
  105. for rl=1,h-1,1 do
  106. npos.move(npos.directions.DOWN, true)
  107. end
  108.  
  109. npos.setOrientation(startPos.o)
  110.  
  111. if(curX ~= startPos.x) then
  112. npos.turnLeft()
  113. for rsw=1,w-1,1 do npos.move(npos.directions.FORWARD, true) end
  114. npos.turnLeft()
  115. for rsl=1,l-1,1 do npos.move(npos.directions.FORWARD, true) end
  116. npos.setOrientation(startPos.o)
  117. end
  118. end
  119.  
  120. print("Kicking off excavation...")
  121. excavateChunk()
  122. print("Done.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement