Advertisement
rjs232323

turtleminingwellOne

Jul 6th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local args = {...}
  2. --slot id:
  3. --1 = mining well, 2=tesseract wtih shiny dust, 3 pipes
  4. print("Dont forget to shiny dust the tesseract to retain their setting upon destroy");
  5. function unloadSystems()
  6. turtle.up();
  7. turtle.up();
  8. turtle.select(2);
  9. turtle.place();
  10. turtle.down();
  11. turtle.select(1);
  12. turtle.place();
  13. end
  14. function dumpAllItems()
  15. for i=1,16 do
  16.  
  17. local data = turtle.getItemDetail(i);
  18. if data then
  19. repeat
  20. turtle.select(i);
  21. until turtle.dropUp();
  22.  
  23. end
  24. end
  25. end
  26.  
  27.  
  28.  
  29.  
  30. function isStillWorking()
  31. return peripheral.call("front","hasWork")
  32. end
  33.  
  34. local zz=turtle
  35. local args = {...}
  36. local currentX=0 -- hoz
  37. local currentY=0 -- height
  38. local currentZ=0 -- depth
  39. local currRad=1 -- 0 is the right, 1 is default (original direction), 2 is the left, 3 is the back
  40. local cacheSlot = {}
  41. function place(slotID)
  42. zz.select(slotID)
  43. if zz.getItemCount()>0 then
  44. return zz.place()
  45. end
  46. return false
  47. end
  48. function placeUp(slotID)
  49. zz.select(slotID)
  50. if zz.getItemCount()>0 then
  51. return zz.placeUp()
  52. end
  53. return false
  54. end
  55. function refuel(amount)
  56. while zz.getFuelLevel()<=math.abs(amount) do
  57. zz.select(16)
  58. zz.refuel(1)
  59. print("Refueling")
  60. end
  61. end
  62. function turnRight()
  63. while zz.turnRight() do
  64. currRad=(currRad-1)%4
  65. break
  66. end
  67. end
  68. function turnLeft()
  69. while zz.turnLeft() do
  70. currRad=(currRad+1)%4
  71. break
  72. end
  73. end
  74. function turnToRad(r)
  75. if currRad==r then
  76. return true
  77. end
  78. while currRad~=r do
  79. if currRad>r then
  80. turnRight()
  81. elseif currRad<r then
  82. turnLeft()
  83. end
  84. end
  85. end
  86. function alertForProblem(stringCauseOfProblem)
  87. zz.turnRight()
  88. zz.turnRight()
  89. zz.turnRight()
  90. zz.turnRight()
  91. print(stringCauseOfProblem)
  92. end
  93. function moveByX(ox)
  94. local x=currentX+ox
  95. turnToRad(0)
  96. refuel(ox)
  97. while ox~=0 do
  98. if ox<0 then
  99. if zz.back() then
  100. ox=ox+1
  101. currentX=currentX-1
  102. else
  103. alertForProblem("can not move - check fuel or obstacle")
  104. moveByX(ox)
  105. break
  106. end
  107. else
  108. if zz.forward() then
  109. ox=ox-1
  110. currentX=currentX+1
  111. else
  112. alertForProblem("can not move - check fuel or obstacle")
  113. moveByX(ox)
  114. break
  115. end
  116. end
  117. end
  118. end
  119. function moveByZ(oz)
  120. local z=currentZ+oz
  121. turnToRad(1)
  122. refuel(oz)
  123. while oz~=0 do
  124. if oz<0 then
  125. if zz.back() then
  126. oz=oz+1
  127. currentZ=currentZ-1
  128. else
  129. alertForProblem("can not move - check fuel or obstacle")
  130. moveByZ(oz)
  131. break
  132. end
  133. else
  134. if zz.forward() then
  135. oz=oz-1
  136. currentZ=currentZ+1
  137. else
  138. alertForProblem("can not move - check fuel or obstacle")
  139. moveByZ(oz)
  140. break
  141. end
  142. end
  143. end
  144. end
  145. function moveByY(oy)
  146. local y=currentY+oy
  147. refuel(oy)
  148. while oy~=0 do
  149. if oy<0 then
  150. if zz.down() then
  151. oy=oy+1
  152. currentY=currentY-1
  153. else
  154. alertForProblem("can not move down - check fuel or obstacle")
  155. moveByY(oy)
  156. break
  157. end
  158. else
  159. if zz.up() then
  160. oy=oy-1
  161. currentY=currentY+1
  162. else
  163. alertForProblem("can not move up - check fuel or obstacle")
  164. moveByY(oy)
  165. break
  166. end
  167. end
  168. end
  169. end
  170. function goToCord(y,x,z)
  171. local differenceX=x-(currentX)
  172. local differenceY=y-currentY
  173. local differenceZ=z-currentZ
  174. if differenceX~=0 then moveByX(differenceX) end
  175. if differenceY~=0 then moveByY(differenceY) end
  176. if differenceZ~=0 then moveByZ(differenceZ) end
  177. end
  178. function placeAt(y,x,z,slotID)
  179. goToCord(y,x,z)
  180. if place(slotID) then return true
  181. else
  182. alertForProblem("can not place ahead - must be air ahead or do I have a material to place")
  183. placeAt(y,x,z,slotID)
  184. end
  185. end
  186. function placeUpAt(y,x,z,slotID)
  187. goToCord(y,x,z)
  188. if placeUp(slotID) then return true
  189. else
  190. alertForProblem("can not place up - must be air ahead or do I have a material to place")
  191. placeUpAt(y,x,z,slotID)
  192. end
  193. end
  194. local repeatUntil=1;
  195. if (#args==1) and tonumber(args[1])>1 then
  196. repeatUntil=tonumber(args[1]);
  197. end
  198. for zd=1,repeatUntil do
  199. unloadSystems()
  200. os.sleep(1);
  201. repeat
  202.  
  203. until not isStillWorking();
  204. dumpAllItems();
  205. turtle.select(1);
  206. turtle.dig();
  207. turtle.up();
  208. turtle.select(2);
  209. turtle.dig();
  210. turtle.down();
  211. turtle.down();
  212.  
  213. if repeatUntil>1 then
  214. turtle.forward();
  215. end
  216. end
  217. print("done");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement