Advertisement
rjs232323

miningTurtleQuadWell

Jun 26th, 2015
251
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. local zz=turtle
  6. local args = {...}
  7. local currentX=0 -- hoz
  8. local currentY=0 -- height
  9. local currentZ=0 -- depth
  10.  
  11. local isUndroppable={};
  12. function setCurrentItemsUndroppable()
  13. isUndroppable={};
  14. for undroppableItems=1,16 do
  15. local data = turtle.getItemDetail(undroppableItems);
  16. if data then
  17. isUndroppable[data.name..data.damage]=true;
  18. end
  19. end
  20. end
  21.  
  22. local memorizedItemInventory={};
  23. function memorizeItemSlot()
  24. memorizedItemInventory={};
  25. for slotIDMemory=1,16 do
  26. local data = turtle.getItemDetail(slotIDMemory);
  27. if data then
  28. memorizedItemInventory[data.name..data.damage]=slotIDMemory;
  29. end
  30. end
  31. end
  32.  
  33. function sortInventoryByMemory()
  34. for slotIDMemory=1,16 do
  35. local data = turtle.getItemDetail(slotIDMemory);
  36. if data and memorizedItemInventory[data.name..data.damage] > 0 then
  37. turtle.select(slotIDMemory);
  38. turtle.transferTo(memorizedItemInventory[data.name..data.damage]);
  39. end
  40. end
  41. end
  42.  
  43.  
  44. function unloadSystems()
  45. placeAt(1,0,0,1);--well
  46. turnLeft();
  47. placeAt(1,0,0,1);--well
  48. turnLeft();
  49. placeAt(1,0,0,1);--well
  50. turnLeft();
  51. placeAt(1,0,0,1);--well
  52. turnLeft();
  53. placeDownAt(1,0,0,1);--bottom well
  54. goToCord(2,0,0);--turtle resting spot
  55. placeDownAt(2,0,0,2);--tesseract
  56.  
  57. end
  58.  
  59. function loadSystems()
  60.  
  61. end
  62. function dumpAllItems()
  63.  
  64. for i=1,16 do
  65. if true then
  66. local data = turtle.getItemDetail(i);
  67. if data and not isUndroppable[data.name..data.damage] then
  68. goToCord(2,0,0);
  69. repeat
  70. turtle.select(i);
  71. until turtle.dropDown();
  72.  
  73. end
  74. end
  75. end
  76. end
  77.  
  78. function dumpAllItemsAndReturnToWork()
  79. local rememberCordX=currentX;
  80. local rememberCordY=currentY;
  81. local rememberCordZ=currentZ;
  82. for iDropReturn=1,16 do
  83. if true then
  84. local data = turtle.getItemDetail(iDropReturn);
  85. if data and not isUndroppable[data.name..data.damage] then
  86. print("trying at "..iDropReturn,currentX,currentY,currentZ);
  87. goToCord(2,0,0);
  88. repeat
  89. turtle.select(iDropReturn);
  90. until turtle.dropDown();
  91.  
  92. end
  93. end
  94. end
  95. goToCord(rememberCordY,rememberCordX,rememberCordZ);
  96. end
  97.  
  98.  
  99.  
  100. function isStillWorking()
  101. return peripheral.call("bottom","hasWork")
  102. end
  103.  
  104.  
  105. local currRad=1 -- 0 is the right, 1 is default (original direction), 2 is the left, 3 is the back
  106. local cacheSlot = {}
  107. function place(slotID)
  108. zz.select(slotID)
  109. if zz.getItemCount()>0 then
  110. return zz.place()
  111. end
  112. return false
  113. end
  114. function placeUp(slotID)
  115. zz.select(slotID)
  116. if zz.getItemCount()>0 then
  117. return zz.placeUp()
  118. end
  119. return false
  120. end
  121. function placeDown(slotID)
  122. zz.select(slotID)
  123. if zz.getItemCount()>0 then
  124. return zz.placeDown()
  125. end
  126. return false
  127. end
  128. function refuel(amount)
  129. while zz.getFuelLevel()<=math.abs(amount) do
  130. zz.select(16)
  131. zz.refuel(1)
  132. print("Refueling")
  133. end
  134. end
  135. function turnRight()
  136. while zz.turnRight() do
  137. currRad=(currRad-1)%4
  138. break
  139. end
  140. end
  141. function turnLeft()
  142. while zz.turnLeft() do
  143. currRad=(currRad+1)%4
  144. break
  145. end
  146. end
  147. function turnToRad(r)
  148. if currRad==r then
  149. return true
  150. end
  151. while currRad~=r do
  152. if currRad>r then
  153. turnRight()
  154. elseif currRad<r then
  155. turnLeft()
  156. end
  157. end
  158. end
  159. function alertForProblem(stringCauseOfProblem)
  160. zz.turnRight()
  161. zz.turnRight()
  162. zz.turnRight()
  163. zz.turnRight()
  164. print(stringCauseOfProblem)
  165. end
  166. function moveByX(ox)
  167. local x=currentX+ox
  168. turnToRad(0)
  169. refuel(ox)
  170. while ox~=0 do
  171. if ox<0 then
  172. if zz.back() then
  173. ox=ox+1
  174. currentX=currentX-1
  175. else
  176. alertForProblem("can not move - check fuel or obstacle")
  177. moveByX(ox)
  178. break
  179. end
  180. else
  181. if zz.forward() then
  182. ox=ox-1
  183. currentX=currentX+1
  184. else
  185. alertForProblem("can not move - check fuel or obstacle")
  186. moveByX(ox)
  187. break
  188. end
  189. end
  190. end
  191. end
  192. function moveByZ(oz)
  193. local z=currentZ+oz
  194. turnToRad(1)
  195. refuel(oz)
  196. while oz~=0 do
  197. if oz<0 then
  198. if zz.back() then
  199. oz=oz+1
  200. currentZ=currentZ-1
  201. else
  202. alertForProblem("can not move - check fuel or obstacle")
  203. moveByZ(oz)
  204. break
  205. end
  206. else
  207. if zz.forward() then
  208. oz=oz-1
  209. currentZ=currentZ+1
  210. else
  211. alertForProblem("can not move - check fuel or obstacle")
  212. moveByZ(oz)
  213. break
  214. end
  215. end
  216. end
  217. end
  218. function moveByY(oy)
  219. local y=currentY+oy
  220. refuel(oy)
  221. while oy~=0 do
  222. if oy<0 then
  223. if zz.down() then
  224. oy=oy+1
  225. currentY=currentY-1
  226. else
  227. alertForProblem("can not move down - check fuel or obstacle")
  228. moveByY(oy)
  229. break
  230. end
  231. else
  232. if zz.up() then
  233. oy=oy-1
  234. currentY=currentY+1
  235. else
  236. alertForProblem("can not move up - check fuel or obstacle")
  237. moveByY(oy)
  238. break
  239. end
  240. end
  241. end
  242. end
  243. function goToCord(y,x,z)
  244. local differenceX=x-(currentX)
  245. local differenceY=y-currentY
  246. local differenceZ=z-currentZ
  247. if differenceX~=0 then moveByX(differenceX) end
  248. if differenceY~=0 then moveByY(differenceY) end
  249. if differenceZ~=0 then moveByZ(differenceZ) end
  250. end
  251.  
  252. function placeAt(y,x,z,slotID)
  253. goToCord(y,x,z)
  254. if place(slotID) then return true
  255. else
  256. alertForProblem("can not place ahead - must be air ahead or do I have a material to place")
  257. placeAt(y,x,z,slotID)
  258. end
  259. end
  260. function placeUpAt(y,x,z,slotID)
  261. goToCord(y,x,z)
  262. if placeUp(slotID) then return true
  263. else
  264. alertForProblem("can not place up - must be air ahead or do I have a material to place")
  265. placeUpAt(y,x,z,slotID)
  266. end
  267. end
  268.  
  269. function placeDownAt(y,x,z,slotID)
  270. goToCord(y,x,z)
  271. if placeDown(slotID) then return true
  272. else
  273. alertForProblem("can not place down - must be air ahead or do I have a material to place")
  274. placeUpAt(y,x,z,slotID)
  275. end
  276. end
  277.  
  278.  
  279. local repeatUntil=1;
  280.  
  281. setCurrentItemsUndroppable();
  282. memorizeItemSlot();
  283. if (#args==1) and tonumber(args[1])>1 then
  284. repeatUntil=tonumber(args[1]);
  285. end
  286. for zd=1,repeatUntil do
  287. unloadSystems();
  288. turtle.select(4);
  289. goToCord(2,1,0);
  290. repeat
  291. os.sleep(1);
  292. until not isStillWorking();
  293.  
  294. --finished work, lets pack it up here
  295. dumpAllItemsAndReturnToWork();
  296. turtle.select(1);
  297. turtle.digDown();
  298. goToCord(2,0,1);
  299. repeat
  300. os.sleep(1);
  301. until not isStillWorking();
  302. dumpAllItemsAndReturnToWork();
  303. turtle.select(1);
  304. turtle.digDown();
  305. goToCord(2,-1,0);
  306. repeat
  307. os.sleep(1);
  308. until not isStillWorking();
  309. dumpAllItemsAndReturnToWork();
  310. turtle.select(1);
  311. turtle.digDown();
  312. goToCord(2,0,-1);
  313. repeat
  314. os.sleep(1);
  315. until not isStillWorking();
  316. dumpAllItemsAndReturnToWork();
  317. turtle.select(1);
  318. turtle.digDown();
  319. goToCord(2,0,0);
  320. turtle.select(2);
  321. turtle.digDown();
  322. goToCord(1,0,0);
  323. turtle.select(1);
  324. turtle.digDown();--destroying bottom well
  325. goToCord(0,0,0);
  326. if repeatUntil>1 then
  327. local moveForward=0;
  328. repeat
  329. if turtle.forward() then moveForward=moveForward+1; end
  330. until moveForward==3;
  331. end
  332. end
  333. print("done");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement