Advertisement
Pit_Anonim

Untitled

Apr 30th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.97 KB | None | 0 0
  1. A1 = 1
  2.  
  3. A2 = 1
  4. LineNum = 1
  5.  
  6. completed = 0
  7.  
  8. xcor = 0
  9.  
  10. zcor = 0
  11.  
  12. ycor = 1
  13.  
  14. zd = 0
  15.  
  16. yd = 0
  17.  
  18. xd = 0
  19.  
  20. r = 0
  21.  
  22. -- GUI --
  23.  
  24. term.clear()
  25.  
  26. term.setCursorPos(1,1)
  27.  
  28. print("Welcome to Digging programm!")
  29.  
  30. sleep(0.5)
  31.  
  32. write("X size(Forward): ")
  33. xs = read()
  34.  
  35. xs = xs + 0
  36. write("Z size(Right): ")
  37.  
  38. zs = read()
  39.  
  40. zs = zs + 0
  41.  
  42. write("Y size(Up/Down): ")
  43.  
  44. ys = read()
  45.  
  46. ys = ys + 0
  47.  
  48. print("Drop items in chest?")
  49.  
  50. while A1 == 1 do
  51.  
  52. if LineNum == 1 then
  53.  
  54. term.clearLine(6)
  55.  
  56. term.setCursorPos(1,6)
  57.  
  58. print("[Yes] No ")
  59.  
  60. elseif LineNum == 2 then
  61.  
  62. term.clearLine(6)
  63.  
  64. term.setCursorPos(1,6)
  65.  
  66. print(" Yes [No]")
  67.  
  68. end
  69.  
  70. name,data = os.pullEvent()
  71.  
  72. if name == "key" then
  73.  
  74. if data == 28 then
  75.  
  76. if LineNum == 1 then
  77.  
  78. Chest = 1
  79.  
  80. A1 = 0
  81.  
  82. elseif LineNum == 2 then
  83.  
  84. Chest = 0
  85.  
  86. A1 = 0
  87.  
  88. end
  89.  
  90. end
  91. if data == 205 or data == 200 then
  92.  
  93. LineNum = LineNum + 1
  94.  
  95. elseif data == 203 or data == 208 then
  96.  
  97. LineNum = LineNum - 1
  98. end
  99.  
  100. end
  101.  
  102. if name == "mouse_scroll" then
  103.  
  104. if data == 1 then
  105.  
  106. LineNum = LineNum + 1
  107.  
  108. elseif data == - 1 then
  109.  
  110. LineNum = LineNum - 1
  111.  
  112. end
  113.  
  114. end
  115.  
  116. if LineNum == 3 then
  117.  
  118. LineNum = 1
  119.  
  120. end
  121.  
  122. if LineNum == 0 then
  123.  
  124. LineNum = 2
  125.  
  126. end
  127.  
  128. end
  129.  
  130. LineNum = 1
  131.  
  132. while A2 == 1 do
  133.  
  134. if LineNum == 1 then
  135.  
  136. term.clearLine(7)
  137.  
  138. term.setCursorPos(1,7)
  139.  
  140. print("[Dig Up] Dig Down ")
  141.  
  142. elseif LineNum == 2 then
  143.  
  144. term.clearLine(7)
  145.  
  146. term.setCursorPos(1,7)
  147.  
  148. print(" Dig Up [Dig Down]")
  149.  
  150. end
  151.  
  152. name,data = os.pullEvent()
  153.  
  154. if name == "key" then
  155.  
  156. if data == 205 or data == 200 then
  157.  
  158. LineNum = LineNum + 1
  159.  
  160. elseif data == 203 or data == 208 then
  161.  
  162. LineNum = LineNum - 1
  163.  
  164. end
  165.  
  166. if data == 28 then
  167.  
  168. if LineNum == 1 then
  169.  
  170. Dir = "up"
  171.  
  172. A2 = 0
  173.  
  174. elseif LineNum == 2 then
  175.  
  176. Dir = "down"
  177.  
  178. A2 = 0
  179.  
  180. end
  181.  
  182. end
  183.  
  184. end
  185.  
  186. if name == "mouse_scroll" then
  187.  
  188. if data == 1 then
  189.  
  190. LineNum = LineNum + 1
  191.  
  192. elseif data == -1 then
  193.  
  194. LineNum = LineNum - 1
  195.  
  196. end
  197.  
  198. end
  199.  
  200. if LineNum == 3 then
  201.  
  202. LineNum = 1
  203.  
  204. elseif LineNum == 0 then
  205.  
  206. LineNum = 2
  207.  
  208. end
  209.  
  210. end
  211.  
  212. LineNum = 1
  213.  
  214. term.clear()
  215.  
  216. term.setCursorPos(1,1)
  217.  
  218. reqfuel = xs*zs*ys
  219.  
  220. print("Minimum fuel required: ",reqfuel)
  221.  
  222. turtle.select(1)
  223.  
  224. turtle.refuel(10)
  225.  
  226. fuel = turtle.getFuelLevel()
  227.  
  228. print("Fuel : ",fuel)
  229.  
  230. A3 = 0
  231.  
  232. if reqfuel > 100000 then
  233.  
  234. print("Sorry but selected size is")
  235.  
  236. print("too large :)")
  237.  
  238. sleep(2,5)
  239.  
  240. print("rebooting...")
  241.  
  242. sleep(1.5)
  243.  
  244. os.reboot()
  245.  
  246. end
  247.  
  248. if fuel < reqfuel then
  249.  
  250. A3 = 1
  251.  
  252. end
  253.  
  254. while A3 == 1 do
  255.  
  256. term.clearLine(2)
  257.  
  258. term.setCursorPos(1,2)
  259.  
  260. print("Fuel: [",fuel,"/",reqfuel,"]")
  261.  
  262. print("Place fuel in slot 1")
  263.  
  264. turtle.select(1)
  265.  
  266. turtle.refuel(10)
  267.  
  268. fuel = turtle.getFuelLevel()
  269.  
  270. if fuel >= reqfuel then
  271.  
  272. term.clearLine(3)
  273.  
  274. term.setCursorPos(1,3)
  275.  
  276. A3 = 0
  277.  
  278. end
  279.  
  280. end
  281.  
  282. term.clearLine(2)
  283.  
  284. term.clearLine(3)
  285.  
  286. term.setCursorPos(1,3)
  287.  
  288. print("X size : ",xs)
  289.  
  290. print("Y size : ",ys)
  291.  
  292. print("Z size : ",zs)
  293.  
  294. write("Use chest : ")
  295.  
  296. if Chest == 1 then
  297.  
  298. print("Yes"
  299. )
  300. elseif Chest == 0
  301. then
  302. print("No")
  303.  
  304. end
  305. print("Mining direction : ",Dir)
  306.  
  307. print("To start press any botton...")
  308.  
  309. print("To reboot press Ctrl...")
  310.  
  311. name,data = os.pullEvent("key")
  312.  
  313. if name == "key" and data == 29 then
  314.  
  315. os.reboot()
  316.  
  317. end
  318.  
  319. size = xs * zs * ys
  320.  
  321. local function monitor()
  322.  
  323. term.clear()
  324.  
  325. term.setCursorPos(1,1)
  326.  
  327. rfuel = turtle.getFuelLevel()
  328.  
  329. print("Fuel : ",rfuel)
  330.  
  331. print("Position : "," X: ",xcor," Y: ",ycor," Z: ",zcor)
  332.  
  333. end
  334.  
  335.  
  336. -- Mining section --
  337.  
  338. zcor = 1
  339.  
  340. completed = 0
  341.  
  342. finish = 0
  343.  
  344. A9 = 0
  345.  
  346. bd = 0
  347.  
  348. while finish == 0 do
  349.  
  350. monitor()
  351.  
  352. if Chest == 1 and turtle.getItemCount(16) > 0 then
  353.  
  354. A9 = 1
  355. xlcor = xcor
  356.  
  357. zlcor = zcor
  358.  
  359. ylcor = ycor
  360. if r == 0 then
  361.  
  362. while xcor > 1 do
  363.  
  364. if turtle.back() then
  365.  
  366. xcor = xcor - 1
  367.  
  368. end
  369.  
  370. end
  371.  
  372. turtle.turnLeft()
  373.  
  374. while zcor > 1 do
  375.  
  376. if turtle.forward() then
  377.  
  378. zcor = zcor - 1
  379.  
  380. end
  381.  
  382. end
  383.  
  384. while ycor > 1 do
  385.  
  386. if Dir == "up" then
  387.  
  388. if turtle.down() then
  389.  
  390. ycor = ycor - 1
  391.  
  392. end
  393.  
  394. elseif Dir == "down" then
  395.  
  396. if turtle.up() then
  397.  
  398. ycor = ycor - 1
  399.  
  400. end
  401.  
  402. end
  403.  
  404. end
  405.  
  406. turtle.turnRight()
  407.  
  408. end
  409. if r == 1 then
  410.  
  411. turtle.turnRight()
  412.  
  413. while zcor > 1 do
  414.  
  415. if turtle.forward() then
  416.  
  417. zcor = zcor - 1
  418.  
  419. end
  420.  
  421. end
  422.  
  423. turtle.turnLeft()
  424.  
  425. while xcor > 1 do
  426.  
  427. if turtle.forward() then
  428.  
  429. xcor = xcor - 1
  430.  
  431. end
  432.  
  433. end
  434.  
  435. turtle.turnRight()
  436.  
  437. turtle.turnRight()
  438.  
  439. while ycor > 1 do
  440.  
  441. if Dir == "up" then
  442.  
  443. if turtle.down() then
  444.  
  445. ycor = ycor - 1
  446.  
  447. end
  448.  
  449. elseif Dir == "down" then
  450.  
  451. if turtle.up() then
  452.  
  453. ycor = ycor - 1
  454.  
  455. end
  456.  
  457. end
  458.  
  459. end
  460.  
  461. end
  462.  
  463. turtle.back()
  464.  
  465. slotNum = 16
  466.  
  467. turtle.select(16)
  468.  
  469. turtle.dropUp()
  470.  
  471. while slotNum > 1 do
  472.  
  473. slotNum = slotNum - 1
  474.  
  475. turtle.select(slotNum)
  476.  
  477. turtle.dropUp()
  478.  
  479. end
  480.  
  481. turtle.forward()
  482.  
  483. while xcor < xlcor do
  484.  
  485. turtle.dig()
  486.  
  487. if turtle.forward() then
  488.  
  489. xcor = xcor + 1
  490.  
  491. end
  492.  
  493. end
  494.  
  495. turtle.turnRight()
  496.  
  497. while zcor < zlcor do
  498.  
  499. turtle.dig()
  500.  
  501. if turtle.forward() then
  502.  
  503. zcor = zcor + 1
  504.  
  505. end
  506.  
  507. end
  508.  
  509. if r == 0 then
  510.  
  511. turtle.turnLeft()
  512.  
  513. elseif r == 1 then
  514.  
  515. turtle.turnRight()
  516.  
  517. end
  518.  
  519. while ycor < ylcor do
  520.  
  521. if Dir == "up" then
  522.  
  523. if turtle.up() then
  524.  
  525. ycor = ycor + 1
  526.  
  527. end
  528.  
  529. elseif Dir == "down" then
  530.  
  531. if turtle.down() then
  532.  
  533. ycor = ycor + 1
  534.  
  535. end
  536.  
  537. end
  538.  
  539. end
  540.  
  541. end
  542.  
  543. turtle.dig()
  544.  
  545. if ys - yd > 1 and xcor > 0 then
  546.  
  547. if Dir == "up" then
  548.  
  549. turtle.digUp()
  550.  
  551. elseif Dir == "down" then
  552.  
  553. turtle.digDown()
  554.  
  555. end
  556.  
  557. end
  558.  
  559. monitor()
  560.  
  561. if finish == 0 and turtle.forward() then
  562.  
  563. monitor()
  564.  
  565. xd = xd + 1
  566.  
  567. if r == 0 then
  568.  
  569. xcor = xcor + 1
  570.  
  571. elseif r == 1 then
  572.  
  573. xcor = xcor - 1
  574.  
  575. end
  576.  
  577. end
  578.  
  579. if zd + 1 == zs and xd == xs then
  580.  
  581. completed = 1
  582.  
  583. end
  584.  
  585. if completed == 1 then
  586.  
  587. if r == 0 then
  588.  
  589. turtle.turnLeft()
  590.  
  591. if ys - yd > 1 then
  592.  
  593. if Dir == "up" then
  594.  
  595. turtle.digUp()
  596.  
  597. elseif Dir == "down" then
  598.  
  599. turtle.digDown()
  600.  
  601. end
  602.  
  603. end
  604.  
  605. monitor()
  606.  
  607. while zcor > 1 do
  608.  
  609. turtle.dig()
  610.  
  611. if turtle.forward() then
  612.  
  613. zcor = zcor - 1
  614.  
  615. end
  616.  
  617. end
  618.  
  619. turtle.turnLeft()
  620.  
  621. while xcor > 1 do
  622.  
  623. turtle.dig()
  624.  
  625. if turtle.forward() then
  626.  
  627. xcor = xcor - 1
  628.  
  629. end
  630.  
  631. end
  632.  
  633. turtle.turnLeft()
  634.  
  635. turtle.turnLeft()
  636.  
  637. end
  638.  
  639. if r == 1 then
  640.  
  641. r = 0
  642.  
  643. if ys - yd > 1 then
  644.  
  645. if Dir == "up" then
  646.  
  647. turtle.digUp()
  648.  
  649. elseif Dir == "down" then
  650.  
  651. turtle.digDown()
  652.  
  653. end
  654.  
  655. end
  656.  
  657. turtle.turnRight()
  658.  
  659. while zcor > 1 do
  660.  
  661. if turtle.forward() then
  662.  
  663. zcor = zcor - 1
  664.  
  665. end
  666.  
  667. end
  668.  
  669. turtle.turnRight()
  670.  
  671. end
  672.  
  673. if ys - yd > 1 then
  674.  
  675. yd = yd + 2
  676.  
  677. elseif ys - yd == 1 then
  678.  
  679. yd = yd + 1
  680.  
  681. end
  682.  
  683. end
  684.  
  685. monitor()
  686.  
  687. if completed == 1 and yd < ys then
  688.  
  689. xd = 1
  690.  
  691. zd = 0
  692.  
  693. zcor = 1
  694.  
  695. xcor = 1
  696.  
  697. completed = 0
  698.  
  699. ycor = ycor + 2
  700.  
  701. A8 = 1
  702.  
  703. if Dir == "up" then
  704.  
  705. while A8 == 1 do
  706.  
  707. turtle.digUp()
  708.  
  709. if turtle.up() then
  710.  
  711. A8 = 0
  712.  
  713. end
  714.  
  715. end
  716.  
  717. A8 = 1
  718.  
  719. while A8 == 1 do
  720.  
  721. turtle.digUp()
  722.  
  723. if turtle.up() then
  724.  
  725. A8 = 0
  726.  
  727. end
  728.  
  729. end
  730.  
  731. elseif Dir == "down" then
  732.  
  733. while A8 == 1 do
  734.  
  735. turtle.digDown()
  736.  
  737. if turtle.down() then
  738.  
  739. A8 = 0
  740.  
  741. end
  742.  
  743. end
  744.  
  745. A8 = 1
  746.  
  747. while A8 == 1 do
  748.  
  749. turtle.digDown()
  750.  
  751. if turtle.down() then
  752.  
  753. A8 = 0
  754.  
  755. end
  756.  
  757. end
  758.  
  759. end
  760.  
  761. end
  762.  
  763. monitor()
  764.  
  765. if completed == 1 and yd == ys then
  766.  
  767. print("completed!")
  768.  
  769. while ycor > 1 do
  770.  
  771. if Dir == "up" then
  772.  
  773. turtle.digUp()
  774.  
  775. if turtle.down() then
  776.  
  777. ycor = ycor - 1
  778.  
  779. end
  780.  
  781. elseif Dir == "down" then
  782.  
  783. turtle.digDown()
  784.  
  785. if turtle.up() then
  786.  
  787. ycor = ycor - 1
  788.  
  789. end
  790.  
  791. end
  792.  
  793. end
  794.  
  795. finish = 1
  796.  
  797. end
  798.  
  799. if completed == 0 and xd == xs and r == 0 and zd<zs then
  800.  
  801. if ys - yd > 1 then
  802.  
  803. if Dir == "down" then
  804.  
  805. turtle.digDown()
  806.  
  807. elseif Dir == "up" then
  808.  
  809. turtle.digUp()
  810.  
  811. end
  812.  
  813. end
  814.  
  815. A4 = 1
  816.  
  817. xd = 1
  818.  
  819. r = 1
  820.  
  821. zd = zd + 1
  822.  
  823. zcor = zcor + 1
  824.  
  825. turtle.turnRight()
  826.  
  827. while A4 == 1 do
  828.  
  829. turtle.dig()
  830.  
  831. if turtle.forward() then
  832.  
  833. A4 = 0
  834.  
  835. end
  836.  
  837. end
  838.  
  839. turtle.turnRight()
  840.  
  841. end
  842.  
  843. if completed == 0 and xd == xs and r == 1 and zd < zs then
  844.  
  845. if ys - yd > 1 then
  846.  
  847. if Dir == "up" then
  848.  
  849. turtle.digUp()
  850.  
  851. elseif Dir == "down" then
  852.  
  853. turtle.digDown()
  854.  
  855. end
  856.  
  857. end
  858.  
  859. A5 = 1
  860.  
  861. xd = 1
  862.  
  863. r = 0
  864.  
  865. zd = zd + 1
  866.  
  867. zcor = zcor + 1
  868.  
  869. turtle.turnLeft()
  870.  
  871. while A5 == 1 do
  872.  
  873. turtle.dig()
  874.  
  875. if turtle.forward() then
  876.  
  877. A5 = 0
  878.  
  879. end
  880.  
  881. end
  882.  
  883. turtle.turnLeft()
  884.  
  885. end
  886.  
  887. monitor()
  888.  
  889. end
  890.  
  891. monitor()
  892.  
  893. print("Completed!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement