Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.38 KB | None | 0 0
  1.  
  2. PASTEBIN
  3. new paste
  4. PRO API tools faq deals
  5.  
  6. Guest User
  7. -
  8. Public Pastes
  9.  
  10. UntitledC++ | 3 sec ago
  11. Untitled3 sec ago
  12. Untitled3 sec ago
  13. UPP changes20 sec ago
  14. minerLua | 36 sec ago
  15. UntitledJava | 37 sec ago
  16. Untitled38 sec ago
  17. dimik_546 sec ago
  18.  
  19. daily pastebin goal
  20. 51%
  21. help support pastebin
  22. SHARE
  23. TWEET
  24. Better Tunnel v2.0
  25. grand_mind1 Aug 31st, 2013 4,155 Never
  26. Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  27. rawdownloadcloneembedreportprint Lua 13.27 KB
  28.  
  29. --Begin clear function
  30. local function clear()
  31. term.clear()
  32. term.setCursorPos(1,1)
  33. end
  34. --End clear function
  35.  
  36. --Begin drawMenu function
  37. local function drawMenu()
  38. clear()
  39. for i = 1,#options-1 do
  40. if sel == i then write("*") end
  41. print(options[i].." "..tostring(values[i]))
  42. end
  43. if sel == 8 then
  44. print("\n\n\n["..options[8].."]")
  45. else
  46. print("\n\n\n"..options[8])
  47. end
  48. end
  49. --End drawMenu function
  50.  
  51. --Begin setValue function
  52. local function setValue(value)
  53. if value == "Disabled" then
  54. value = false
  55. else
  56. value = true
  57. end
  58. return value
  59. end
  60. --End setValue function
  61.  
  62. --Begin toggle function
  63. local function toggle(able)
  64. if able == "Disabled" then
  65. able = "Enabled"
  66. else
  67. able = "Disabled"
  68. end
  69. return able
  70. end
  71. --End toggle function
  72.  
  73. --Begin saveProgress function
  74. local function saveProgress()
  75. fs.delete("btProgress")
  76. d = fs.open("btProgress", "w")
  77. d.writeLine("This contains the current position of the turtle in btunnel.")
  78. d.writeLine(loc)
  79. d.writeLine(tostring(curLength))
  80. d.writeLine(tostring(length))
  81. d.writeLine(facing)
  82. d.close()
  83. end
  84. --End saveProgress function
  85.  
  86. --Begin loadProgress function
  87. local function loadProgress()
  88. d = fs.open("btProgress", "r")
  89. comment1 = d.readLine()
  90. loc = d.readLine()
  91. curLength = tonumber(d.readLine())
  92. length = tonumber(d.readLine())
  93. facing = d.readLine()
  94. end
  95. --End loadProgress function
  96.  
  97. --Begin saveSettings function
  98. local function saveSettings()
  99. if fs.exists("btSettings") then
  100. fs.delete("btSettings")
  101. end
  102. h = fs.open("btSettings","w")
  103. h.writeLine("--Better Tunnel Settings")
  104. h.writeLine("--Deleting will reset settings")
  105. h.close()
  106. h = fs.open("btSettings","a")
  107. h.writeLine(orders)
  108. h.writeLine(useChests)
  109. h.writeLine(useEnder)
  110. h.writeLine(useTorches)
  111. h.writeLine(bridgeGaps)
  112. h.writeLine(tonumber(compID))
  113. h.writeLine(tonumber(fuelSlot))
  114. h.writeLine(tunnelType)
  115. h.close()
  116. end
  117. --End saveSettings function
  118.  
  119. --Begin checkChests function
  120. local function checkChests()
  121. if useChests then
  122. max = 15
  123. if chests == 0 then
  124. if useEnder then
  125. print("\nPlease input an enderchest into slot "..chestSlot.."...")
  126. else
  127. print("\nPlease input chests into slot "..chestSlot.."...")
  128. end
  129. while chests == 0 do
  130. chests = turtle.getItemCount(chestSlot)
  131. sleep(1)
  132. end
  133. end
  134. end
  135. end
  136. --End the checkChests function
  137.  
  138. --Begin the checkTorches function
  139. local function checkTorches()
  140. if useTorches then
  141. if useChests then
  142. torchSlot = 15
  143. torches = turtle.getItemCount(torchSlot)
  144. max = 14
  145. else
  146. torchSlot = 16
  147. torches = turtle.getItemCount(torchSlot)
  148. max = 15
  149. end
  150. if torches == 0 then
  151. print("\nPlease input torches into slot "..torchSlot.."...")
  152. while torches == 0 do
  153. torches = turtle.getItemCount(torchSlot)
  154. sleep(1)
  155. end
  156. end
  157. end
  158. end
  159. --End the checkTorches function
  160.  
  161. --Begin loadSettings function
  162. local function loadSettings()
  163. h = fs.open("btSettings", "r")
  164. comment1 = h.readLine()
  165. comment2 = h.readLine()
  166. orders = h.readLine()
  167. useChests = h.readLine()
  168. useEnder = h.readLine()
  169. useTorches = h.readLine()
  170. bridgeGaps = h.readLine()
  171. compID = tonumber(h.readLine())
  172. fuelSlot = tonumber(h.readLine())
  173. tunnelType = h.readLine()
  174. h.close()
  175. max = 16
  176. checkChests()
  177. checkTorches()
  178. end
  179. --End loadSettings function
  180.  
  181. --Begin findLoc function
  182. local function findLoc()
  183. if facing == "right" then
  184. if loc == "top" then
  185. dig()
  186. down()
  187. loc = "mid"
  188. dig()
  189. down()
  190. loc = "bot"
  191. dig()
  192. turtle.turnLeft()
  193. facing = "forw"
  194. forward()
  195. length = length+1
  196. elseif loc == "mid" then
  197. dig()
  198. down()
  199. loc = "bot"
  200. dig()
  201. turtle.turnLeft()
  202. facing = "forw"
  203. forward()
  204. length = length+1
  205. elseif loc == "bot" then
  206. dig()
  207. turtle.turnLeft()
  208. facing = "forw"
  209. forward()
  210. length = length+1
  211. end
  212. end
  213. end
  214. --End findLoc function
  215.  
  216. --Begin modemExists function
  217. local function modemExists()
  218. if peripheral.getType("right") == "modem" then
  219. return true
  220. end
  221. return false
  222. end
  223. --End modemExists function
  224.  
  225. --Begin invalid function
  226. local function invalid()
  227. print("\nInvalid")
  228. sleep(1)
  229. end
  230. --End invalid function
  231.  
  232. --Begin isValid function
  233. local function isValid(check, isOrders)
  234. vType = type(check)
  235. check = string.lower(check)
  236. if not isOrders or isOrders == nil then
  237. if check == "y" or check == "n" and vType == "string" then
  238. return true
  239. end
  240. else
  241. if check == "u" or check == "r" and vType == "string" then
  242. return true
  243. end
  244. end
  245. return false
  246. end
  247. --End isValid function
  248.  
  249. --Begin the useFuel function
  250. local function useFuel()
  251. clear()
  252. if useFuelSlot then
  253. continue = false
  254. repeat
  255. clear()
  256. print("What slot would you like the fuel to be in?: ")
  257. fuelSlot = tonumber(read())
  258. if fuelSlot == torchSlot or fuelSlot == chestSlot or fuelSlot > 16 then
  259. continue = false
  260. invalid()
  261. else
  262. if fuelSlot == max then
  263. max = max-1
  264. end
  265. print("\nPlease input fuel into slot ",fuelSlot,"...")
  266. fuelAmount = turtle.getItemCount(fuelSlot)
  267. while fuelAmount == 0 do
  268. fuelAmount = turtle.getItemCount(fuelSlot)
  269. sleep(1)
  270. end
  271. continue = true
  272. end
  273. until continue
  274. end
  275. continue = true
  276. end
  277. --End the useFuel Function
  278.  
  279. --Begin dropoff function
  280. local function dropOff()
  281. turtle.digUp()
  282. turtle.select(chestSlot)
  283. turtle.placeUp()
  284. for i = 1,max do
  285. if turtle.getItemCount(i) > 0 and i ~= fuelSlot then
  286. turtle.select(i)
  287. turtle.dropUp()
  288. end
  289. end
  290. if useEnder == true then
  291. sleep(2)
  292. turtle.select(chestSlot)
  293. turtle.digUp()
  294. end
  295. turtle.select(1)
  296. end
  297. --End dropoff function
  298.  
  299. --Begin dig function
  300. local function dig()
  301. while turtle.detect() do
  302. turtle.dig()
  303. end
  304. end
  305. --End dig function
  306.  
  307. --Begin up function
  308. function up(num)
  309. curUp = 1
  310. if num == nil then
  311. num = 1
  312. end
  313. while curUp <= num do
  314. if not turtle.up() then
  315. turtle.digUp()
  316. turtle.attackUp()
  317. else
  318. curUp = curUp+1
  319. end
  320. end
  321. end
  322. --End up function
  323.  
  324. --Begin forward function
  325. function forward(num)
  326. curForw = 1
  327. if num == nil then
  328. num = 1
  329. end
  330. while curForw <= num do
  331. if not turtle.forward() then
  332. turtle.dig()
  333. turtle.attack()
  334. else
  335. curForw = curForw+1
  336. end
  337. end
  338. end
  339. --End forward function
  340.  
  341. --Begin down function
  342. function down(num)
  343. curDown = 1
  344. if num == nil then
  345. num = 1
  346. end
  347. while curDown <= num do
  348. if not turtle.down() then
  349. turtle.digDown()
  350. turtle.attackDown()
  351. else
  352. curDown = curDown+1
  353. end
  354. end
  355. end
  356. --End down function
  357.  
  358. --Begin the tryRefuel function
  359. local function tryRefuel()
  360. for i = 1,max do
  361. if turtle.getItemCount(i) > 0 then
  362. turtle.select(i)
  363. if turtle.refuel(1) then
  364. return true
  365. end
  366. end
  367. end
  368. turtle.select(1)
  369. return false
  370. end
  371. --End the tryRefuel function
  372.  
  373. --Begin refuel function
  374. local function refuel()
  375. curFuel = turtle.getFuelLevel()
  376. if curFuel == "unlimited" or curFuel >= 10 then
  377. return
  378. else
  379. if not tryRefuel() then
  380. print("Please supply more fuel to coninue...")
  381. while not tryRefuel() do
  382. sleep(1)
  383. end
  384. end
  385. end
  386. end
  387. --End refuel function
  388.  
  389. --Begin the stackFuel function
  390. local function stackFuel()
  391. for i = 1,16 do
  392. if turtle.getItemCount(i) > 0 and i ~= fuelSlot and i < max then
  393. turtle.select(i)
  394. if turtle.compareTo(fuelSlot) then
  395. turtle.transferTo(fuelSlot, turtle.getItemCount(i))
  396. end
  397. end
  398. end
  399. turtle.select(1)
  400. end
  401. --End the stackFuel function
  402.  
  403. --Begin tunnel function
  404. local function tunnel(tunLength)
  405. for i = 1,tunLength do
  406. if useTorches then
  407. turtle.select(torchSlot)
  408. if torch == 9 or curLength == 1 or curLength == tunLength-1 then
  409. turtle.digDown()
  410. turtle.placeDown()
  411. turtle.select(1)
  412. torch = 1
  413. else
  414. torch = torch+1
  415. end
  416. turtle.select(1)
  417. end
  418. if bridgeGaps and not turtle.detectDown() then
  419. turtle.placeDown()
  420. end
  421. print("Current tunnel length: ",curLength-1)
  422. refuel()
  423. turtle.turnLeft()
  424. dig()
  425. up()
  426. dig()
  427. if tunnelType == "3x3" then
  428. up()
  429. dig()
  430. end
  431. turtle.turnRight()
  432. turtle.turnRight()
  433. dig()
  434. down()
  435. dig()
  436. if tunnelType == "3x3" then
  437. down()
  438. dig()
  439. end
  440. turtle.turnLeft()
  441. if useFuelSlot == true then
  442. stackFuel()
  443. end
  444. refuel()
  445. if useChests then
  446. if turtle.getItemCount(max) > 0 then
  447. dropOff()
  448. end
  449. end
  450. turtle.select(1)
  451. turtle.dig()
  452. forward()
  453. curLength = curLength+1
  454. saveProgress()
  455. saveSettings()
  456. end
  457. end
  458. --End tunnel function
  459.  
  460.  
  461. --Begin Main code
  462. --[[Check if the turtle already began a tunnel and needs to finish it now
  463. if fs.exists("btProgress") then
  464. print("I need to continue with my tunnel!")
  465. loadProgress()
  466. loadSettings()
  467. findLoc()
  468. end
  469. --]]
  470.  
  471. --Declare Variables
  472. max = 16
  473. continue = false
  474. torchSlot = 15
  475. chestSlot = 16
  476. curLength = 1
  477. useSettings = false
  478. compID = 1
  479. facing = "right"
  480. torches = turtle.getItemCount(torchSlot)
  481. chests = turtle.getItemCount(chestSlot)
  482.  
  483. values={
  484. "User",
  485. "Disabled",
  486. "Disabled",
  487. "Disabled",
  488. "Disabled",
  489. "3x3",
  490. "Disabled"
  491. }
  492. orders = values[1]
  493. useChests = values[2]
  494. useEnder = values[3]
  495. useTorches = values[4]
  496. bridgeGaps = values[5]
  497. tunnelType = values[6]
  498. useFuelSlot = values[7]
  499.  
  500. options={
  501. "Receive orders via:",
  502. "Use chests:",
  503. "Use Enderchests:",
  504. "Use Torches:",
  505. "Bridge Gaps:",
  506. "Tunnel Type:",
  507. "Specific Slot for Fuel:",
  508. "Continue"
  509. }
  510.  
  511. clear()
  512. print("Better Tunnel v2.0")
  513. sleep(2.5)
  514.  
  515. --If a settings file exists, ask the user if they want to load it
  516. if fs.exists("btSettings") then
  517. continue = false
  518. repeat
  519. clear()
  520. print("A settings file was found.")
  521. print("Would you like to load it?(Y/N): ")
  522. load = read()
  523. load = string.lower(load)
  524. if load == "y" then
  525. useSettings = true
  526. continue = true
  527. elseif load == "n" then
  528. useSettings = false
  529. continue = true
  530. else
  531. invalid()
  532. end
  533. until continue
  534. else
  535. useSettings = false
  536. end
  537.  
  538. --If they chose to load it, it will load the setting from the file
  539. if useSettings then
  540. loadSettings()
  541. else--If the file didn't exist or the user chose not to load it, the program will ask the user for settings
  542. sel = 1--The first option is selected when the screen is first drawn
  543.  
  544. clear()--clear the screen before starting
  545. while true do
  546. clear()
  547. drawMenu()--draw the menu
  548. event, key=os.pullEvent("key")--wait for a key to be pressed
  549. if key == keys.up and sel ~= 1 then--long and excessive logic(I feel it could be improved) to decide what to select next
  550. sel = sel-1
  551. elseif key == keys.down and sel ~= 8 then
  552. sel = sel+1
  553. elseif key == keys.enter then
  554. if sel == 1 then
  555. if values[1] == "User" then
  556. values[1] = "Rednet"
  557. else
  558. values[1] = "User"
  559. end
  560. elseif sel == 2 then
  561. values[2] = toggle(values[2])
  562. if values[2] == "Disabled" and values[3] ~= "Disabled" then
  563. values[3] = toggle(values[3])
  564. end
  565. elseif sel == 3 then
  566. values[3] = toggle(values[3])
  567. if values[3] == "Enabled" and values [2] ~= "Enabled" then
  568. values[2] = toggle(values[2])
  569. end
  570. elseif sel == 4 then
  571. values[4] = toggle(values[4])
  572. elseif sel == 5 then
  573. values[5] = toggle(values[5])
  574. elseif sel == 6 then
  575. if values[6] == "3x3" then
  576. values[6] = "2x3"
  577. else
  578. values[6] = "3x3"
  579. end
  580. elseif sel == 7 then
  581. values[7] = toggle(values[7])
  582. elseif sel == 8 then
  583. orders = values[1]
  584. useChests = setValue(values[2])
  585. useEnder = setValue(values[3])
  586. useTorches = setValue(values[4])
  587. bridgeGaps = setValue(values[5])
  588. useFuelSlot = setValue(values[7])
  589. break
  590. end
  591. end
  592. end
  593. checkChests()
  594. checkTorches()
  595. useFuel()
  596. end
  597.  
  598. if (not modemExists() and (orders == "Rednet")) then
  599. clear()
  600. print("No modem was detected on this turtle!")
  601. print("User input has been automatically selected.")
  602. orders = "User"
  603. sleep(3)
  604. end
  605.  
  606. --Run the tunnel function based on the orders chosen
  607. if orders == "Rednet" then
  608. rednet.open("right")
  609. clear()
  610. if not useSettings then
  611. continue = false
  612. repeat
  613. print("You chose to receive orders via Rednet.")
  614. write("What computer would you like me to accept messages from?: ")
  615. compID = tonumber(read())
  616. if compID > 0 then
  617. continue = true
  618. else
  619. invalid()
  620. end
  621. until continue
  622. end
  623. clear()
  624. print("I will listen for orders from the computer with id: "..compID)
  625. id, msg = rednet.receive()
  626. if id == tonumber(compID) then
  627. length = msg
  628. checkChests()
  629. checkTorches()
  630. print("Beginning tunnel with length: "..length)
  631. tunnel(length)
  632. end
  633. elseif orders == "User" then
  634. repeat
  635. clear()
  636. print("You chose to receive orders via User.")
  637. write("How long would you like the tunnel to be?(In blocks): ")
  638. length = tonumber(read())
  639. vType = type(length)
  640. if vType == "number" then
  641. print("Beginning tunnel with length: "..length)
  642. continue = true
  643. checkChests()
  644. checkTorches()
  645. tunnel(length)
  646. else
  647. invalid()
  648. continue = false
  649. end
  650. until continue
  651. end
  652.  
  653. clear()
  654. print("I'm done!")
  655. print("I completed a tunnel with length: "..length)
  656.  
  657. if not useSettings then
  658. print("Would you like to save these settings for use in the next tunnel?(Y/N): ")
  659. save = read()
  660. save = string.lower(save)
  661. if save == "y" then
  662. saveSettings()
  663. print("Settings have been saved")
  664. sleep(2)
  665. end
  666.  
  667. end
  668.  
  669. RAW Paste Data
  670. --Begin clear function
  671. local function clear()
  672. term.clear()
  673. term.setCursorPos(1,1)
  674. end
  675. --End clear function
  676.  
  677. --Begin drawMenu function
  678. local function drawMenu()
  679. clear()
  680. for i = 1,#options-1 do
  681. if sel == i then write("*") end
  682. print(options[i].." "..tostring(values[i]))
  683. end
  684. if sel == 8 then
  685. print("\n\n\n["..options[8].."]")
  686. else
  687. print("\n\n\n"..options[8])
  688. end
  689. end
  690. --End drawMenu function
  691.  
  692. --Begin setValue function
  693. local function setValue(value)
  694. if value == "Disabled" then
  695. value = false
  696. else
  697. value = true
  698. end
  699. return value
  700. end
  701. --End setValue function
  702.  
  703. --Begin toggle function
  704. local function toggle(able)
  705. if able == "Disabled" then
  706. able = "Enabled"
  707. else
  708. able = "Disabled"
  709. end
  710. return able
  711. end
  712. --End toggle function
  713.  
  714. --Begin saveProgress function
  715. local function saveProgress()
  716. fs.delete("btProgress")
  717. d = fs.open("btProgress", "w")
  718. d.writeLine("This contains the current position of the turtle in btunnel.")
  719. d.writeLine(loc)
  720. d.writeLine(tostring(curLength))
  721. d.writeLine(tostring(length))
  722. d.writeLine(facing)
  723. d.close()
  724. end
  725. --End saveProgress function
  726.  
  727. --Begin loadProgress function
  728. local function loadProgress()
  729. d = fs.open("btProgress", "r")
  730. comment1 = d.readLine()
  731. loc = d.readLine()
  732. curLength = tonumber(d.readLine())
  733. length = tonumber(d.readLine())
  734. facing = d.readLine()
  735. end
  736. --End loadProgress function
  737.  
  738. --Begin saveSettings function
  739. local function saveSettings()
  740. if fs.exists("btSettings") then
  741. fs.delete("btSettings")
  742. end
  743. h = fs.open("btSettings","w")
  744. h.writeLine("--Better Tunnel Settings")
  745. h.writeLine("--Deleting will reset settings")
  746. h.close()
  747. h = fs.open("btSettings","a")
  748. h.writeLine(orders)
  749. h.writeLine(useChests)
  750. h.writeLine(useEnder)
  751. h.writeLine(useTorches)
  752. h.writeLine(bridgeGaps)
  753. h.writeLine(tonumber(compID))
  754. h.writeLine(tonumber(fuelSlot))
  755. h.writeLine(tunnelType)
  756. h.close()
  757. end
  758. --End saveSettings function
  759.  
  760. --Begin checkChests function
  761. local function checkChests()
  762. if useChests then
  763. max = 15
  764. if chests == 0 then
  765. if useEnder then
  766. print("\nPlease input an enderchest into slot "..chestSlot.."...")
  767. else
  768. print("\nPlease input chests into slot "..chestSlot.."...")
  769. end
  770. while chests == 0 do
  771. chests = turtle.getItemCount(chestSlot)
  772. sleep(1)
  773. end
  774. end
  775. end
  776. end
  777. --End the checkChests function
  778.  
  779. --Begin the checkTorches function
  780. local function checkTorches()
  781. if useTorches then
  782. if useChests then
  783. torchSlot = 15
  784. torches = turtle.getItemCount(torchSlot)
  785. max = 14
  786. else
  787. torchSlot = 16
  788. torches = turtle.getItemCount(torchSlot)
  789. max = 15
  790. end
  791. if torches == 0 then
  792. print("\nPlease input torches into slot "..torchSlot.."...")
  793. while torches == 0 do
  794. torches = turtle.getItemCount(torchSlot)
  795. sleep(1)
  796. end
  797. end
  798. end
  799. end
  800. --End the checkTorches function
  801.  
  802. --Begin loadSettings function
  803. local function loadSettings()
  804. h = fs.open("btSettings", "r")
  805. comment1 = h.readLine()
  806. comment2 = h.readLine()
  807. orders = h.readLine()
  808. useChests = h.readLine()
  809. useEnder = h.readLine()
  810. useTorches = h.readLine()
  811. bridgeGaps = h.readLine()
  812. compID = tonumber(h.readLine())
  813. fuelSlot = tonumber(h.readLine())
  814. tunnelType = h.readLine()
  815. h.close()
  816. max = 16
  817. checkChests()
  818. checkTorches()
  819. end
  820. --End loadSettings function
  821.  
  822. --Begin findLoc function
  823. local function findLoc()
  824. if facing == "right" then
  825. if loc == "top" then
  826. dig()
  827. down()
  828. loc = "mid"
  829. dig()
  830. down()
  831. loc = "bot"
  832. dig()
  833. turtle.turnLeft()
  834. facing = "forw"
  835. forward()
  836. length = length+1
  837. elseif loc == "mid" then
  838. dig()
  839. down()
  840. loc = "bot"
  841. dig()
  842. turtle.turnLeft()
  843. facing = "forw"
  844. forward()
  845. length = length+1
  846. elseif loc == "bot" then
  847. dig()
  848. turtle.turnLeft()
  849. facing = "forw"
  850. forward()
  851. length = length+1
  852. end
  853. end
  854. end
  855. --End findLoc function
  856.  
  857. --Begin modemExists function
  858. local function modemExists()
  859. if peripheral.getType("right") == "modem" then
  860. return true
  861. end
  862. return false
  863. end
  864. --End modemExists function
  865.  
  866. --Begin invalid function
  867. local function invalid()
  868. print("\nInvalid")
  869. sleep(1)
  870. end
  871. --End invalid function
  872.  
  873. --Begin isValid function
  874. local function isValid(check, isOrders)
  875. vType = type(check)
  876. check = string.lower(check)
  877. if not isOrders or isOrders == nil then
  878. if check == "y" or check == "n" and vType == "string" then
  879. return true
  880. end
  881. else
  882. if check == "u" or check == "r" and vType == "string" then
  883. return true
  884. end
  885. end
  886. return false
  887. end
  888. --End isValid function
  889.  
  890. --Begin the useFuel function
  891. local function useFuel()
  892. clear()
  893. if useFuelSlot then
  894. continue = false
  895. repeat
  896. clear()
  897. print("What slot would you like the fuel to be in?: ")
  898. fuelSlot = tonumber(read())
  899. if fuelSlot == torchSlot or fuelSlot == chestSlot or fuelSlot > 16 then
  900. continue = false
  901. invalid()
  902. else
  903. if fuelSlot == max then
  904. max = max-1
  905. end
  906. print("\nPlease input fuel into slot ",fuelSlot,"...")
  907. fuelAmount = turtle.getItemCount(fuelSlot)
  908. while fuelAmount == 0 do
  909. fuelAmount = turtle.getItemCount(fuelSlot)
  910. sleep(1)
  911. end
  912. continue = true
  913. end
  914. until continue
  915. end
  916. continue = true
  917. end
  918. --End the useFuel Function
  919.  
  920. --Begin dropoff function
  921. local function dropOff()
  922. turtle.digUp()
  923. turtle.select(chestSlot)
  924. turtle.placeUp()
  925. for i = 1,max do
  926. if turtle.getItemCount(i) > 0 and i ~= fuelSlot then
  927. turtle.select(i)
  928. turtle.dropUp()
  929. end
  930. end
  931. if useEnder == true then
  932. sleep(2)
  933. turtle.select(chestSlot)
  934. turtle.digUp()
  935. end
  936. turtle.select(1)
  937. end
  938. --End dropoff function
  939.  
  940. --Begin dig function
  941. local function dig()
  942. while turtle.detect() do
  943. turtle.dig()
  944. end
  945. end
  946. --End dig function
  947.  
  948. --Begin up function
  949. function up(num)
  950. curUp = 1
  951. if num == nil then
  952. num = 1
  953. end
  954. while curUp <= num do
  955. if not turtle.up() then
  956. turtle.digUp()
  957. turtle.attackUp()
  958. else
  959. curUp = curUp+1
  960. end
  961. end
  962. end
  963. --End up function
  964.  
  965. --Begin forward function
  966. function forward(num)
  967. curForw = 1
  968. if num == nil then
  969. num = 1
  970. end
  971. while curForw <= num do
  972. if not turtle.forward() then
  973. turtle.dig()
  974. turtle.attack()
  975. else
  976. curForw = curForw+1
  977. end
  978. end
  979. end
  980. --End forward function
  981.  
  982. --Begin down function
  983. function down(num)
  984. curDown = 1
  985. if num == nil then
  986. num = 1
  987. end
  988. while curDown <= num do
  989. if not turtle.down() then
  990. turtle.digDown()
  991. turtle.attackDown()
  992. else
  993. curDown = curDown+1
  994. end
  995. end
  996. end
  997. --End down function
  998.  
  999. --Begin the tryRefuel function
  1000. local function tryRefuel()
  1001. for i = 1,max do
  1002. if turtle.getItemCount(i) > 0 then
  1003. turtle.select(i)
  1004. if turtle.refuel(1) then
  1005. return true
  1006. end
  1007. end
  1008. end
  1009. turtle.select(1)
  1010. return false
  1011. end
  1012. --End the tryRefuel function
  1013.  
  1014. --Begin refuel function
  1015. local function refuel()
  1016. curFuel = turtle.getFuelLevel()
  1017. if curFuel == "unlimited" or curFuel >= 10 then
  1018. return
  1019. else
  1020. if not tryRefuel() then
  1021. print("Please supply more fuel to coninue...")
  1022. while not tryRefuel() do
  1023. sleep(1)
  1024. end
  1025. end
  1026. end
  1027. end
  1028. --End refuel function
  1029.  
  1030. --Begin the stackFuel function
  1031. local function stackFuel()
  1032. for i = 1,16 do
  1033. if turtle.getItemCount(i) > 0 and i ~= fuelSlot and i < max then
  1034. turtle.select(i)
  1035. if turtle.compareTo(fuelSlot) then
  1036. turtle.transferTo(fuelSlot, turtle.getItemCount(i))
  1037. end
  1038. end
  1039. end
  1040. turtle.select(1)
  1041. end
  1042. --End the stackFuel function
  1043.  
  1044. --Begin tunnel function
  1045. local function tunnel(tunLength)
  1046. for i = 1,tunLength do
  1047. if useTorches then
  1048. turtle.select(torchSlot)
  1049. if torch == 9 or curLength == 1 or curLength == tunLength-1 then
  1050. turtle.digDown()
  1051. turtle.placeDown()
  1052. turtle.select(1)
  1053. torch = 1
  1054. else
  1055. torch = torch+1
  1056. end
  1057. turtle.select(1)
  1058. end
  1059. if bridgeGaps and not turtle.detectDown() then
  1060. turtle.placeDown()
  1061. end
  1062. print("Current tunnel length: ",curLength-1)
  1063. refuel()
  1064. turtle.turnLeft()
  1065. dig()
  1066. up()
  1067. dig()
  1068. if tunnelType == "3x3" then
  1069. up()
  1070. dig()
  1071. end
  1072. turtle.turnRight()
  1073. turtle.turnRight()
  1074. dig()
  1075. down()
  1076. dig()
  1077. if tunnelType == "3x3" then
  1078. down()
  1079. dig()
  1080. end
  1081. turtle.turnLeft()
  1082. if useFuelSlot == true then
  1083. stackFuel()
  1084. end
  1085. refuel()
  1086. if useChests then
  1087. if turtle.getItemCount(max) > 0 then
  1088. dropOff()
  1089. end
  1090. end
  1091. turtle.select(1)
  1092. turtle.dig()
  1093. forward()
  1094. curLength = curLength+1
  1095. saveProgress()
  1096. saveSettings()
  1097. end
  1098. end
  1099. --End tunnel function
  1100.  
  1101.  
  1102. --Begin Main code
  1103. --[[Check if the turtle already began a tunnel and needs to finish it now
  1104. if fs.exists("btProgress") then
  1105. print("I need to continue with my tunnel!")
  1106. loadProgress()
  1107. loadSettings()
  1108. findLoc()
  1109. end
  1110. --]]
  1111.  
  1112. --Declare Variables
  1113. max = 16
  1114. continue = false
  1115. torchSlot = 15
  1116. chestSlot = 16
  1117. curLength = 1
  1118. useSettings = false
  1119. compID = 1
  1120. facing = "right"
  1121. torches = turtle.getItemCount(torchSlot)
  1122. chests = turtle.getItemCount(chestSlot)
  1123.  
  1124. values={
  1125. "User",
  1126. "Disabled",
  1127. "Disabled",
  1128. "Disabled",
  1129. "Disabled",
  1130. "3x3",
  1131. "Disabled"
  1132. }
  1133. orders = values[1]
  1134. useChests = values[2]
  1135. useEnder = values[3]
  1136. useTorches = values[4]
  1137. bridgeGaps = values[5]
  1138. tunnelType = values[6]
  1139. useFuelSlot = values[7]
  1140.  
  1141. options={
  1142. "Receive orders via:",
  1143. "Use chests:",
  1144. "Use Enderchests:",
  1145. "Use Torches:",
  1146. "Bridge Gaps:",
  1147. "Tunnel Type:",
  1148. "Specific Slot for Fuel:",
  1149. "Continue"
  1150. }
  1151.  
  1152. clear()
  1153. print("Better Tunnel v2.0")
  1154. sleep(2.5)
  1155.  
  1156. --If a settings file exists, ask the user if they want to load it
  1157. if fs.exists("btSettings") then
  1158. continue = false
  1159. repeat
  1160. clear()
  1161. print("A settings file was found.")
  1162. print("Would you like to load it?(Y/N): ")
  1163. load = read()
  1164. load = string.lower(load)
  1165. if load == "y" then
  1166. useSettings = true
  1167. continue = true
  1168. elseif load == "n" then
  1169. useSettings = false
  1170. continue = true
  1171. else
  1172. invalid()
  1173. end
  1174. until continue
  1175. else
  1176. useSettings = false
  1177. end
  1178.  
  1179. --If they chose to load it, it will load the setting from the file
  1180. if useSettings then
  1181. loadSettings()
  1182. else--If the file didn't exist or the user chose not to load it, the program will ask the user for settings
  1183. sel = 1--The first option is selected when the screen is first drawn
  1184.  
  1185. clear()--clear the screen before starting
  1186. while true do
  1187. clear()
  1188. drawMenu()--draw the menu
  1189. event, key=os.pullEvent("key")--wait for a key to be pressed
  1190. if key == keys.up and sel ~= 1 then--long and excessive logic(I feel it could be improved) to decide what to select next
  1191. sel = sel-1
  1192. elseif key == keys.down and sel ~= 8 then
  1193. sel = sel+1
  1194. elseif key == keys.enter then
  1195. if sel == 1 then
  1196. if values[1] == "User" then
  1197. values[1] = "Rednet"
  1198. else
  1199. values[1] = "User"
  1200. end
  1201. elseif sel == 2 then
  1202. values[2] = toggle(values[2])
  1203. if values[2] == "Disabled" and values[3] ~= "Disabled" then
  1204. values[3] = toggle(values[3])
  1205. end
  1206. elseif sel == 3 then
  1207. values[3] = toggle(values[3])
  1208. if values[3] == "Enabled" and values [2] ~= "Enabled" then
  1209. values[2] = toggle(values[2])
  1210. end
  1211. elseif sel == 4 then
  1212. values[4] = toggle(values[4])
  1213. elseif sel == 5 then
  1214. values[5] = toggle(values[5])
  1215. elseif sel == 6 then
  1216. if values[6] == "3x3" then
  1217. values[6] = "2x3"
  1218. else
  1219. values[6] = "3x3"
  1220. end
  1221. elseif sel == 7 then
  1222. values[7] = toggle(values[7])
  1223. elseif sel == 8 then
  1224. orders = values[1]
  1225. useChests = setValue(values[2])
  1226. useEnder = setValue(values[3])
  1227. useTorches = setValue(values[4])
  1228. bridgeGaps = setValue(values[5])
  1229. useFuelSlot = setValue(values[7])
  1230. break
  1231. end
  1232. end
  1233. end
  1234. useFuel()
  1235. checkChests()
  1236. checkTorches()
  1237. end
  1238.  
  1239. if (not modemExists() and (orders == "Rednet")) then
  1240. clear()
  1241. print("No modem was detected on this turtle!")
  1242. print("User input has been automatically selected.")
  1243. orders = "User"
  1244. sleep(3)
  1245. end
  1246.  
  1247. --Run the tunnel function based on the orders chosen
  1248. if orders == "Rednet" then
  1249. rednet.open("right")
  1250. clear()
  1251. if not useSettings then
  1252. continue = false
  1253. repeat
  1254. print("You chose to receive orders via Rednet.")
  1255. write("What computer would you like me to accept messages from?: ")
  1256. compID = tonumber(read())
  1257. if compID > 0 then
  1258. continue = true
  1259. else
  1260. invalid()
  1261. end
  1262. until continue
  1263. end
  1264. clear()
  1265. print("I will listen for orders from the computer with id: "..compID)
  1266. id, msg = rednet.receive()
  1267. if id == tonumber(compID) then
  1268. length = msg
  1269. checkChests()
  1270. checkTorches()
  1271. print("Beginning tunnel with length: "..length)
  1272. tunnel(length)
  1273. end
  1274. elseif orders == "User" then
  1275. repeat
  1276. clear()
  1277. print("You chose to receive orders via User.")
  1278. write("How long would you like the tunnel to be?(In blocks): ")
  1279. length = tonumber(read())
  1280. vType = type(length)
  1281. if vType == "number" then
  1282. print("Beginning tunnel with length: "..length)
  1283. continue = true
  1284. checkChests()
  1285. checkTorches()
  1286. tunnel(length)
  1287. else
  1288. invalid()
  1289. continue = false
  1290. end
  1291. until continue
  1292. end
  1293.  
  1294. clear()
  1295. print("I'm done!")
  1296. print("I completed a tunnel with length: "..length)
  1297.  
  1298. if not useSettings then
  1299. print("Would you like to save these settings for use in the next tunnel?(Y/N): ")
  1300. save = read()
  1301. save = string.lower(save)
  1302. if save == "y" then
  1303. saveSettings()
  1304. print("Settings have been saved")
  1305. sleep(2)
  1306. end
  1307. end
  1308. We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
  1309.  
  1310. create new paste / dealsnew! / syntax languages / archive / faq / tools / night mode / api / scraping api / go
  1311. privacy statement / cookies policy / terms of service / security disclosure / dmca / contact
  1312.  
  1313. By using Pastebin.com you agree to our cookies policy to enhance your experience.
  1314. Site design & logo © 2018 Pastebin; user contributions (pastes) licensed under cc by-sa 3.0 -- Dedicated Server Hosting by Steadfast
  1315. Top
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement