Advertisement
wolfking41

Untitled

May 7th, 2019
1,128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.91 KB | None | 0 0
  1.  
  2. X = 0
  3. Y = 0
  4. Z = 0
  5. FACE = 0 --North=0,East=1,South=2,West=3
  6.  
  7. HOME = {-659, 70, 75, 3}
  8. ORE_DEPOT = {-667, 70, 61, 3}
  9. COAL_DEPOT = {-667, 70, 64, 3}
  10. DIAMOND_DEPOT = {-667, 70, 67, 3}
  11. REDSTONE_DEPOT = {-667, 70, 70, 3}
  12. OTHER_DEPOT = {-667, 70, 82, 3}
  13. MINE_STAGING_AREA = {-661,70,37,0}
  14. MINE_EXIT_AREA = {-662,70,37,0}
  15. FURNACE_ROW_START = {-649,70,77}
  16.  
  17. STOPWATCH = 0
  18.  
  19. NOBREAK = {"minecraft:chest","minecraft:furnace","computercraft:turtle_expanded","minecraft:bedrock"}
  20.  
  21. TRASH = {"minecraft:cobblestone","minecraft:stone","minecraft:dirt","minecraft:sand",
  22. "minecraft:sandstone","chisel:limestone2","minecraft:red_sandstone","chisel:marble2",
  23. "minecraft:gravel","minecraft:quartz","minecraft:flint"}
  24.  
  25. ORES = {"minecraft:gold_ore","minecraft:iron_ore","thermalfoundation:ore","ic2:blockmetal",
  26. "galacticraftcore:basic_block_core"}
  27.  
  28.  
  29. KEEP = {"minecraft:gold_ore","minecraft:iron_ore","minecraft:diamond","minecraft:coal","minecraft:redstone",
  30. "minecraft:element_77","ic2:itemoreiridium","minecraft:emerald","minecraft:diamond_ore","minecraft:redstone_ore",
  31. "minecraft:lit_redstone_ore","minecraft:coal_ore","minecraft:emerald_ore"}
  32.  
  33. function isTrash(name)
  34. for _,v in pairs(KEEP) do
  35. if v == name then
  36. return false
  37. end
  38. end
  39. return true
  40. end
  41.  
  42. function dontBreak(block)
  43. for _,v in pairs(NOBREAK) do
  44. if v == name then
  45. return true
  46. end
  47. end
  48. return false
  49. end
  50.  
  51. function isOre(name)
  52. for _,v in pairs(ORES) do
  53. if v == name then
  54. return true
  55. end
  56. end
  57. return false
  58. end
  59.  
  60. function getCurrentLocation()
  61. local a = {X,Y,Z,FACE}
  62. return a
  63. end
  64.  
  65. function determineLocation()
  66. local x,y,z = gps.locate()
  67. if not x then
  68. X,Y,Z,FACE = getInitialCoordinates()
  69. else
  70. X=x
  71. Y=y
  72. Z=z
  73. findFacing()
  74. end
  75. end
  76.  
  77. function getInitialCoordinates()
  78. print("Input x position: ")
  79. local x = tonumber(read())
  80. print("Input y position: ")
  81. local y = tonumber(read())
  82. print("Input z position: ")
  83. local z = tonumber(read())
  84. print("Input facing position: ")
  85. local face = tonumber(read())
  86. return x,y,z,face
  87. end
  88.  
  89. function findFacing()
  90. local x1 = X
  91. local z1 = Z
  92. turtle.forward()
  93. local x2,y2,z2 = gps.locate()
  94. if x2>x1 then
  95. FACE = 1
  96. elseif x2<x1 then
  97. FACE = 3
  98. elseif z2>z1 then
  99. FACE = 2
  100. elseif z2<z1 then
  101. FACE = 0
  102. else
  103. print("UNABLE TO RESOLVE FACING DIRECTION")
  104. end
  105. turtle.back()
  106. end
  107.  
  108. function turnTowards(dir)
  109. if(dir==FACE) then
  110. return
  111. end
  112. if dir == (FACE +1)%4 then
  113. if(turtle.turnRight()) then
  114. FACE = (FACE+1)%4
  115. end
  116. else
  117. if turtle.turnLeft() then
  118. FACE = (FACE-1)%4
  119. end
  120. end
  121. end
  122.  
  123. function updatePosition()
  124. if FACE==0 then
  125. Z=Z-1
  126. end
  127. if FACE==1 then
  128. X=X+1
  129. end
  130. if FACE==2 then
  131. Z=Z+1
  132. end
  133. if FACE==3 then
  134. X=X-1
  135. end
  136. end
  137.  
  138. function updateAltitude(num)
  139. Y=Y+num
  140. end
  141.  
  142. function smartMoveForward()
  143.  
  144. STOPWATCH = STOPWATCH + 1
  145.  
  146. local blockPresent, data = turtle.inspect()
  147. if blockPresent then
  148. if dontBreak(data.name) then
  149. smartMoveUp()
  150. smartMoveForward()
  151. smartMoveForward()
  152. smartMoveDown()
  153. else
  154. turtle.dig()
  155. end
  156. end
  157. if turtle.forward() then
  158. updatePosition()
  159. end
  160. end
  161.  
  162.  
  163.  
  164. function smartMoveUp()
  165. local blockPresent, data = turtle.inspectUp()
  166. if blockPresent then
  167. if dontBreak(data.name) then
  168. smartMoveNorth()
  169. smartMoveUp()
  170. smartMoveUp()
  171. smartMoveSouth()
  172. else
  173. turtle.digUp()
  174. end
  175. end
  176. if turtle.up() then
  177. updateAltitude(1)
  178. end
  179. end
  180.  
  181. function password()
  182. print("Enter password: ")
  183. while true do
  184. pass = tonumber(read())
  185. if pass==4794 then
  186. return true
  187. end
  188. end
  189. end
  190.  
  191. function smartMoveDown()
  192. local blockPresent, data = turtle.inspectDown()
  193. if blockPresent then
  194. if dontBreak(data.name) then
  195. smartMoveNorth()
  196. smartMoveDown()
  197. smartMoveDown()
  198. smartMoveSouth()
  199. else
  200. turtle.digDown()
  201. end
  202. end
  203. if turtle.down() then
  204. updateAltitude(-1)
  205. end
  206. end
  207.  
  208. function smartMoveWest()
  209. while FACE~=3 do
  210. turnTowards(3)
  211. end
  212. return smartMoveForward()
  213. end
  214.  
  215.  
  216. function smartMoveEast()
  217. while FACE~=1 do
  218. turnTowards(1)
  219. end
  220. return smartMoveForward()
  221. end
  222.  
  223. function smartMoveNorth()
  224. while FACE~=0 do
  225. turnTowards(0)
  226. end
  227. return smartMoveForward()
  228. end
  229.  
  230. function smartMoveSouth()
  231. while FACE~=2 do
  232. turnTowards(2)
  233. end
  234. return smartMoveForward()
  235. end
  236.  
  237. function inspectUp()
  238. return turtle.inspectUp()
  239. end
  240.  
  241. function inspectDown()
  242. return turtle.inspectDown()
  243. end
  244.  
  245. function inspectWest()
  246. while FACE~=3 do
  247. turnTowards(3)
  248. end
  249. return turtle.inspect()
  250. end
  251.  
  252.  
  253. function inspectEast()
  254. while FACE~=1 do
  255. turnTowards(1)
  256. end
  257. return turtle.inspect()
  258. end
  259.  
  260. function inspectNorth()
  261. while FACE~=0 do
  262. turnTowards(0)
  263. end
  264. return turtle.inspect()
  265. end
  266.  
  267. function inspectSouth()
  268. while FACE~=2 do
  269. turnTowards(2)
  270. end
  271. return turtle.inspect()
  272. end
  273.  
  274. function moveto(loc)
  275. for i=1,50 do
  276. for j=1,100 do
  277. if Y>loc[2] then
  278. smartMoveDown()
  279. end
  280. if Y<loc[2] then
  281. smartMoveUp()
  282. end
  283. end
  284.  
  285. for j=1,100 do
  286. if X>loc[1] then
  287. smartMoveWest()
  288. end
  289. if X<loc[1] then
  290. smartMoveEast()
  291. end
  292. end
  293.  
  294. for j=1,100 do
  295. if Z>loc[3] then
  296. smartMoveNorth()
  297. end
  298. if Z<loc[3] then
  299. smartMoveSouth()
  300. end
  301. end
  302.  
  303. while FACE~=loc[4] do
  304. turnTowards(loc[4])
  305. end
  306. end
  307. end
  308.  
  309.  
  310. function surfaceWalk(loc)
  311. local block,data = turtle.inspectDown()
  312. if not block() then
  313. smartMoveDown()
  314. end
  315. block,data = turtle.inspect()
  316. end
  317.  
  318. function depositMaterials()
  319. moveto(ORE_DEPOT)
  320. for i=1,16 do
  321. if(turtle.getItemCount(i)>0) then
  322. if isOre(turtle.getItemDetail(i).name) then
  323. turtle.select(i)
  324. turtle.drop()
  325. end
  326. end
  327. end
  328. moveto(COAL_DEPOT)
  329. for i=1,16 do
  330. if(turtle.getItemCount(i)>0) then
  331. if turtle.getItemDetail(i).name=="minecraft:coal" then
  332. turtle.select(i)
  333. turtle.drop()
  334. end
  335. end
  336. end
  337. moveto(DIAMOND_DEPOT)
  338. for i=1,16 do
  339. if(turtle.getItemCount(i)>0) then
  340. if turtle.getItemDetail(i).name=="minecraft:diamond" then
  341. turtle.select(i)
  342. turtle.drop()
  343. end
  344. end
  345. end
  346. moveto(REDSTONE_DEPOT)
  347. for i=1,16 do
  348. if(turtle.getItemCount(i)>0) then
  349. if turtle.getItemDetail(i).name=="minecraft:redstone" then
  350. turtle.select(i)
  351. turtle.drop()
  352. end
  353. end
  354. end
  355. moveto(OTHER_DEPOT)
  356. for i=2,16 do
  357. if(turtle.getItemCount(i)>0) then
  358. turtle.select(i)
  359. turtle.drop()
  360. end
  361. end
  362.  
  363. end
  364.  
  365.  
  366. function veinFollow()
  367. local initialFacing = FACE
  368. local success,data = turtle.inspectUp()
  369. if success and not isTrash(data.name) then
  370. smartMoveUp()
  371. veinFollow()
  372. smartMoveDown()
  373. end
  374.  
  375. success,data = turtle.inspectDown()
  376. if success and not isTrash(data.name) then
  377. smartMoveDown()
  378. veinFollow(material)
  379. smartMoveUp()
  380. end
  381.  
  382. success,data = inspectNorth()
  383. if success and not isTrash(data.name) then
  384. smartMoveNorth()
  385. veinFollow()
  386. smartMoveSouth()
  387. end
  388.  
  389. success,data = inspectEast()
  390. if success and not isTrash(data.name) then
  391. smartMoveEast()
  392. veinFollow()
  393. smartMoveWest()
  394. end
  395.  
  396. success,data = inspectSouth()
  397. if success and not isTrash(data.name) then
  398. smartMoveSouth()
  399. veinFollow()
  400. smartMoveNorth()
  401. end
  402.  
  403. success,data = inspectWest()
  404. if success and not isTrash(data.name) then
  405. smartMoveWest()
  406. veinFollow()
  407. smartMoveEast()
  408. end
  409.  
  410. turnTowards(initialFacing)
  411. turnTowards(initialFacing)
  412.  
  413. end
  414.  
  415. function dumpTrash()
  416. for i=2,16 do
  417. if(turtle.getItemCount(i)>0) then
  418. if isTrash(turtle.getItemDetail(i).name) then
  419. turtle.select(i)
  420. turtle.drop()
  421. end
  422. end
  423. end
  424. end
  425.  
  426. function inventoryFull()
  427. for i=1,16 do
  428. if turtle.getItemCount(i)==0 then
  429. return false
  430. end
  431. end
  432. return true
  433. end
  434.  
  435.  
  436. function isFullLava(success,data)
  437. return success and (data.name=="minecraft:lava" or data.name=="minecraft:flowing_lava") and data.state.level==0
  438. end
  439.  
  440. function collectLava()
  441.  
  442. local initialFacing = FACE
  443.  
  444. print("collecting lava")
  445. print(turtle.getFuelLevel())
  446. if isFullLava(inspectUp()) and turtle.getFuelLevel() < 19000 then
  447. turtle.select(1)
  448. turtle.placeUp()
  449. turtle.refuel()
  450. smartMoveUp()
  451. collectLava()
  452. smartMoveDown()
  453. end
  454.  
  455. if isFullLava(inspectDown()) and turtle.getFuelLevel() < 19000 then
  456. turtle.select(1)
  457. turtle.placeDown()
  458. turtle.refuel()
  459. smartMoveDown()
  460. collectLava()
  461. smartMoveUp()
  462. end
  463.  
  464. if isFullLava(inspectNorth()) and turtle.getFuelLevel() < 19000 then
  465. turtle.select(1)
  466. turtle.place()
  467. turtle.refuel()
  468. smartMoveNorth()
  469. collectLava()
  470. smartMoveSouth()
  471. end
  472.  
  473. if isFullLava(inspectEast()) and turtle.getFuelLevel() < 19000 then
  474. turtle.select(1)
  475. turtle.place()
  476. turtle.refuel()
  477. smartMoveEast()
  478. collectLava()
  479. smartMoveWest()
  480. end
  481.  
  482. if isFullLava(inspectSouth()) and turtle.getFuelLevel() < 19000 then
  483. turtle.select(1)
  484. turtle.place()
  485. turtle.refuel()
  486. smartMoveSouth()
  487. collectLava()
  488. smartMoveNorth()
  489. end
  490.  
  491. if isFullLava(inspectWest()) and turtle.getFuelLevel() < 19000 then
  492. turtle.select(1)
  493. turtle.place()
  494. turtle.refuel()
  495. smartMoveWest()
  496. collectLava()
  497. smartMoveEast()
  498. end
  499.  
  500. turnTowards(initialFacing)
  501. turnTowards(initialFacing)
  502.  
  503. end
  504.  
  505. function mine(loc)
  506. success,data = turtle.inspectUp()
  507. if success then
  508. if isFullLava(success,data) then
  509. collectLava()
  510. end
  511. if not isTrash(data.name) then
  512. turtle.digUp()
  513. smartMoveUp()
  514. veinFollow()
  515. smartMoveDown()
  516. end
  517. end
  518.  
  519. success,data = turtle.inspectDown()
  520. if success then
  521. if isFullLava(success,data) then
  522. collectLava()
  523. end
  524. if not isTrash(data.name) then
  525. turtle.digDown()
  526. smartMoveDown()
  527. veinFollow()
  528. smartMoveUp()
  529. end
  530. end
  531.  
  532. success,data = turtle.inspect()
  533. if success then
  534. if isFullLava(success,data) then
  535. collectLava()
  536. end
  537. if not isTrash(data.name) then
  538. turtle.dig()
  539. smartMoveForward()
  540. veinFollow()
  541. else
  542. turtle.dig()
  543. end
  544. end
  545. end
  546.  
  547. function fillInventory()
  548. for i=2,16 do
  549. turtle.select(i)
  550. turtle.suck()
  551. end
  552. end
  553.  
  554. function mineLayer(loc,width,depth)
  555. moveto(loc)
  556. for j=1,(width/2) do
  557. for i=1,depth do
  558. smartMoveNorth()
  559. mine()
  560. end
  561. smartMoveWest()
  562. for i=1,depth do
  563. smartMoveSouth()
  564. mine()
  565. end
  566. smartMoveWest()
  567. dumpTrash()
  568. end
  569. end
  570.  
  571. function mineLoop()
  572. moveto(MINE_STAGING_AREA)
  573. local mineLocation = {X+math.random(-100,100), 15, Z+math.random(-100,100), FACE}
  574. moveto(mineLocation)
  575. while turtle.getFuelLevel()>1000 and not inventoryFull() and STOPWATCH<2000 do
  576. mineLayer(mineLocation,20,20)
  577. if mineLocation[2] >= 9 then
  578. mineLocation[2] = mineLocation[2]-3
  579. else
  580. if turtle.getFuelLevel()>12000 then
  581. mineLocation = {X+math.random(-20,20), 40+math.random(-10,10), Z+math.random(-20,20), FACE}
  582. else
  583. mineLocation = {X+math.random(-20,20), 15, Z+math.random(-20,20), FACE}
  584. end
  585. end
  586. end
  587. moveto(MINE_EXIT_AREA)
  588. depositMaterials()
  589. moveto(HOME)
  590. end
  591.  
  592.  
  593. function main()
  594.  
  595. determineLocation()
  596. while turtle.getFuelLevel()>2000 do
  597. mineLoop()
  598. end
  599. end
  600.  
  601. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement