bjohnston562

test

Jan 16th, 2021 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.83 KB | None | 0 0
  1. function serialize(data, name) -- this is for setting the variable "data" what you want and "name" is the file name. when saving a number to the file make sure to write as tonumber(read()) (this overwrites each time)
  2. if not fs.exists('/data') then
  3. fs.makeDir('/data')
  4. end
  5. local f = fs.open('/data/'..name, 'w')
  6. f.write(textutils.serialize(data))
  7. f.close()
  8. end
  9.  
  10. function unserialize(name) --this will bring up the file name in my program i need to make x = unserialize(name) this will set my variable to the saved number
  11. if fs.exists('/data/'..name) then
  12. local f = fs.open('/data/'..name, 'r')
  13. data = textutils.unserialize(f.readAll())
  14. f.close()
  15. end
  16. return data
  17. end
  18.  
  19. --this sets up a host computer for gps network (below text)
  20. --shell.run("gps","host",x,y,z)
  21. --then on the turtle side you can set x, y, z = gps.locate(1) the one is the time till it times out if it cant find position
  22.  
  23. function recieve() --this is the recieve side to run scripts
  24. modem = peripheral.wrap("left")
  25. modem.open(0)
  26. while true do
  27. event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  28.  
  29. if message == "up" then
  30. turtle.up()
  31. end
  32.  
  33. if message == "down" then
  34. turtle.down()
  35. end
  36. end
  37. end
  38.  
  39. function getHeading() --gets heading and stores it in file = heading and variable is p (1 north is negative, 3 south is positive, 4 east is negative, and 2 west is positive )
  40. loc1 = vector.new(gps.locate(2,false))
  41. for i = 1,10 do
  42. if turtle.detect() == true then
  43. turtle.dig()
  44. else
  45. end
  46. end
  47. turtle.forward()
  48. loc2 = vector.new(gps.locate(2,false))
  49. if loc2.z - loc1.z < 0 then
  50. p = 1
  51. elseif loc2.x - loc1.x > 0 then
  52. p = 2
  53. elseif loc2.z - loc1.z > 0 then
  54. p = 3
  55. elseif loc2.x - loc1.x < 0 then
  56. p = 4
  57. end
  58. serialize(p, "heading")
  59. end
  60.  
  61. function dig() --dig and sleeps
  62. turtle.dig()
  63. end
  64.  
  65. function digup()
  66. turtle.digUp()
  67. end
  68.  
  69. function digdown()
  70. turtle.digDown()
  71. end
  72.  
  73. function forward() --forward and sleeps
  74. --[[
  75. local success, infront = turtle.inspect()
  76. local success, above = turtle.inspectUp()
  77. local success, below = turtle.inspectDown()
  78. if infront.name == "minecraft:lava" or infront.name == "minecraft:flowing_lava" or above.name == "minecraft:flowing_lava" or above.name == "minecraft:lava" then
  79. if turtle.getItemCount(2) > 5 then
  80. turtle.select(2)
  81. turtle.place()
  82. left()
  83. turtle.place()
  84. right()
  85. right()
  86. turtle.place()
  87. left()
  88. turtle.placeUp()
  89. turtle.placeDown()
  90. turtle.dig()
  91. turtle.forward()
  92.  
  93. elseif turtle.getItemCount(3) > 5 then
  94. turtle.select(3)
  95. turtle.place()
  96. left()
  97. turtle.place()
  98. right()
  99. right()
  100. turtle.place()
  101. left()
  102. turtle.placeUp()
  103. turtle.placeDown()
  104. turtle.dig()
  105. turtle.forward()
  106.  
  107. elseif turtle.getItemCount(4) > 5 then
  108. turtle.select(4)
  109. turtle.place()
  110. turtle.turnLeft()
  111. turtle.place()
  112. turtle.turnRight()
  113. turtle.turnRight()
  114. turtle.place()
  115. turtle.turnLeft()
  116. turtle.placeUp()
  117. turtle.placeDown()
  118. turtle.dig()
  119. turtle.forward()
  120.  
  121. end
  122. elseif below.name == "minecraft:lava" or below.name == "minecraft:flowing_lava" then
  123. if turtle.getItemCount(2) > 5 then
  124. turtle.select(2)
  125. turtle.placeDown()
  126. turtle.dig()
  127. turtle.forward()
  128.  
  129. elseif turtle.getItemCount(3) > 5 then
  130. turtle.select(3)
  131. turtle.placeDown()
  132. turtle.dig()
  133. turtle.forward()
  134.  
  135. elseif turtle.getItemCount(4) > 5 then
  136. turtle.select(4)
  137. turtle.placeDown()
  138. turtle.dig()
  139. turtle.forward()
  140.  
  141. end
  142. end
  143. --]]
  144. while turtle.forward() == false do
  145. sleep(1)
  146. turtle.dig()
  147. end
  148. if heading == 1 then
  149. z_c_f = z_c_i - 1
  150. z_c_i = z_c_f
  151. elseif heading == 2 then
  152. x_c_f = x_c_i + 1
  153. x_c_i = x_c_f
  154. elseif heading == 3 then
  155. z_c_f = z_c_i + 1
  156. z_c_i = z_c_f
  157. elseif heading == 4 then
  158. x_c_f = x_c_i - 1
  159. x_c_i = x_c_f
  160. end
  161. serialize(x_c_f, "xfinal")
  162. serialize(z_c_f, "zfinal")
  163. end
  164.  
  165. function right() --turns right and sleeps
  166. turtle.turnRight()
  167.  
  168. if heading <= 3 then
  169. heading = heading + 1
  170. else
  171. heading = 1
  172. end
  173. end
  174.  
  175. function left() --turns left and sleeps
  176. turtle.turnLeft()
  177.  
  178. if heading >= 2 then
  179. heading = heading - 1
  180. else
  181. heading = 4
  182. end
  183. end
  184.  
  185. function down() --goes down and sleeps
  186. turtle.down()
  187. y_c_f = y_c_i - 1
  188. y_c_i = y_c_f
  189. serialize(y_c_f, "yfinal")
  190. end
  191.  
  192. function up() --goes up and sleeps
  193. turtle.up()
  194. y_c_f = y_c_i + 1
  195. y_c_i = y_c_f
  196. serialize(y_c_f, "yfinal")
  197. end
  198.  
  199. function inspect()
  200. turtle.inspect()
  201. end
  202.  
  203. function detect()
  204. turtle.detect()
  205. end
  206.  
  207. function clearinventory()
  208. for i = 5, 16 do
  209. turtle.select(i)
  210. turtle.dropUp()
  211. end
  212. turtle.select(5)
  213. end
  214.  
  215. function backtostart()
  216.  
  217. x_c_f = x_c_f - x_i
  218. y_c_f = y_c_f - y_i
  219. z_c_f = z_c_f - z_i
  220.  
  221. print(x_c_f)
  222. print(y_c_f)
  223. print(z_c_f)
  224.  
  225.  
  226. if x_c_f == 0 then
  227. movex = 0
  228. else
  229. movex = x_c_f - x_i
  230. end
  231. if y_c_f == 0 then
  232. movey = 0
  233. else
  234. movey = y_c_f - y_i
  235. end
  236. if z_c_f == 0 then
  237. movez = 0
  238. else
  239. movez = z_c_f - z_i
  240. end
  241.  
  242. --move the turtle to correct y position
  243. if movey > 0 then
  244. for i = 1, movey do
  245. while digdown() == true do
  246. digdown()
  247. end
  248. down()
  249. end
  250. else
  251. for i = -1, movey, -1 do
  252. while digup() == true do
  253. digup()
  254. end
  255. up()
  256. end
  257. end
  258. --move the turtle to correct x position
  259. if movex > 0 then
  260. if heading == 1 then
  261. left()
  262. for i = 1, movex do
  263. while dig() == true do
  264. dig()
  265. end
  266. forward()
  267. end
  268. elseif heading == 2 then
  269. right()
  270. right()
  271. for i = 1, movex do
  272. while dig() == true do
  273. dig()
  274. end
  275. forward()
  276. end
  277. elseif heading == 3 then
  278. right()
  279. for i = 1, movex do
  280. while dig() == true do
  281. dig()
  282. end
  283. forward()
  284. end
  285. elseif heading == 4 then
  286. for i = 1, movex do
  287. while dig() == true do
  288. dig()
  289. end
  290. forward()
  291. end
  292. end
  293. elseif movex == 0 then
  294. elseif movex < 0 then
  295. if heading == 1 then
  296. right()
  297. for i = -1, movex, -1 do
  298. while dig() == true do
  299. dig()
  300. end
  301. forward()
  302. end
  303. elseif heading == 2 then
  304. for i = -1, movex, -1 do
  305. while dig() == true do
  306. dig()
  307. end
  308. forward()
  309. end
  310. elseif heading == 3 then
  311. left()
  312. for i = -1, movex, -1 do
  313. while dig() == true do
  314. dig()
  315. end
  316. forward()
  317. end
  318. elseif heading == 4 then
  319. right()
  320. right()
  321. for i = -1, movex, -1 do
  322. while dig() == true do
  323. dig()
  324. end
  325. forward()
  326. end
  327. end
  328.  
  329. end
  330. --move turtle to correct z position
  331. if movez < 0 then
  332. if heading == 1 then
  333. right()
  334. right()
  335. for i = -1, movez, -1 do
  336. while dig() == true do
  337. dig()
  338. end
  339. forward()
  340. end
  341. elseif heading == 2 then
  342. right()
  343. for i = -1, movez, -1 do
  344. while dig() == true do
  345. dig()
  346. end
  347. forward()
  348. end
  349. elseif heading == 3 then
  350. for i = -1, movez, -1 do
  351. while dig() == true do
  352. dig()
  353. end
  354. forward()
  355. end
  356. elseif heading == 4 then
  357. left()
  358. for i = -1, movez, -1 do
  359. while dig() == true do
  360. dig()
  361. end
  362. forward()
  363. end
  364. end
  365. elseif movez == 0 then
  366. elseif movez > 0 then
  367. if heading == 1 then
  368. for i = 1, movez do
  369. while dig() == true do
  370. dig()
  371. end
  372. forward()
  373. end
  374. elseif heading == 2 then
  375. left()
  376. for i = 1, movez do
  377. while dig() == true do
  378. dig()
  379. end
  380. forward()
  381. end
  382. elseif heading == 3 then
  383. right()
  384. right()
  385. for i = 1, movez do
  386. while dig() == true do
  387. dig()
  388. end
  389. forward()
  390. end
  391. elseif heading == 4 then
  392. right()
  393. for i = 1, movez do
  394. while dig() == true do
  395. dig()
  396. end
  397. forward()
  398. end
  399. end
  400. end
  401. end
  402.  
  403. function returntowork()
  404. x_c_f = unserialize("xreturn")
  405. y_c_f = unserialize("yreturn")
  406. z_c_f = unserialize("zreturn")
  407.  
  408. x_c_f = x_c_f*1
  409. y_c_f = y_c_f*1
  410. z_c_f = z_c_f*1
  411.  
  412. if x_c_f == 0 then
  413. movex = 0
  414. else
  415. movex = x_c_f - x_i
  416. end
  417. if y_c_f == 0 then
  418. movey = 0
  419. else
  420. movey = y_c_f - y_i
  421. end
  422. if z_c_f == 0 then
  423. movez = 0
  424. else
  425. movez = z_c_f - z_i
  426. end
  427.  
  428. --move turtle to correct z position
  429. if movez < 0 then
  430. if heading == 1 then
  431. for i = -1, movez, -1 do
  432. while dig() == true do
  433. dig()
  434. end
  435. forward()
  436. end
  437. elseif heading == 2 then
  438. left()
  439. for i = -1, movez, -1 do
  440. while dig() == true do
  441. dig()
  442. end
  443. forward()
  444. end
  445. elseif heading == 3 then
  446. right()
  447. right()
  448. for i = -1, movez, -1 do
  449. while dig() == true do
  450. dig()
  451. end
  452. forward()
  453. end
  454. elseif heading == 4 then
  455. right()
  456. for i = -1, movez, -1 do
  457. while dig() == true do
  458. dig()
  459. end
  460. forward()
  461. end
  462. end
  463. elseif movez == 0 then
  464. elseif movez > 0 then
  465. if heading == 1 then
  466. right()
  467. right()
  468. for i = 1, movez do
  469. while dig() == true do
  470. dig()
  471. end
  472. forward()
  473. end
  474. elseif heading == 2 then
  475. right()
  476. for i = 1, movez do
  477. while dig() == true do
  478. dig()
  479. end
  480. forward()
  481. end
  482. elseif heading == 3 then
  483. for i = 1, movez do
  484. while dig() == true do
  485. dig()
  486. end
  487. forward()
  488. end
  489. elseif heading == 4 then
  490. left()
  491. for i = 1, movez do
  492. while dig() == true do
  493. dig()
  494. end
  495. forward()
  496. end
  497. end
  498. end
  499. --move the turtle to correct x position
  500. if movex > 0 then
  501. if heading == 1 then
  502. right()
  503. for i = 1, movex do
  504. while dig() == true do
  505. dig()
  506. end
  507. forward()
  508. end
  509. elseif heading == 2 then
  510. for i = 1, movex do
  511. while dig() == true do
  512. dig()
  513. end
  514. forward()
  515. end
  516. elseif heading == 3 then
  517. left()
  518. for i = 1, movex do
  519. while dig() == true do
  520. dig()
  521. end
  522. forward()
  523. end
  524. elseif heading == 4 then
  525. right()
  526. right()
  527. for i = 1, movex do
  528. while dig() == true do
  529. dig()
  530. end
  531. forward()
  532. end
  533. end
  534. elseif movex == 0 then
  535. elseif movex < 0 then
  536. if heading == 1 then
  537. left()
  538. for i = -1, movex do
  539. while dig() == true do
  540. dig()
  541. end
  542. forward()
  543. end
  544. elseif heading == 2 then
  545. right()
  546. right()
  547. for i = -1, movex do
  548. while dig() == true do
  549. dig()
  550. end
  551. forward()
  552. end
  553. elseif heading == 3 then
  554. right()
  555. for i = -1, movex do
  556. while dig() == true do
  557. dig()
  558. end
  559. forward()
  560. end
  561. elseif heading == 4 then
  562. for i = -1, movex do
  563. while dig() == true do
  564. dig()
  565. end
  566. forward()
  567. end
  568. end
  569.  
  570. end
  571. --move the turtle to correct y position
  572. if movey > 0 then
  573. for i = 1, movey do
  574. while digup() == true do
  575. digup()
  576. end
  577. up()
  578. end
  579. else
  580. for i = -1, movey, -1 do
  581. while digdown() == true do
  582. digdown()
  583. end
  584. down()
  585. end
  586. end
  587.  
  588. headingreturn = tonumber(unserialize("headingreturn"))
  589. while heading ~= headingreturn do
  590. right()
  591. end
  592. end
  593.  
  594. function inventorycheck()
  595. if turtle.getItemCount(16) > 0 then
  596. serialize(x_c_f, "xreturn")
  597. serialize(y_c_f, "yreturn")
  598. serialize(z_c_f, "zreturn")
  599. serialize(heading, "headingreturn")
  600. backtostart()
  601. clearinventory()
  602. returntowork()
  603. else
  604. end
  605. end
  606.  
  607. function refuel()
  608. if turtle.getItemCount(1) == 0 then
  609. backtostart()
  610. print("Waiting for fuel to be placed in slot 1.")
  611. while turtle.getItemCount == 0 do
  612. sleep(1)
  613. end
  614. while turtle.getFuelLevel() <1000 do
  615. turtle.select(1)
  616. turtle.refuel()
  617. end
  618. returntowork()
  619. elseif turtle.getItemCount(1) > 0 then
  620. while turtle.getFuelLevel() <1000 do
  621. turtle.select(1)
  622. turtle.refuel()
  623. end
  624. end
  625. end
  626.  
  627. function digcubebottomleft() --efficiently mines out an area determined by the user
  628. print("Place coal blocks or coal in slot 1. Also place a stack of cobblestone in slots 2, 3, 4. Also dig a pit trap 2 blocks in front of the turtle in case a mob spawns in front of it.")
  629.  
  630. print("What is the width? this number expands to the right with the first part of the cube being in front of the turtle.")
  631. w = tonumber(read())
  632.  
  633. print("What is the length? This number expands into the area you are excavating.")
  634. l = tonumber(read())
  635.  
  636. print("What is the height? This number is the how many blocks up the cube expands up from starting position")
  637. h = tonumber(read())
  638.  
  639. print("what is the current direction the turtle is facing? (type 1 for north, 2 for east, 3 for south and 4 for west)")
  640. heading = tonumber(read())
  641.  
  642. while dig() == true do --this get the turtle into position
  643. dig()
  644. end
  645. forward()
  646. if l > w and l > h then --if the cube has a long length like a tunnel this will be the function it follows
  647. for a = 1, h do
  648. for b = 1, w do --this digs into the cube
  649. for c = 1, (l-1) do --this digs the length
  650. while dig() == true do
  651. dig()
  652. end
  653. forward()
  654. refuel()
  655. inventorycheck()
  656. end
  657. if w%2 == 1 then
  658. if b < w then
  659. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  660. right()
  661. while dig() == true do
  662. dig()
  663. end
  664. forward()
  665. right()
  666. else
  667. left()
  668. while dig() == true do
  669. dig()
  670. end
  671. forward()
  672. left()
  673. end
  674. else
  675. end
  676. else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
  677. if b < w then
  678. if a%2 == 1 then
  679. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  680. right()
  681. while dig() == true do
  682. dig()
  683. end
  684. forward()
  685. right()
  686. else
  687. left()
  688. while dig() == true do
  689. dig()
  690. end
  691. forward()
  692. left()
  693. end
  694. else
  695. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  696. left()
  697. while dig() == true do
  698. dig()
  699. end
  700. forward()
  701. left()
  702. else
  703. right()
  704. while dig() == true do
  705. dig()
  706. end
  707. forward()
  708. right()
  709. end
  710. end
  711. else
  712. end
  713. end
  714. end
  715. if a < h then
  716. while digup() == true do --this is to go up to next layer
  717. digup()
  718. end
  719. up()
  720. right()
  721. right()
  722. else
  723. end
  724. end
  725. elseif w > l and w > h then -- this is when the width is greater than the length and height
  726. for d = 1 , l-1 do
  727. while dig() == true do
  728. dig()
  729. end
  730. forward()
  731. end
  732. right()
  733. for a = 1, h do
  734. for b = 1, l do --this digs into the cube
  735. for c = 1, (w-1) do --this digs the length
  736. while dig() == true do
  737. dig()
  738. end
  739. forward()
  740. refuel()
  741. inventorycheck()
  742. end
  743. if w%2 == 1 then
  744. if b < l then
  745. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  746. right()
  747. while dig() == true do
  748. dig()
  749. end
  750. forward()
  751. right()
  752. else
  753. left()
  754. while dig() == true do
  755. dig()
  756. end
  757. forward()
  758. left()
  759. end
  760. else
  761. end
  762. else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
  763. if b < l then
  764. if a%2 == 1 then
  765. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  766. right()
  767. while dig() == true do
  768. dig()
  769. end
  770. forward()
  771. right()
  772. else
  773. left()
  774. while dig() == true do
  775. dig()
  776. end
  777. forward()
  778. left()
  779. end
  780. else
  781. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  782. left()
  783. while dig() == true do
  784. dig()
  785. end
  786. forward()
  787. left()
  788. else
  789. right()
  790. while dig() == true do
  791. dig()
  792. end
  793. forward()
  794. right()
  795. end
  796. end
  797. else
  798. end
  799. end
  800. end
  801. if a < h then
  802. while digup() == true do --this is to go up to next layer
  803. digup()
  804. end
  805. up()
  806. right()
  807. right()
  808. else
  809. end
  810. end
  811. elseif h > w and h > l then
  812. for a = 1, w do
  813. for b = 1, l do --this digs into the cube
  814. for c = 1, (h-1) do --this digs the length
  815. if l%2 == 1 then
  816. if a%2 == 1 then
  817. if b%2 == 1 then
  818. while digup() == true do
  819. digup()
  820. end
  821. up()
  822. refuel()
  823. inventorycheck()
  824. else
  825. while digdown() == true do
  826. digdown()
  827. end
  828. down()
  829. inventorycheck()
  830. end
  831. else
  832. if b%2 == 1 then
  833. while digdown() == true do
  834. digdown()
  835. end
  836. down()
  837. inventorycheck()
  838. else
  839. while digup() == true do
  840. digup()
  841. end
  842. up()
  843. inventorycheck()
  844. end
  845.  
  846. end
  847. else
  848. if b%2 == 1 then
  849. while digup() == true do
  850. digup()
  851. end
  852. up()
  853. inventorycheck()
  854. else
  855. while digdown() == true do
  856. digdown()
  857. end
  858. down()
  859. inventorycheck()
  860. end
  861. end
  862. end
  863. if b < l then
  864. while dig() == true do
  865. dig()
  866. end
  867. forward()
  868. else
  869. end
  870. end
  871. if a < w then
  872. if a%2 == 1 then
  873. right()
  874. while dig() == true do
  875. dig()
  876. end
  877. forward()
  878. right()
  879. else
  880. left()
  881. while dig() == true do
  882. dig()
  883. end
  884. forward()
  885. left()
  886. end
  887. else
  888. end
  889. end
  890. elseif w == l then
  891. for a = 1, h do
  892. for b = 1, w do --this digs into the cube
  893. for c = 1, (l-1) do --this digs the length
  894. while dig() == true do
  895. dig()
  896. end
  897. forward()
  898. refuel()
  899. inventorycheck()
  900. end
  901. if w%2 == 1 then
  902. if b < w then
  903. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  904. right()
  905. while dig() == true do
  906. dig()
  907. end
  908. forward()
  909. right()
  910. else
  911. left()
  912. while dig() == true do
  913. dig()
  914. end
  915. forward()
  916. left()
  917. end
  918. else
  919. end
  920. else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
  921. if b < w then
  922. if a%2 == 1 then
  923. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  924. right()
  925. while dig() == true do
  926. dig()
  927. end
  928. forward()
  929. right()
  930. else
  931. left()
  932. while dig() == true do
  933. dig()
  934. end
  935. forward()
  936. left()
  937. end
  938. else
  939. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  940. left()
  941. while dig() == true do
  942. dig()
  943. end
  944. forward()
  945. left()
  946. else
  947. right()
  948. while dig() == true do
  949. dig()
  950. end
  951. forward()
  952. right()
  953. end
  954. end
  955. else
  956. end
  957. end
  958. end
  959. if a < h then
  960. while digup() == true do --this is to go up to next layer
  961. digup()
  962. end
  963. up()
  964. right()
  965. right()
  966. else
  967. end
  968. end
  969. elseif w == h then
  970. for d = 1 , l-1 do
  971. while dig() == true do
  972. dig()
  973. end
  974. forward()
  975. refuel()
  976. inventorycheck()
  977. end
  978. right()
  979. for a = 1, h do
  980. for b = 1, l do --this digs into the cube
  981. for c = 1, (w-1) do --this digs the length
  982. while dig() == true do
  983. dig()
  984. refuel()
  985. inventorycheck()
  986. end
  987. forward()
  988. end
  989. if w%2 == 1 then
  990. if b < l then
  991. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  992. right()
  993. while dig() == true do
  994. dig()
  995. end
  996. forward()
  997. right()
  998. else
  999. left()
  1000. while dig() == true do
  1001. dig()
  1002. end
  1003. forward()
  1004. left()
  1005. end
  1006. else
  1007. end
  1008. else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
  1009. if b < l then
  1010. if a%2 == 1 then
  1011. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1012. right()
  1013. while dig() == true do
  1014. dig()
  1015. end
  1016. forward()
  1017. right()
  1018. else
  1019. left()
  1020. while dig() == true do
  1021. dig()
  1022. end
  1023. forward()
  1024. left()
  1025. end
  1026. else
  1027. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1028. left()
  1029. while dig() == true do
  1030. dig()
  1031. end
  1032. forward()
  1033. left()
  1034. else
  1035. right()
  1036. while dig() == true do
  1037. dig()
  1038. end
  1039. forward()
  1040. right()
  1041. end
  1042. end
  1043. else
  1044. end
  1045. end
  1046. end
  1047. if a < h then
  1048. while digup() == true do --this is to go up to next layer
  1049. digup()
  1050. end
  1051. up()
  1052. right()
  1053. right()
  1054. else
  1055. end
  1056. end
  1057. elseif h == l then
  1058. for a = 1, h do
  1059. for b = 1, w do --this digs into the cube
  1060. for c = 1, (l-1) do --this digs the length
  1061. while dig() == true do
  1062. dig()
  1063. end
  1064. forward()
  1065. refuel()
  1066. inventorycheck()
  1067. end
  1068. if w%2 == 1 then
  1069. if b < w then
  1070. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1071. right()
  1072. while dig() == true do
  1073. dig()
  1074. end
  1075. forward()
  1076. right()
  1077. else
  1078. left()
  1079. while dig() == true do
  1080. dig()
  1081. end
  1082. forward()
  1083. left()
  1084. end
  1085. else
  1086. end
  1087. else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
  1088. if b < w then
  1089. if a%2 == 1 then
  1090. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1091. right()
  1092. while dig() == true do
  1093. dig()
  1094. end
  1095. forward()
  1096. right()
  1097. else
  1098. left()
  1099. while dig() == true do
  1100. dig()
  1101. end
  1102. forward()
  1103. left()
  1104. end
  1105. else
  1106. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1107. left()
  1108. while dig() == true do
  1109. dig()
  1110. end
  1111. forward()
  1112. left()
  1113. else
  1114. right()
  1115. while dig() == true do
  1116. dig()
  1117. end
  1118. forward()
  1119. right()
  1120. end
  1121. end
  1122. else
  1123. end
  1124. end
  1125. end
  1126. if a < h then
  1127. while digup() == true do --this is to go up to next layer
  1128. digup()
  1129. end
  1130. up()
  1131. right()
  1132. right()
  1133. else
  1134. end
  1135. end
  1136. elseif w == h and l == h then
  1137. for a = 1, h do
  1138. for b = 1, w do --this digs into the cube
  1139. for c = 1, (l-1) do --this digs the length
  1140. while dig() == true do
  1141. dig()
  1142. end
  1143. forward()
  1144. refuel()
  1145. inventorycheck()
  1146. end
  1147. if w%2 == 1 then
  1148. if b < w then
  1149. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1150. right()
  1151. while dig() == true do
  1152. dig()
  1153. end
  1154. forward()
  1155. right()
  1156. else
  1157. left()
  1158. while dig() == true do
  1159. dig()
  1160. end
  1161. forward()
  1162. left()
  1163. end
  1164. else
  1165. end
  1166. else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
  1167. if b < w then
  1168. if a%2 == 1 then
  1169. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1170. right()
  1171. while dig() == true do
  1172. dig()
  1173. end
  1174. forward()
  1175. right()
  1176. else
  1177. left()
  1178. while dig() == true do
  1179. dig()
  1180. end
  1181. forward()
  1182. left()
  1183. end
  1184. else
  1185. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1186. left()
  1187. while dig() == true do
  1188. dig()
  1189. end
  1190. forward()
  1191. left()
  1192. else
  1193. right()
  1194. while dig() == true do
  1195. dig()
  1196. end
  1197. forward()
  1198. right()
  1199. end
  1200. end
  1201. else
  1202. end
  1203. end
  1204. end
  1205. if a < h then
  1206. while digup() == true do --this is to go up to next layer
  1207. digup()
  1208. end
  1209. up()
  1210. right()
  1211. right()
  1212. else
  1213. end
  1214. end
  1215. end
  1216. backtostart()
  1217. clearinventory()
  1218. end
  1219.  
  1220. function digcubetopleft() --efficiently mines out an area determined by the user
  1221. print("Place coal blocks or coal in slot 1. Also place a stack of cobblestone in slots 2, 3, 4. Also dig a pit trap 2 blocks in front of the turtle in case a mob spawns in front of it.")
  1222.  
  1223. print("What is the width? this number expands to the right with the first part of the cube being in front of the turtle.")
  1224. w = tonumber(read())
  1225.  
  1226. print("What is the length? This number expands into the area you are excavating.")
  1227. l = tonumber(read())
  1228.  
  1229. print("What is the height? This number is the how many blocks up the cube expands up from starting position")
  1230. h = tonumber(read())
  1231.  
  1232. print("what is the current direction the turtle is facing? (type 1 for north, 2 for east, 3 for south and 4 for west)")
  1233. heading = tonumber(read())
  1234.  
  1235. while dig() == true do --this get the turtle into position
  1236. dig()
  1237. end
  1238. forward()
  1239. if l > w and l > h then --if the cube has a long length like a tunnel this will be the function it follows
  1240. for a = 1, h do
  1241. for b = 1, w do --this digs into the cube
  1242. for c = 1, (l-1) do --this digs the length
  1243. while dig() == true do
  1244. dig()
  1245. end
  1246. forward()
  1247. refuel()
  1248. inventorycheck()
  1249. end
  1250. if w%2 == 1 then
  1251. if b < w then
  1252. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1253. right()
  1254. while dig() == true do
  1255. dig()
  1256. end
  1257. forward()
  1258. right()
  1259. else
  1260. left()
  1261. while dig() == true do
  1262. dig()
  1263. end
  1264. forward()
  1265. left()
  1266. end
  1267. else
  1268. end
  1269. else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
  1270. if b < w then
  1271. if a%2 == 1 then
  1272. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1273. right()
  1274. while dig() == true do
  1275. dig()
  1276. end
  1277. forward()
  1278. right()
  1279. else
  1280. left()
  1281. while dig() == true do
  1282. dig()
  1283. end
  1284. forward()
  1285. left()
  1286. end
  1287. else
  1288. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1289. left()
  1290. while dig() == true do
  1291. dig()
  1292. end
  1293. forward()
  1294. left()
  1295. else
  1296. right()
  1297. while dig() == true do
  1298. dig()
  1299. end
  1300. forward()
  1301. right()
  1302. end
  1303. end
  1304. else
  1305. end
  1306. end
  1307. end
  1308. if a < h then
  1309. while digdown() == true do --this is to go up to next layer
  1310. digdown()
  1311. end
  1312. down()
  1313. right()
  1314. right()
  1315. else
  1316. end
  1317. end
  1318. elseif w > l and w > h then -- this is when the width is greater than the length and height
  1319. for d = 1 , l-1 do
  1320. while dig() == true do
  1321. dig()
  1322. end
  1323. forward()
  1324. end
  1325. right()
  1326. for a = 1, h do
  1327. for b = 1, l do --this digs into the cube
  1328. for c = 1, (w-1) do --this digs the length
  1329. while dig() == true do
  1330. dig()
  1331. end
  1332. forward()
  1333. refuel()
  1334. inventorycheck()
  1335. end
  1336. if w%2 == 1 then
  1337. if b < l then
  1338. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1339. right()
  1340. while dig() == true do
  1341. dig()
  1342. end
  1343. forward()
  1344. right()
  1345. else
  1346. left()
  1347. while dig() == true do
  1348. dig()
  1349. end
  1350. forward()
  1351. left()
  1352. end
  1353. else
  1354. end
  1355. else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
  1356. if b < l then
  1357. if a%2 == 1 then
  1358. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1359. right()
  1360. while dig() == true do
  1361. dig()
  1362. end
  1363. forward()
  1364. right()
  1365. else
  1366. left()
  1367. while dig() == true do
  1368. dig()
  1369. end
  1370. forward()
  1371. left()
  1372. end
  1373. else
  1374. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1375. left()
  1376. while dig() == true do
  1377. dig()
  1378. end
  1379. forward()
  1380. left()
  1381. else
  1382. right()
  1383. while dig() == true do
  1384. dig()
  1385. end
  1386. forward()
  1387. right()
  1388. end
  1389. end
  1390. else
  1391. end
  1392. end
  1393. end
  1394. if a < h then
  1395. while digdown() == true do --this is to go up to next layer
  1396. digdown()
  1397. end
  1398. down()
  1399. right()
  1400. right()
  1401. else
  1402. end
  1403. end
  1404. elseif h > w and h > l then
  1405. for a = 1, w do
  1406. for b = 1, l do --this digs into the cube
  1407. for c = 1, (h-1) do --this digs the length
  1408. if l%2 == 1 then
  1409. if a%2 == 1 then
  1410. if b%2 == 1 then
  1411. while digdown() == true do
  1412. digdown()
  1413. end
  1414. down()
  1415. refuel()
  1416. inventorycheck()
  1417. else
  1418. while digup() == true do
  1419. digup()
  1420. end
  1421. up()
  1422. inventorycheck()
  1423. end
  1424. else
  1425. if b%2 == 1 then
  1426. while digup() == true do
  1427. digup()
  1428. end
  1429. up()
  1430. inventorycheck()
  1431. else
  1432. while digdown() == true do
  1433. digdown()
  1434. end
  1435. down()
  1436. inventorycheck()
  1437. end
  1438.  
  1439. end
  1440. else
  1441. if b%2 == 1 then
  1442. while digdown() == true do
  1443. digdown()
  1444. end
  1445. down()
  1446. inventorycheck()
  1447. else
  1448. while digup() == true do
  1449. digup()
  1450. end
  1451. up()
  1452. inventorycheck()
  1453. end
  1454. end
  1455. end
  1456. if b < l then
  1457. while dig() == true do
  1458. dig()
  1459. end
  1460. forward()
  1461. else
  1462. end
  1463. end
  1464. if a < w then
  1465. if a%2 == 1 then
  1466. right()
  1467. while dig() == true do
  1468. dig()
  1469. end
  1470. forward()
  1471. right()
  1472. else
  1473. left()
  1474. while dig() == true do
  1475. dig()
  1476. end
  1477. forward()
  1478. left()
  1479. end
  1480. else
  1481. end
  1482. end
  1483. elseif w == l then
  1484. for a = 1, h do
  1485. for b = 1, w do --this digs into the cube
  1486. for c = 1, (l-1) do --this digs the length
  1487. while dig() == true do
  1488. dig()
  1489. end
  1490. forward()
  1491. refuel()
  1492. inventorycheck()
  1493. end
  1494. if w%2 == 1 then
  1495. if b < w then
  1496. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1497. right()
  1498. while dig() == true do
  1499. dig()
  1500. end
  1501. forward()
  1502. right()
  1503. else
  1504. left()
  1505. while dig() == true do
  1506. dig()
  1507. end
  1508. forward()
  1509. left()
  1510. end
  1511. else
  1512. end
  1513. else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
  1514. if b < w then
  1515. if a%2 == 1 then
  1516. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1517. right()
  1518. while dig() == true do
  1519. dig()
  1520. end
  1521. forward()
  1522. right()
  1523. else
  1524. left()
  1525. while dig() == true do
  1526. dig()
  1527. end
  1528. forward()
  1529. left()
  1530. end
  1531. else
  1532. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1533. left()
  1534. while dig() == true do
  1535. dig()
  1536. end
  1537. forward()
  1538. left()
  1539. else
  1540. right()
  1541. while dig() == true do
  1542. dig()
  1543. end
  1544. forward()
  1545. right()
  1546. end
  1547. end
  1548. else
  1549. end
  1550. end
  1551. end
  1552. if a < h then
  1553. while digdown() == true do --this is to go up to next layer
  1554. digdown()
  1555. end
  1556. down()
  1557. right()
  1558. right()
  1559. else
  1560. end
  1561. end
  1562. elseif w == h then
  1563. for d = 1 , l-1 do
  1564. while dig() == true do
  1565. dig()
  1566. end
  1567. forward()
  1568. refuel()
  1569. inventorycheck()
  1570. end
  1571. right()
  1572. for a = 1, h do
  1573. for b = 1, l do --this digs into the cube
  1574. for c = 1, (w-1) do --this digs the length
  1575. while dig() == true do
  1576. dig()
  1577. refuel()
  1578. inventorycheck()
  1579. end
  1580. forward()
  1581. end
  1582. if w%2 == 1 then
  1583. if b < l then
  1584. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1585. right()
  1586. while dig() == true do
  1587. dig()
  1588. end
  1589. forward()
  1590. right()
  1591. else
  1592. left()
  1593. while dig() == true do
  1594. dig()
  1595. end
  1596. forward()
  1597. left()
  1598. end
  1599. else
  1600. end
  1601. else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
  1602. if b < l then
  1603. if a%2 == 1 then
  1604. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1605. right()
  1606. while dig() == true do
  1607. dig()
  1608. end
  1609. forward()
  1610. right()
  1611. else
  1612. left()
  1613. while dig() == true do
  1614. dig()
  1615. end
  1616. forward()
  1617. left()
  1618. end
  1619. else
  1620. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1621. left()
  1622. while dig() == true do
  1623. dig()
  1624. end
  1625. forward()
  1626. left()
  1627. else
  1628. right()
  1629. while dig() == true do
  1630. dig()
  1631. end
  1632. forward()
  1633. right()
  1634. end
  1635. end
  1636. else
  1637. end
  1638. end
  1639. end
  1640. if a < h then
  1641. while digdown() == true do --this is to go up to next layer
  1642. digdown()
  1643. end
  1644. down()
  1645. right()
  1646. right()
  1647. else
  1648. end
  1649. end
  1650. elseif h == l then
  1651. for a = 1, h do
  1652. for b = 1, w do --this digs into the cube
  1653. for c = 1, (l-1) do --this digs the length
  1654. while dig() == true do
  1655. dig()
  1656. end
  1657. forward()
  1658. refuel()
  1659. inventorycheck()
  1660. end
  1661. if w%2 == 1 then
  1662. if b < w then
  1663. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1664. right()
  1665. while dig() == true do
  1666. dig()
  1667. end
  1668. forward()
  1669. right()
  1670. else
  1671. left()
  1672. while dig() == true do
  1673. dig()
  1674. end
  1675. forward()
  1676. left()
  1677. end
  1678. else
  1679. end
  1680. else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
  1681. if b < w then
  1682. if a%2 == 1 then
  1683. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1684. right()
  1685. while dig() == true do
  1686. dig()
  1687. end
  1688. forward()
  1689. right()
  1690. else
  1691. left()
  1692. while dig() == true do
  1693. dig()
  1694. end
  1695. forward()
  1696. left()
  1697. end
  1698. else
  1699. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1700. left()
  1701. while dig() == true do
  1702. dig()
  1703. end
  1704. forward()
  1705. left()
  1706. else
  1707. right()
  1708. while dig() == true do
  1709. dig()
  1710. end
  1711. forward()
  1712. right()
  1713. end
  1714. end
  1715. else
  1716. end
  1717. end
  1718. end
  1719. if a < h then
  1720. while digdown() == true do --this is to go up to next layer
  1721. digdown()
  1722. end
  1723. down()
  1724. right()
  1725. right()
  1726. else
  1727. end
  1728. end
  1729. elseif w == h and l == h then
  1730. for a = 1, h do
  1731. for b = 1, w do --this digs into the cube
  1732. for c = 1, (l-1) do --this digs the length
  1733. while dig() == true do
  1734. dig()
  1735. end
  1736. forward()
  1737. refuel()
  1738. inventorycheck()
  1739. end
  1740. if w%2 == 1 then
  1741. if b < w then
  1742. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1743. right()
  1744. while dig() == true do
  1745. dig()
  1746. end
  1747. forward()
  1748. right()
  1749. else
  1750. left()
  1751. while dig() == true do
  1752. dig()
  1753. end
  1754. forward()
  1755. left()
  1756. end
  1757. else
  1758. end
  1759. else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
  1760. if b < w then
  1761. if a%2 == 1 then
  1762. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1763. right()
  1764. while dig() == true do
  1765. dig()
  1766. end
  1767. forward()
  1768. right()
  1769. else
  1770. left()
  1771. while dig() == true do
  1772. dig()
  1773. end
  1774. forward()
  1775. left()
  1776. end
  1777. else
  1778. if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
  1779. left()
  1780. while dig() == true do
  1781. dig()
  1782. end
  1783. forward()
  1784. left()
  1785. else
  1786. right()
  1787. while dig() == true do
  1788. dig()
  1789. end
  1790. forward()
  1791. right()
  1792. end
  1793. end
  1794. else
  1795. end
  1796. end
  1797. end
  1798. if a < h then
  1799. while digdown() == true do --this is to go up to next layer
  1800. digdown()
  1801. end
  1802. down()
  1803. right()
  1804. right()
  1805. else
  1806. end
  1807. end
  1808. end
  1809. backtostart()
  1810. clearinventory()
  1811. end
  1812.  
  1813.  
  1814. -- MAIN PROGRAM //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1815.  
  1816. x_i = 0 --this is if you are not using gps and not getting real world coords
  1817. y_i = 0
  1818. z_i = 0
  1819.  
  1820. x_c_f = 0 --stands for *_current_final represents the last position the turtle was at before it stopped mining
  1821. y_c_f = 0
  1822. z_c_f = 0
  1823.  
  1824. x_c_i = 0 --you need x_c_i and such as a placeholder in function forward to keep values increasing or decreasing
  1825. y_c_i = 0
  1826. z_c_i = 0
  1827.  
  1828. print("You can choose from two directions to dig. From top left down and to the right, or from bottom left up and to the right. 1 for top left and 2 for bottom left. If you are mining below 16 place the turtle at 16 and have it dig top left down.")
  1829.  
  1830. direction = tonumber(read())
  1831. if direction == 1 then
  1832. digcubetopleft()
  1833. elseif direction == 2 then
  1834. digcubebottomleft()
  1835. end
Add Comment
Please, Sign In to add comment