Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 90.14 KB | None | 0 0
  1. --[[ORE COLLECTING MINER V2.6 by BrunoZockt
  2.  
  3. MIT License
  4.  
  5. Copyright (c) 2018 Bruno Heberle
  6.  
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13.  
  14. The above copyright notice and this permission notice shall be included in all
  15. copies or substantial portions of the Software.
  16.  
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. SOFTWARE.
  24.  
  25.  
  26. V1.0 released 22.07.2016 17kb
  27. V1.1 released 16.08.2016 17kb
  28. V2.0 released 07.10.2017 35kb
  29. V2.1 released 15.12.2017 40kb
  30. V2.2 released 17.12.2017 42kb
  31. V2.3 released 11.02.2018 46kb
  32. V2.4 released 19.06.2018 57kb
  33. V2.5 released 15.07.2018 68kb
  34. V2.5.1 released 19.08.2018 78kb
  35. V2.6 released 16.09.2018 90kb
  36. This program is a work in progress and
  37. will automatically update itself.
  38. If you have any problems, questions or
  39. suggestions I'd be happy if you wrote
  40. an e-mail to 8run0z0ckt@gmail.com.
  41. Feel free to use this program whenever
  42. you want. If you want to use parts of
  43. my program for developing, do so but
  44. don't say it's yours - a sidenote
  45. e.g. "by BrunoZockt" would be nice :)
  46. If you want to understand this program
  47. I recommend to read the variables first
  48. and then the rest of the code from the
  49. bottom to the top! Maybe I will add
  50. some comments for better understanding
  51. soon! The names of my functions and
  52. variables may sound strange because
  53. some are german and others are not
  54. really creative, but I hope you
  55. understand it anyways ;) ]]--
  56.  
  57. local HOST_ENV = _ENV or getfenv()
  58. local OUR_ENV = {}
  59.  
  60. setmetatable(OUR_ENV, {__index = HOST_ENV, OUR_ENV = OUR_ENV})
  61. setfenv(1, OUR_ENV)
  62.  
  63. -----###-----configurable variables-----###-----
  64.  
  65. settings = {
  66. ["language"] = "en",
  67. ["tunnelspace"] = 4,
  68. ["quantity"] = 10,
  69. ["length"] = 8,
  70. ["ignor"] = {"minecraft:stone", "minecraft:cobblestone", "minecraft:dirt", "minecraft:lava", "minecraft:flowing_lava", "minecraft:water", "minecraft:flowing_water", "minecraft:torch"},
  71. ["chestSelect"] = 3,
  72. ["torches"] = true,
  73. ["mainTorches"] = true,
  74. ["lateralTorches"] = 1,
  75. ["Autofuel"] = false,
  76. ["floor"] = true,
  77. ["trash"] = false,
  78. ["walls"] = false
  79. }
  80.  
  81. -----###-----constants-----###-----
  82.  
  83. local programName = shell.getRunningProgram()
  84. local label = os.getComputerLabel() or "the turtle"
  85. local chestSlot = 16
  86. local fuelLevel = 100
  87. local w, h = term.getSize()
  88. local kill = false
  89. chestList = {"minecraft:chest", "IronChest:BlockIronChest", "IronChest:BlockIronChest:1", "IronChest:BlockIronChest:2", "IronChest:BlockIronChest:3", "IronChest:BlockIronChest:4", "IronChest:BlockIronChest:5", "IronChest:BlockIronChest:6"}
  90. enderChestList = {"EnderStorage:enderChest", "ThermalExpansion:Strongbox", "ThermalExpansion:Tesseract"}
  91. cardinal = {"North", "West", "South", "East"}
  92.  
  93. -----###-----mining variables-----###-----
  94.  
  95. variables = {
  96. ["searching"] = false,
  97. ["level"] = 0,
  98. ["direction"] = 1,
  99. ["cache"] = {},
  100. ["maxSpace"] = false,
  101. ["setup"] = false,
  102. ["index"] = 2,
  103. ["slots"] = {"_","_","_","_","_","_","_","_","_","_","_","_","_","_","_","_"},
  104. ["torchPositions"] = {},
  105. ["stats"] = {
  106. ["dug"] = 0,
  107. ["ores"] = 0,
  108. ["time"] = 0,
  109. ["moves"] = 0
  110. },
  111. ["TorchDemand"] = 0,
  112. ["orientation"] = {},
  113. ["CrosswayAmount"] = 0,
  114. ["FuelDemand"] = 0,
  115. ["startDay"] = 0,
  116. ["startTime"] = 0
  117. }
  118.  
  119. -----###-----menu variables-----###-----
  120.  
  121. local select = 1
  122. local menustate
  123. local checkbox = false
  124. local gone = {}
  125. local timer = {}
  126. local chest = {"enderchest", "chest", "none"}
  127. local objects = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
  128. local errors = {false, false, false, false, false, false, false, false}
  129. local Check = {["Fuellevel"] = false, ["torches"] = false, ["chest"] = false}
  130.  
  131. local menuVars = {
  132. ["notificationCenter"] = {
  133. time = 0
  134. },
  135. ["drawOptions"] = {
  136. shift = 0,
  137. shift2 = 0,
  138. saved = false,
  139. scroll = 0,
  140. scroll2 = 0,
  141. focus = 100,
  142. ypos
  143. },
  144. ["drawPopup"] = {
  145. scroll = 0,
  146. lastscroll = 0,
  147. ypos = 9
  148. },
  149. ["drawNews"] = {
  150. scroll = 0
  151. }
  152. }
  153.  
  154.  
  155. -----###-----helpful functions-----###-----
  156.  
  157. function Sprint(str, xpos, ypos)
  158. term.setCursorPos(xpos, ypos)
  159. term.write(str)
  160. end
  161.  
  162. function printCentered(str, ypos)
  163. term.setCursorPos(w/2 - #str/2 + 1, ypos)
  164. term.write(str)
  165. end
  166.  
  167. function printRight(str, ypos, xoffset)
  168. if xoffset == nil then
  169. xoffset = 0
  170. end
  171. term.setCursorPos(w - xoffset - (#str - 1), ypos)
  172. term.write(str)
  173. end
  174.  
  175. function printLeft(str, ypos)
  176. term.setCursorPos(1, ypos)
  177. term.write(str)
  178. end
  179.  
  180. function printB(tab, y, stop, start)
  181. if start == nil then
  182. start = 1
  183. end
  184. if stop == nil then
  185. stop = w
  186. end
  187. local letters = 0
  188. for i in pairs(tab) do
  189. letters = letters + #tab[i]
  190. end
  191. local space = (stop-start)+1-letters
  192. term.setCursorPos(start, y)
  193. if (space/(#tab+1))%1 == 0 then
  194. for i in ipairs(tab) do
  195. term.write(string.rep(" ", space/(#tab+1))..tab[i])
  196. end
  197. elseif (space/(#tab))%2 == 0 then
  198. term.write(string.rep(" ", (space/#tab)/2))
  199. for i in ipairs(tab) do
  200. term.write(tab[i]..string.rep(" ", space/#tab))
  201. end
  202. elseif space == #tab-1 then
  203. term.write(tab[1])
  204. for i = 2, #tab do
  205. term.write(" "..tab[i])
  206. end
  207. else
  208. for i in ipairs(tab) do
  209. term.write(string.rep(" ", round(space/(#tab-i+2), "u"))..tab[i])
  210. space = space - round(space/(#tab-i+2), "u")
  211. end
  212. end
  213. end
  214.  
  215. function printWrapped(tab, xpos, ypos, Space, sep)
  216. local sep = sep or " "
  217. if tab[1] == "-" then
  218. Sprint(tab[1]..sep, xpos, ypos)
  219. table.remove(tab, 1)
  220. xpos = xpos+2
  221. Space = Space-2
  222. end
  223. local leftSpace = Space
  224. local newxpos = xpos
  225. for word = 1, #tab do
  226. if Space < #tab[word] + #sep then
  227. return false
  228. elseif leftSpace >= #tab[word]+#sep then
  229. Sprint(tab[word]..sep, newxpos, ypos)
  230. leftSpace = leftSpace - (#tab[word]+#sep)
  231. newxpos = newxpos + #tab[word]+#sep
  232. else
  233. ypos = ypos + 1
  234. leftSpace = Space
  235. Sprint(tab[word]..sep, xpos, ypos)
  236. leftSpace = leftSpace - (#tab[word]+#sep)
  237. newxpos = xpos + (#tab[word]+#sep)
  238. end
  239. end
  240. return ypos
  241. end
  242.  
  243. function printLine(xpos, start, stop, point, endPoint)
  244. for i = start, stop do
  245. Sprint("|", xpos, i)
  246. end
  247. if point ~= nil then
  248. Sprint(point, xpos, start)
  249. Sprint((endPoint or point), xpos, stop)
  250. end
  251. end
  252.  
  253. function Splitter(inputstr, sep)
  254. if inputstr == nil then
  255. return nil
  256. elseif sep == nil then
  257. sep = "%s"
  258. end
  259. local t, i = {}, 1
  260. for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  261. t[i] = str
  262. i = i + 1
  263. end
  264. return t
  265. end
  266.  
  267. local Version = tonumber(Splitter(os.version())[2])
  268.  
  269. function ItemCount(Block, Slot)
  270. if Slot == 0 then
  271. return false
  272. elseif Slot == nil then
  273. return false
  274. end
  275. local loops = 1
  276. if type(Block) == "table" then
  277. loops = #Block
  278. end
  279. if Version >= 1.64 then
  280. for i = 1, loops do
  281. local Data = turtle.getItemDetail(Slot)
  282. if Data == nil then
  283. return 0
  284. elseif loops == 1 then
  285. if Data.name == Block then
  286. return Data.count
  287. end
  288. else
  289. if Data.name == Block[i] then
  290. return Data.count
  291. end
  292. end
  293. end
  294. return false
  295. else
  296. return turtle.getItemCount(Slot)
  297. end
  298. end
  299.  
  300. function Color()
  301. if Version <= 1.45 then
  302. return false
  303. elseif term.isColor() then
  304. return true
  305. else
  306. return false
  307. end
  308. end
  309.  
  310. function MoveObjects(deleted, mode)
  311. if mode == 1 then
  312. for k, v in ipairs(gone) do
  313. if v == deleted then
  314. return
  315. end
  316. end
  317. for k, v in ipairs(objects) do
  318. if k > deleted and k < 12 then
  319. objects[k] = objects[k] - 1
  320. end
  321. end
  322. table.insert(gone, deleted)
  323. elseif mode == 2 then
  324. for k, v in ipairs(gone) do
  325. if v == deleted then
  326. table.remove(gone, k)
  327. for k, v in ipairs(objects) do
  328. if k > deleted and k < 12 then
  329. objects[k] = objects[k] + 1
  330. end
  331. end
  332. end
  333. end
  334. end
  335. end
  336.  
  337. function OreCounter()
  338. if variables.searching == true then
  339. variables.stats["ores"] = variables.stats["ores"] + 1
  340. if variables.stats["ores"] == 1 then
  341. print(lang.status(settings.language, 1))
  342. else
  343. print(lang.status(settings.language, 2, variables.stats["ores"]))
  344. end
  345. end
  346. end
  347.  
  348. function SlotCalculator(code, param)
  349. local output = {}
  350. local item
  351. if param ~= nil and param ~= "check" then
  352. item = param
  353. elseif param == "check" then
  354. if code == "T" then
  355. item = "minecraft:torch"
  356. elseif code == "C" then
  357. if settings.chestSelect == 1 then
  358. item = enderChestList
  359. elseif settings.chestSelect == 2 then
  360. item = chestList
  361. end
  362. end
  363. end
  364. for n = 1, #variables.slots do
  365. if variables.slots[n] == code then
  366. if param == "empty" then
  367. table.insert(output, n)
  368. elseif param == nil then
  369. if turtle.getItemCount(n) > 0 then
  370. table.insert(output, n)
  371. end
  372. elseif ItemCount(item, n) ~= false and ItemCount(item, n) ~= 0 then
  373. table.insert(output, n)
  374. end
  375. end
  376. end
  377. return output
  378. end
  379.  
  380. function refuel(Amount, Execute)
  381. local ActualAmount = turtle.getItemCount()
  382. if ActualAmount < Amount then
  383. if Execute == true then
  384. if turtle.refuel() == false then
  385. return false
  386. else
  387. while turtle.refuel() ~= false do
  388. end
  389. return ActualAmount
  390. end
  391. else
  392. return false
  393. end
  394. else
  395. turtle.refuel(Amount)
  396. return true
  397. end
  398. end
  399.  
  400. function basicInputHandler(orientation, event, key)
  401. if event == "key" then
  402. if key == 28 then
  403. menustate = menu[menustate].options[select]
  404. select = 1
  405. elseif orientation == "vertical" then
  406. if key == 200 and select > 1 then
  407. select = select-1
  408. elseif key == 208 and select < #menu[menustate].options then
  409. select = select + 1
  410. end
  411. else
  412. if key == 203 and select > 1 then
  413. select = select - 1
  414. elseif key == 205 and select < #menu[menustate].options then
  415. select = select + 1
  416. end
  417. end
  418. end
  419. end
  420.  
  421. function save(path, content, todolist)
  422. local file = fs.open(path, "w")
  423. if todolist then
  424. file.writeLine("todoList = "..textutils.serialize(content))
  425. elseif type(content) == "table" then
  426. for k, v in pairs(content) do
  427. if type(content[k]) == "table" then
  428. file.writeLine(k.." = "..textutils.serialize(content[k]))
  429. else
  430. file.writeLine(k.." = "..tostring(content[k]))
  431. end
  432. end
  433. else
  434. file.writeLine(content)
  435. end
  436. file.close()
  437. end
  438.  
  439. function translate(str, category)
  440. if category == "layout" then
  441. n = 35
  442. end
  443. for i = 1, n do
  444. if str == lang[category]("en", i) then
  445. return lang[category](settings.language, i)
  446. end
  447. end
  448. end
  449.  
  450. function round(int, mode, dez)
  451. if dez == nil then
  452. dez = 1
  453. end
  454. if mode == "d" then
  455. mode = 0.4999
  456. elseif mode == "u" then
  457. mode = 0.5
  458. end
  459. return math.floor(int/dez+mode)*dez
  460. end
  461.  
  462. local function compile(chunk) -- returns compiled chunk or nil and error message
  463. if type(chunk) ~= "string" then
  464. error("expected string, got ".. type(chunk), 2)
  465. end
  466.  
  467. local function findChunkName(var)
  468. for k,v in pairs(HOST_ENV) do
  469. if v==var then
  470. return k
  471. end
  472. end
  473. return "Unknown chunk"
  474. end
  475.  
  476. return load(chunk, findChunkName(chunk), "t", OUR_ENV)
  477. end
  478.  
  479. function insert(code)
  480. table.insert(todoList, variables.index, code)
  481. variables.index = variables.index + 1
  482. save("database/OCM/resume/todoList", todoList, true)
  483. end
  484.  
  485. -----###-----improved functions-----###-----
  486.  
  487. function dig(gravel)
  488. local a = false
  489. insert('OreCounter()')
  490. variables.stats["dug"] = variables.stats["dug"] + 1
  491. if gravel then
  492. while turtle.dig() do
  493. os.sleep(0.05)
  494. a = true
  495. end
  496. return a
  497. else
  498. return turtle.dig()
  499. end
  500. end
  501.  
  502. function digUp()
  503. insert('OreCounter()')
  504. variables.stats["dug"] = variables.stats["dug"] + 1
  505. return turtle.digUp()
  506. end
  507.  
  508. function digDown()
  509. insert('OreCounter()')
  510. variables.stats["dug"] = variables.stats["dug"] + 1
  511. return turtle.digDown()
  512. end
  513.  
  514. function face(int)
  515. if int == variables.direction then
  516. return
  517. elseif (int + variables.direction)%2 == 0 then
  518. return turn()
  519. elseif math.abs(int - variables.direction) == 1 then
  520. if variables.direction < int then
  521. return left()
  522. else
  523. return right()
  524. end
  525. else
  526. if variables.direction < int then
  527. return right()
  528. else
  529. return left()
  530. end
  531. end
  532. end
  533.  
  534. function right()
  535. turtle.turnRight()
  536. variables.direction = variables.direction - 1
  537. if variables.direction == 0 then
  538. variables.direction = 4
  539. end
  540. end
  541.  
  542. function left()
  543. turtle.turnLeft()
  544. variables.direction = variables.direction + 1
  545. if variables.direction == 5 then
  546. variables.direction = 1
  547. end
  548. end
  549.  
  550. function turn()
  551. left()
  552. left()
  553. end
  554.  
  555. function Freeway()
  556. variables.searching = false
  557. insert([[while not turtle.forward() do
  558. if turtle.getFuelLevel() == 0 then
  559. Fuel()
  560. elseif dig() == false then
  561. turtle.attack()
  562. end
  563. end]])
  564. variables.stats["moves"] = variables.stats["moves"] + 1
  565. end
  566.  
  567. function FreewayUp()
  568. variables.searching = false
  569. insert("variables.level = variables.level + 1")
  570. insert([[while not turtle.up() do
  571. if turtle.getFuelLevel() == 0 then
  572. Fuel()
  573. elseif digUp() == false then
  574. turtle.attackUp()
  575. end
  576. end]])
  577. variables.stats['moves'] = variables.stats['moves'] + 1
  578. end
  579.  
  580. function FreewayDown()
  581. variables.searching = false
  582. insert("variables.level = variables.level - 1")
  583. insert([[while not turtle.down() do
  584. if turtle.getFuelLevel() == 0 then
  585. Fuel()
  586. elseif digDown() == false then
  587. turtle.attackDown()
  588. end
  589. end]])
  590. variables.stats['moves'] = variables.stats['moves'] + 1
  591. end
  592.  
  593. function FreewayBack()
  594. variables.searching = false
  595. while not turtle.back() do
  596. if turtle.getFuelLevel() == 0 then
  597. Fuel()
  598. else
  599. turn()
  600. insert([[if dig() == false then
  601. for i = 1, 20 do
  602. turtle.attack()
  603. os.sleep(0.05)
  604. end
  605. end]])
  606. turn()
  607. end
  608. end
  609. variables.stats["moves"] = variables.stats["moves"] + 1
  610. end
  611.  
  612.  
  613. -----###-----drawMenus-----###-----
  614.  
  615. function notificationCenter()
  616. local advice = {
  617. lang.adv(settings.language, 1, ErrorSlot),
  618. lang.adv(settings.language, 2, 1),
  619. lang.adv(settings.language, 3, chestSlot),
  620. lang.adv(settings.language, 4, chestSlot),
  621. lang.adv(settings.language, 5, chestSlot),
  622. lang.adv(settings.language, 6, chestSlot),
  623. lang.adv(settings.language, 7, 1),
  624. lang.adv(settings.language, 8, 1)
  625. }
  626. if menuVars["notificationCenter"].time > 5 then
  627. for i = 1, #errors do
  628. if errors[i] ~= false then
  629. printWrapped(Splitter(advice[i], " "), 1, objects[8], w - 10)
  630. return
  631. end
  632. end
  633. end
  634. for i = 1, 4 do
  635. printLeft(lang.layout(settings.language, i), objects[i+7])
  636. end
  637. menuVars["notificationCenter"].time = menuVars["notificationCenter"].time + 0.5
  638. end
  639.  
  640. function drawPopup(event, p1, p2, p3)
  641. local errorMessages = {
  642. lang.popup(settings.language, 1, ErrorSlot),
  643. lang.popup(settings.language, 2),
  644. lang.popup(settings.language, 1, chestSlot),
  645. lang.popup(settings.language, 3),
  646. lang.popup(settings.language, 1, chestSlot),
  647. lang.popup(settings.language, 4),
  648. lang.popup(settings.language, 5),
  649. lang.popup(settings.language, 6)
  650. }
  651. local leftBorder = round(w/9, "u")
  652. local rightBorder = round(w+1-w/9, "u")
  653. local winWidth = rightBorder-leftBorder-1
  654.  
  655. menuVars["drawPopup"].lastscroll = menuVars["drawPopup"].scroll
  656.  
  657. if event == "mouse_scroll" then
  658. menuVars["drawPopup"].scroll = menuVars["drawPopup"].scroll - p1
  659. elseif event == "mouse_click" and p1 == 1 then
  660. if p2 == leftBorder+winWidth then
  661. if p3 == 6 then
  662. menuVars["drawPopup"].scroll = menuVars["drawPopup"].scroll + 1
  663. elseif p3 == h-3 then
  664. menuVars["drawPopup"].scroll = menuVars["drawPopup"].scroll - 1
  665. end
  666. end
  667. elseif event == "key" then
  668. if p1 == 208 then
  669. menuVars["drawPopup"].scroll = menuVars["drawPopup"].scroll - 1
  670. elseif p1 == 200 then
  671. menuVars["drawPopup"].scroll = menuVars["drawPopup"].scroll + 1
  672. end
  673. end
  674. if menuVars["drawPopup"].scroll < -(menuVars["drawPopup"].ypos-menuVars["drawPopup"].lastscroll-(math.ceil((h-6)/10)+6)) then
  675. menuVars["drawPopup"].scroll = -(menuVars["drawPopup"].ypos-menuVars["drawPopup"].lastscroll-(math.ceil((h-6)/10)+6))
  676. elseif menuVars["drawPopup"].scroll > 0 then
  677. menuVars["drawPopup"].scroll = 0
  678. end
  679.  
  680. printLine(leftBorder, 4, h-1, "+")
  681. printLine(rightBorder, 4, h-1, "+")
  682. menuVars["drawPopup"].ypos = math.ceil((h-6)/10)+5+menuVars["drawPopup"].scroll
  683. for i = 1, #errors do
  684. if errors[i] == true then
  685. menuVars["drawPopup"].ypos = printWrapped(Splitter("- "..errorMessages[i]), leftBorder+1, menuVars["drawPopup"].ypos+1, winWidth, " ")
  686. end
  687. end
  688. printCentered(string.rep("-", winWidth), 4)
  689. printCentered(string.rep("-", winWidth), h-1)
  690. printCentered(string.rep(" ", winWidth), 5)
  691. printCentered(string.rep(" ", winWidth), 6)
  692. printWrapped(Splitter(lang.popup(settings.language, 7, label)), leftBorder+1, math.ceil((h-6)/10)+4, winWidth, " ")
  693. printCentered(string.rep(" ", winWidth), h-3)
  694. printCentered(string.rep(" ", winWidth), 3)
  695. drawHeader()
  696. printLine(rightBorder-1, 6, h-3, "^", "v")
  697. if select == 1 then
  698. printB({">"..lang.popup(settings.language, 8).."<"," "..lang.popup(settings.language, 9).." ", " "..lang.popup(settings.language, 10).." "}, math.ceil((h-6)/10*9)+4, rightBorder-1, leftBorder+1)
  699. elseif select == 2 then
  700. printB({" "..lang.popup(settings.language, 8).." ",">"..lang.popup(settings.language, 9).."<", " "..lang.popup(settings.language, 10).." "}, math.ceil((h-6)/10*9)+4, rightBorder-1, leftBorder+1)
  701. else
  702. printB({" "..lang.popup(settings.language, 8).." "," "..lang.popup(settings.language, 9).." ", ">"..lang.popup(settings.language, 10).."<"}, math.ceil((h-6)/10*9)+4, rightBorder-1, leftBorder+1)
  703. end
  704. end
  705.  
  706. function drawHeader()
  707. printCentered("ORE SEARCHING STRIP MINER by BrunoZockt", 1)
  708. printLeft(string.rep("-", w), 2)
  709. end
  710.  
  711. function drawUpdate(event, p1, p2, p3)
  712. local leftBorder = round(w/6, "u")
  713. local rightBorder = round(w/6*5, "u")
  714. local winWidth = rightBorder-leftBorder-1
  715. local space = round(winWidth-13, "u")
  716. if event == "mouse_click" and p1 == 1 then
  717. if p2 == leftBorder+3 and p3 == math.ceil((h-6)/2)+5 then
  718. checkbox = not checkbox
  719. elseif p3 == math.ceil((h-6)/10*9)+4 then
  720. if p2 >= leftBorder+round(0.25*space, "u")+1 and p2 <= leftBorder+round(0.25*space, "u")+11 then
  721. if select == 1 then
  722. menustate = menu[menustate].options[select]
  723. else
  724. select = 1
  725. end
  726. elseif leftBorder+round(0.75*space, "u")+12 <= p2 and p2 <= leftBorder+round(0.75*space, "u")+13 then
  727. if select == 2 then
  728. menustate = menu[menustate].options[select]
  729. else
  730. select = 2
  731. end
  732. end
  733. end
  734. elseif event == "key" then
  735. if p1 == 203 and select > 1 then
  736. select = select - 1
  737. elseif p1 == 205 and select < #menu[menustate].options then
  738. select = select + 1
  739. elseif p1 == 28 then
  740. menustate = menu[menustate].options[select]
  741. end
  742. end
  743. printCentered(lang.layout(settings.language, 5), math.ceil((h-6)/6.9)+4)
  744. printCentered(string.rep("-", math.floor(w/3*2)), 4)
  745. printCentered(string.rep("-", math.floor(w/3*2)), 12)
  746. printLine(leftBorder, 4, 12, "+")
  747. printLine(rightBorder, 4, 12, "+")
  748. Sprint("_", leftBorder+3, math.ceil((h-6)/2)+4)
  749. Sprint("|_|"..lang.layout(settings.language, 6), leftBorder+2, math.ceil((h-6)/2)+5)
  750. if select == 1 then
  751. printB({">"..lang.layout(settings.language, 7).."<", " "..lang.layout(settings.language, 8).." "}, math.ceil((h-6)/10*9)+4, rightBorder-1, leftBorder+1)
  752. elseif select == 2 then
  753. printB({" "..lang.layout(settings.language, 7).." ", ">"..lang.layout(settings.language, 8).."<"}, math.ceil((h-6)/10*9)+4, rightBorder-1, leftBorder+1)
  754. end
  755. if checkbox == true then
  756. Sprint("X", leftBorder+3, math.ceil((h-6)/2)+5)
  757. end
  758. end
  759.  
  760. function drawNews(event, p1, p2, p3)
  761. if event == "mouse_scroll" then
  762. menuVars["drawNews"].scroll = menuVars["drawNews"].scroll - p1
  763. elseif event == "key" then
  764. if p1 == 28 then
  765. menustate = menu[menustate].options[select]
  766. select = 1
  767. menuVars["drawNews"].scroll = 0
  768. elseif p1 == 208 then
  769. menuVars["drawNews"].scroll = menuVars["drawNews"].scroll - 1
  770. elseif p1 == 200 then
  771. menuVars["drawNews"].scroll = menuVars["drawNews"].scroll + 1
  772. end
  773. elseif event == "mouse_click" then
  774. if p1 == 1 then
  775. if p2 == w then
  776. if p3 == 3 then
  777. menuVars["drawNews"].scroll = menuVars["drawNews"].scroll + 1
  778. elseif p3 == h then
  779. menuVars["drawNews"].scroll = menuVars["drawNews"].scroll - 1
  780. end
  781. elseif p2 >= w/2-2 and p2 <= w/2+2 and p3 == h then
  782. menustate = menu[menustate].options[select]
  783. select = 1
  784. menuVars["drawNews"].scroll = 0
  785. end
  786. end
  787. end
  788. if menuVars["drawNews"].scroll > 0 then
  789. menuVars["drawNews"].scroll = 0
  790. elseif menuVars["drawNews"].scroll < -283 then
  791. menuVars["drawNews"].scroll = -283
  792. end
  793. Sprint("Patch 2.6", 1, 3+menuVars["drawNews"].scroll)
  794. Sprint("-----------", 1, 4+menuVars["drawNews"].scroll)
  795. Sprint("1.NEW FEATURES", 2, 6+menuVars["drawNews"].scroll)
  796. local ypos = printWrapped(Splitter("- The program will now continue automatically after a server restart."), 3, 7+menuVars["drawNews"].scroll, w-3, " ")
  797. ypos = printWrapped(Splitter("- To achieve this it is very important that there is always one torch available so that the turtle can orientate itself."), 4, ypos+1, w-4, " ")
  798. ypos = printWrapped(Splitter("- The program will also install my Startup Handler in 'startup' so that it can be automatically executed. Any file existing in 'startup' will be moved to 'old_startup' and called whenever there is no program that needs to be resumed."), 4, ypos+1, w-4, " ")
  799. ypos = printWrapped(Splitter("- Everything that needs to be done is written to an extern file, which also takes up some disk space (very unlikely to exceed 10kb). So make sure that there is some file space left."), 4, ypos+1, w-4, " ")
  800. ypos = printWrapped(Splitter("- The options 'chest' and 'enderchest' are now compatible with all the chests from the mods 'Iron chests' and 'Thermal Expansion'."), 4, ypos+1, w-4, " ")
  801. Sprint("2.OPTIMIZATIONS", 2, ypos+2)
  802. ypos = printWrapped(Splitter("- The path of the external files is now including your program name so that you could have multiple instances of the program on one turtle. The updater had to be modified aswell."), 3, ypos+3, w-3, " ")
  803. ypos = printWrapped(Splitter("- This page looks a lot cleaner now."), 3, ypos+3, w-3, " ")
  804. ypos = printWrapped(Splitter("- The variables are now ordered a lot better by splitting them into categories."), 3, ypos+1, w-3, " ")
  805. ypos = printWrapped(Splitter("- Many minor changes in program structure to save a few bytes."), 3, ypos+1, w-3, " ")
  806. Sprint("3.Bug fixes", 2, ypos+2)
  807. ypos = printWrapped(Splitter("- The 'place Walls'-option will now place walls in water or lava like it was originally supposed to (quite stupid mistake on my part)."), 3, ypos+3, w-3, " ")
  808. Sprint("Patch 2.5.1", 1, ypos+2)
  809. Sprint("-----------", 1, ypos+3)
  810. Sprint("1.NEW FEATURES", 2, ypos+5)
  811. ypos = printWrapped(Splitter("- You can now choose to let the turtle build walls and ceiling to prevent the hallways from being flooded by water or lava."), 3, ypos+6, w-3, " ")
  812. ypos = printWrapped(Splitter("- If torches need to be placed, the turtle will now determine it's cardial direction at the beginning of digging."), 3, ypos+1, w-3, " ")
  813. ypos = printWrapped(Splitter("- Torches will -now for real- be placed under all circumstances (see 'Bug fixes')."), 3, ypos+1, w-3, " ")
  814. Sprint("2.OPTIMIZATIONS", 2, ypos+2)
  815. ypos = printWrapped(Splitter("- When trash-option or chest-option is true, the turtle will now keep 1 Stack of cobblestone to place floor or walls, if selected."), 3, ypos+3, w-3, " ")
  816. ypos = printWrapped(Splitter("- Added the page counter in the bottom left"), 3, ypos+1, w-3, " ")
  817. Sprint("3.Bug fixes", 2, ypos+2)
  818. ypos = printWrapped(Splitter("- There was a 50% chance (turtle heading north or south) that 50% of the torches (either on the right or the left crosstunnel) were lost. That is because torches are by default placed heading west if possible. The turtle will now determine where it is heading and adjust the way it places torches accordingly so that it never loses a single torch."), 3, ypos+3, w-3, " ")
  819. ypos = printWrapped(Splitter("- When in default settings, 'chest' was set to 'none' there would be a slot for a chest anyways."), 3, ypos+1, w-3, " ")
  820. ypos = printWrapped(Splitter("- I missed two instances in my code that would cause a crash when no cobblestone was available. However the probability to hit this crash was soooo low that I'm sure nobody ever encountered it."), 3, ypos+1, w-3, " ")
  821. Sprint("Patch 2.5", 1, ypos+2)
  822. Sprint("---------", 1, ypos+3)
  823. Sprint("1.NEW FEATURES", 2, ypos+5)
  824. ypos = printWrapped(Splitter("- If you are using ComputerCraft Version 1.64 or higher, the turtle won't determine whether to mine a block or not by comparing it to the Ignor-slots but by comparing it with the new Ignor-list, which you can add blocks to. This is not only easier and more flexible but also a lot faster."), 3, ypos+6, w-3, " ")
  825. ypos = printWrapped(Splitter("- If you want to, the turtle will now throw away items contained on the Ignor-list."), 3, ypos+1, w-3, " ")
  826. ypos = printWrapped(Splitter("- The decision whether to empty the inventory into a chest, also takes the length of the lateral tunnel into account now, to prevent the loss of items."), 3, ypos+1, w-3, " ")
  827. ypos = printWrapped(Splitter("- Torches will now be placed immediatly after digging the tunnel and not only after searching through the tunnel, to prevent mobspawns."), 3, ypos+1, w-3, " ")
  828. ypos = printWrapped(Splitter("- Torches will now be placed under all circumstances, even if a block for the torch to hold on to has to be placed."), 3, ypos+1, w-3, " ")
  829. ypos = printWrapped(Splitter("- As soon as torch-slots become free because all its torches have been placed, it changes to an empty slot now, which makes it available for ores."), 3, ypos+1, w-3, " ")
  830. ypos = printWrapped(Splitter("- The program wont throw an error and terminate, when it doesn't have blocks it wants to place, it simply doesn't place them."), 3, ypos+1, w-3, " ")
  831. Sprint("2.OPTIMIZATIONS", 2, ypos+2)
  832. ypos = printWrapped(Splitter("- The turtle will also search right and left at the very first two blocks of the tunnel, just in case you are lazy."), 3, ypos+3, w-3, " ")
  833. ypos = printWrapped(Splitter("- When you decide to use no chest, the chest-slot will now be converted to an empty slot, available as inventory."), 3, ypos+1, w-3, " ")
  834. ypos = printWrapped(Splitter("- The floor will now be placed after digging out ores, so that there will definitly be no holes in the ground."), 3, ypos+1, w-3, " ")
  835. ypos = printWrapped(Splitter("- The inventory will now be cleared after finishing."), 3, ypos+1, w-3, " ")
  836. ypos = printWrapped(Splitter("- Optimized the dig() function to run faster, increasing the overall speed of the program drasticly."), 3, ypos+1, w-3, " ")
  837. Sprint("3.Bug fixes", 2, ypos+2)
  838. ypos = printWrapped(Splitter("- In the main hallway, there was a 25% chance that the block a torch was just placed on gets destroyed a second after, and thereby losing the torch."), 3, ypos+3, w-3, " ")
  839. ypos = printWrapped(Splitter("- In rare cases when selected normal chest, the turtle would try to return to its chest after the program had finished, resulting in the turtle vanishing to Australia."), 3, ypos+1, w-3, " ")
  840. ypos = printWrapped(Splitter("- Asking for fuel and taking that fuel wasn't always sync."), 3, ypos+1, w-3, " ")
  841. ypos = printWrapped(Splitter("- The turtle would sometimes put the coal it needs to fuel itself into the chest."), 3, ypos+1, w-3, " ")
  842. ypos = printWrapped(Splitter("- When a tunnellength <= 4 was chosen the turtle placed way too much torches."), 3, ypos+1, w-3, " ")
  843. ypos = printWrapped(Splitter("- Many variables weren't refreshed after changing some options, messing up the preparation page."), 3, ypos+1, w-3, " ")
  844. ypos = printWrapped(Splitter("- When running out of fuel the turtle would think that it encountered an obstacle, constantly digging and hitting the air in front."), 3, ypos+1, w-3, " ")
  845. Sprint("Patch 2.4", 1, ypos+2)
  846. Sprint("---------", 1, ypos+3)
  847. Sprint("1.NEW FEATURES", 2, ypos+5)
  848. ypos = printWrapped(Splitter("- Option to place a floor, if needed"), 3, ypos+6, w-3, " ")
  849. ypos = printWrapped(Splitter("- Option to change language. Currently available: english, german"), 3, ypos+1, w-3, " ")
  850. ypos = printWrapped(Splitter("- Added a scrollbar to the options page, too"), 3, ypos+1, w-3, " ")
  851. Sprint("2.OPTIMIZATIONS", 2, ypos+2)
  852. ypos = printWrapped(Splitter("- The positions of the Buttons are determined more intelligent now, therefore being evenly spaced on every possible monitor size"), 3, ypos+3, w-3, " ")
  853. ypos = printWrapped(Splitter("- The structure of code is more centralized now, which results in faster processing and less blocked storage"), 3, ypos+1, w-3, " ")
  854. ypos = printWrapped(Splitter("- The Buttons of the options page won't slide up anymore when there is enough space, was a stupid feature anyways..."), 3, ypos+1, w-3, " ")
  855. Sprint("3.Bug fixes", 2, ypos+2)
  856. ypos = printWrapped(Splitter("- When more than 12 stacks torches were needed the ignore slots were overwritten, and wouldn't reset even when the options were changed to need less torches"), 3, ypos+3, w-3, " ")
  857. ypos = printWrapped(Splitter("- Fixed a bug that caused the turtle to claim having found an ore, even though it had not"), 3, ypos+1, w-3, " ")
  858. ypos = printWrapped(Splitter("- Fixed a bug where the turtle would place torches at wrong positions when the options were changed before start"), 3, ypos+1, w-3, " ")
  859. ypos = printWrapped(Splitter("- Everytime after placing a torch the turtle would freeze for a few seconds (related to the bug above), this precious time is being saved now"), 3, ypos+1, w-3, " ")
  860. Sprint("Patch 2.3", 1, ypos+2)
  861. Sprint("---------", 1, ypos+3)
  862. Sprint("1.LAYOUT", 2, ypos+5)
  863. ypos = printWrapped(Splitter("- Popup on execution in case of Errors"), 3, ypos+6, w-3, " ")
  864. ypos = printWrapped(Splitter("- Tiny optical improvement on the scrollbar"), 3, ypos+1, w-3, " ")
  865. Sprint("2.NEW FEATURES", 2, ypos+2)
  866. ypos = printWrapped(Splitter("- Option to make the turtle place the floor when it's missing"), 3, ypos+3, w-3, " ")
  867. ypos = printWrapped(Splitter("- Captions in the startmenu are visible for at least 5 seconds now"), 3, ypos+1, w-3, " ")
  868. Sprint("3.Bug fixes", 2, ypos+2)
  869. ypos = printWrapped(Splitter("- Autofuel would always refuel 5 coal, no matter how much was needed"), 3, ypos+3, w-3, " ")
  870. ypos = printWrapped(Splitter("- Options sometimes couldn't be selected or the layout got ugly"), 3, ypos+1, w-3, " ")
  871. ypos = printWrapped(Splitter("- In the startmenu the displayed amount of necessary torches was wrong"), 3, ypos+1, w-3, " ")
  872. Sprint("Patch 2.2", 1, ypos+2)
  873. Sprint("---------", 1, ypos+3)
  874. Sprint("1.NEW LAYOUT", 2, ypos+5)
  875. ypos = printWrapped(Splitter("- The awesome update window!"), 3, ypos+6, w-3, " ")
  876. ypos = printWrapped(Splitter("-> Anti-Annoying-Checkbox ;)"), 4, ypos+1, w-4, " ")
  877. ypos = printWrapped(Splitter("- This awesome news window!"), 3, ypos+1, w-3, " ")
  878. ypos = printWrapped(Splitter("-> Very functional scrollbar (mouse_wheel, arrow-keys or arrow-buttons can be used)"), 4, ypos+1, w-4, " ")
  879. Sprint("2.NEW FEATURES", 2, ypos+2)
  880. ypos = printWrapped(Splitter("- Favorite options are now savable"), 3, ypos+3, w-3, " ")
  881. ypos = printWrapped(Splitter("- There is a new function that, when activated, places torches automatically: Perfectly spaced so no mobs can spawn!!!"), 3, ypos+1, w-3, " ")
  882. ypos = printWrapped(Splitter("- Torches on the main floor are placed instantly now, to prevent mobs from spawning"), 3, ypos+1, w-3, " ")
  883. Sprint("3.Bug fixes", 2, ypos+2)
  884. ypos = printWrapped(Splitter("- Putting wrong items into a torchslot resulted in a wrong Errormessage"), 3, ypos+3, w-3, " ")
  885. ypos = printWrapped(Splitter("- When normal chest was selected, the program crashed trying to deploy the chest"), 3, ypos+1, w-3, " ")
  886. printLeft(string.rep(" ", w-2), h)
  887. printLeft("Page "..tostring(math.ceil((-menuVars["drawNews"].scroll+1)/10)).."/"..tostring(math.ceil((ypos-menuVars["drawNews"].scroll)/10)-1), h)
  888. printCentered(">Ok<", h)
  889. printLine(w, 3, h, "^", "v")
  890. drawHeader()
  891. end
  892.  
  893. function drawHome(event, p1, p2, p3)
  894. for i = 1, 3 do
  895. printCentered(lang.layout(settings.language, i+8), round((h-5)*(i/4), "u")+i+2)
  896. end
  897. printCentered(string.rep("-", #lang.layout(settings.language, select+8)), round((h-5)*(select/4), "u")+select+3)
  898. end
  899.  
  900. function drawStart(event, p1, p2, p3)
  901. --Fuellevel
  902. MoveObjects(3, 2)
  903. printLeft(lang.layout(settings.language, 12), objects[3])
  904.  
  905. --Torches
  906. local TorchAmount = 0
  907. ErrorSlot = 0
  908. for i = 1, #variables.slots do
  909. if variables.slots[i] == "T" then
  910. if ItemCount("minecraft:torch", i) ~= false then
  911. TorchAmount = TorchAmount + ItemCount("minecraft:torch", i)
  912. else
  913. ErrorSlot = i
  914. end
  915. end
  916. end
  917. if ErrorSlot ~= 0 then
  918. errors[1] = true
  919. else
  920. errors[1] = false
  921. end
  922. if variables.TorchDemand ~= 0 then
  923. MoveObjects(4, 2)
  924. printLeft(lang.layout(settings.language, 14), objects[4])
  925. if TorchAmount < variables.TorchDemand then
  926. Check.torch = false
  927. if Color() then
  928. term.setBackgroundColor(colors.red)
  929. end
  930. else
  931. Check.torch = true
  932. if Color() then
  933. term.setBackgroundColor(colors.lime)
  934. end
  935. end
  936. printRight(TorchAmount.."/"..variables.TorchDemand, objects[4])
  937. if Check.torch == false then
  938. errors[7] = true
  939. else
  940. errors[7] = false
  941. end
  942. term.setBackgroundColor(colors.black)
  943. else
  944. MoveObjects(4, 1)
  945. errors[7] = false
  946. end
  947.  
  948. --Chest
  949. errors[2] = false
  950. errors[3] = false
  951. errors[4] = false
  952. errors[5] = false
  953. errors[6] = false
  954. Check.chest = false
  955. if settings.chestSelect == 1 then
  956. MoveObjects(5, 2)
  957. printLeft(lang.layout(settings.language, 15), objects[5])
  958. if Version < 1.64 then
  959. if turtle.getItemCount(chestSlot) == 0 then
  960. errors[4] = true
  961. else
  962. Check.chest = true
  963. end
  964. else
  965. if ItemCount("minecraft:ender_chest", chestSlot) ~= false and ItemCount("minecraft:ender_chest", chestSlot) > 0 then
  966. errors[2] = true
  967. elseif ItemCount(enderChestList, chestSlot) == false then
  968. errors[3] = true
  969. elseif ItemCount(enderChestList, chestSlot) == 0 then
  970. errors[4] = true
  971. else
  972. Check.chest = true
  973. end
  974. end
  975. elseif settings.chestSelect == 2 then
  976. MoveObjects(5, 2)
  977. printLeft(lang.layout(settings.language, 18), objects[5])
  978. if ItemCount(chestList, chestSlot) == false then
  979. errors[5] = true
  980. elseif ItemCount(chestList, chestSlot) == 0 then
  981. errors[6] = true
  982. else
  983. Check.chest = true
  984. end
  985. else
  986. Check.chest = true
  987. MoveObjects(5, 1)
  988. end
  989. if Check.chest == false then
  990. if Color() then
  991. term.setBackgroundColor(colors.red)
  992. end
  993. printRight(lang.layout(settings.language, 16), objects[5])
  994. else
  995. if Color() then
  996. term.setBackgroundColor(colors.lime)
  997. end
  998. printRight(lang.layout(settings.language, 17), objects[5])
  999. end
  1000. term.setBackgroundColor(colors.black)
  1001.  
  1002. --Autofuel
  1003. if settings.Autofuel == true then
  1004. MoveObjects(6, 2)
  1005. printLeft(lang.layout(settings.language, 19), objects[6])
  1006. term.setBackgroundColor(colors.lime)
  1007. printRight(lang.layout(settings.language, 17), objects[6])
  1008. term.setBackgroundColor(colors.black)
  1009. if help[4] == false then
  1010. help[4] = turtle.getItemCount(AutofuelSlot)
  1011. end
  1012. else
  1013. MoveObjects(6, 1)
  1014. end
  1015.  
  1016. printLeft(string.rep("-", w), objects[7])
  1017.  
  1018. --Inventory
  1019. if Version < 1.64 then
  1020. for i = 1, #variables.slots do
  1021. if variables.slots[i] == "I" then
  1022. variables.slots[i] = "_"
  1023. end
  1024. end
  1025. for i = 1, settings.ignor do
  1026. variables.slots[i] = "I"
  1027. end
  1028. end
  1029. for k, v in ipairs(SlotCalculator("T", "empty")) do
  1030. variables.slots[v] = "_"
  1031. end
  1032. local stupid = SlotCalculator("_", "empty")
  1033. for k, v in ipairs(stupid) do
  1034. if k > #stupid-math.ceil(variables.TorchDemand/64) then
  1035. variables.slots[v] = "T"
  1036. end
  1037. end
  1038. notificationCenter()
  1039. printRight("|"..variables.slots[1].."|"..variables.slots[2].."|"..variables.slots[3].."|"..variables.slots[4].."|", objects[8])
  1040. printRight("|"..variables.slots[5].."|"..variables.slots[6].."|"..variables.slots[7].."|"..variables.slots[8].."|", objects[9])
  1041. printRight("|"..variables.slots[9].."|"..variables.slots[10].."|"..variables.slots[11].."|"..variables.slots[12].."|", objects[10])
  1042. printRight("|"..variables.slots[13].."|"..variables.slots[14].."|"..variables.slots[15].."|"..variables.slots[16].."|", objects[11])
  1043.  
  1044. if objects[11] < 12 then
  1045. printLeft(string.rep("-", w), 12)
  1046. end
  1047.  
  1048. --Buttons
  1049. if select == 1 then
  1050. printB({">"..lang.layout(settings.language, 20).."<", " "..lang.layout(settings.language, 10).." ", " "..lang.layout(settings.language, 21).." "}, objects[13])
  1051. elseif select == 2 then
  1052. printB({" "..lang.layout(settings.language, 20).." ", ">"..lang.layout(settings.language, 10).."<", " "..lang.layout(settings.language, 21).." "}, objects[13])
  1053. elseif select == 3 then
  1054. printB({" "..lang.layout(settings.language, 20).." ", " "..lang.layout(settings.language, 10).." ", ">"..lang.layout(settings.language, 21).."<"}, objects[13])
  1055. end
  1056. end
  1057.  
  1058. function drawOptions(event, p1, p2, p3)
  1059. if menuVars["drawOptions"].focus == 100 then
  1060. calculateFuelDemand()
  1061. TorchCalculator()
  1062. if menuVars["drawOptions"].saved == true and select == 3 then
  1063. select = 2
  1064. end
  1065. end
  1066. if event == "mouse_scroll" then
  1067. if menuVars["drawOptions"].focus == 100 then
  1068. menuVars["drawOptions"].scroll = menuVars["drawOptions"].scroll - p1
  1069. elseif menuVars["drawOptions"].focus == 13+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift and ((p1 < 0 and menuVars["drawOptions"].scroll2 < 0) or (p1 >= 0 and h < menuVars["drawOptions"].ypos)) then
  1070. menuVars["drawOptions"].scroll2 = menuVars["drawOptions"].scroll2 - p1
  1071. end
  1072. elseif event == "mouse_click" and p1 == 1 and menuVars["drawOptions"].focus == 100 then
  1073. if p2 == w then
  1074. if p3 == 3 then
  1075. menuVars["drawOptions"].scroll = menuVars["drawOptions"].scroll + 1
  1076. elseif p3 == h then
  1077. menuVars["drawOptions"].scroll = menuVars["drawOptions"].scroll - 1
  1078. end
  1079. else
  1080. menuVars["drawOptions"].focus = p3
  1081. if menuVars["drawOptions"].focus > 15+menuVars["drawOptions"].shift+menuVars["drawOptions"].shift2 or menuVars["drawOptions"].focus > h-3 or menuVars["drawOptions"].focus < 3 then
  1082. menuVars["drawOptions"].focus = 100
  1083. end
  1084. end
  1085. elseif event == "key" then
  1086. if p1 == 28 and menuVars["drawOptions"].focus ~= 0 then
  1087. menuVars["drawOptions"].saved = false
  1088. menuVars["drawOptions"].focus = 100
  1089. elseif p1 == 208 and menuVars["drawOptions"].focus == 100 then
  1090. menuVars["drawOptions"].scroll = menuVars["drawOptions"].scroll - 1
  1091. elseif p1 == 200 and menuVars["drawOptions"].focus == 100 then
  1092. menuVars["drawOptions"].scroll = menuVars["drawOptions"].scroll + 1
  1093. else
  1094. if settings.torches == false then
  1095. if menuVars["drawOptions"].focus == 8+menuVars["drawOptions"].scroll then
  1096. if p1 == 203 and settings.mainTorches == false then
  1097. settings.mainTorches = true
  1098. elseif p1 == 205 and settings.mainTorches == true then
  1099. settings.mainTorches = false
  1100. end
  1101. end
  1102. end
  1103. menuVars["drawOptions"].shift2 = 0
  1104. if Version >= 1.64 then
  1105. if menuVars["drawOptions"].focus == 14+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1106. if p1 == 203 and settings.trash == false then
  1107. settings.trash = true
  1108. elseif p1 == 205 and settings.trash == true then
  1109. settings.trash = false
  1110. end
  1111. end
  1112. else
  1113. menuVars["drawOptions"].shift2 = menuVars["drawOptions"].shift2-1
  1114. end
  1115. if menuVars["drawOptions"].focus == 3+menuVars["drawOptions"].scroll then
  1116. if p1 == 203 and settings.language == "de" then
  1117. settings.language = "en"
  1118. elseif p1 == 205 and settings.language == "en" then
  1119. settings.language = "de"
  1120. end
  1121. elseif menuVars["drawOptions"].focus == 4+menuVars["drawOptions"].scroll then
  1122. if p1 == 203 and settings.tunnelspace == 4 then
  1123. settings.tunnelspace = 3
  1124. elseif p1 == 205 and settings.tunnelspace == 3 then
  1125. settings.tunnelspace = 4
  1126. end
  1127. elseif menuVars["drawOptions"].focus == 7+menuVars["drawOptions"].scroll then
  1128. if p1 == 203 and settings.chestSelect > 1 then
  1129. settings.chestSelect = settings.chestSelect - 1
  1130. elseif p1 == 205 and settings.chestSelect < #chest then
  1131. settings.chestSelect = settings.chestSelect + 1
  1132. end
  1133. for k, v in ipairs(chest) do
  1134. if k == settings.chestSelect then
  1135. v = true
  1136. else
  1137. v = false
  1138. end
  1139. end
  1140. elseif menuVars["drawOptions"].focus == 8+menuVars["drawOptions"].scroll then
  1141. if p1 == 203 and settings.torches == false then
  1142. settings.torches = true
  1143. elseif p1 == 205 and settings.torches == true then
  1144. settings.torches = false
  1145. end
  1146. elseif menuVars["drawOptions"].focus == 11+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1147. if p1 == 203 and settings.Autofuel == false then
  1148. settings.Autofuel = true
  1149. elseif p1 == 205 and settings.Autofuel == true then
  1150. settings.Autofuel = false
  1151. end
  1152. elseif menuVars["drawOptions"].focus == 12+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1153. if p1 == 203 and settings.floor == false then
  1154. settings.floor = true
  1155. elseif p1 == 205 and settings.floor == true then
  1156. settings.floor = false
  1157. end
  1158. elseif menuVars["drawOptions"].focus == 13+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1159. if p1 == 200 and menuVars["drawOptions"].scroll2 < 0 then
  1160. menuVars["drawOptions"].scroll2 = menuVars["drawOptions"].scroll2+1
  1161. elseif p1 == 208 and h < menuVars["drawOptions"].ypos then
  1162. menuVars["drawOptions"].scroll2 = menuVars["drawOptions"].scroll2-1
  1163. elseif Version >= 1.64 then
  1164. if p1 == 57 or p1 == 14 then
  1165. for i = 1, 16 do
  1166. local data = turtle.getItemDetail(i)
  1167. if data then
  1168. for k, v in ipairs(settings.ignor) do
  1169. if v == data.name then
  1170. table.remove(settings.ignor, k)
  1171. end
  1172. end
  1173. if p1 == 57 then
  1174. table.insert(settings.ignor, data.name)
  1175. end
  1176. end
  1177. end
  1178. end
  1179. end
  1180. elseif menuVars["drawOptions"].focus == 15+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1181. if p1 == 203 and settings.walls == false then
  1182. settings.walls = true
  1183. elseif p1 == 205 and settings.walls == true then
  1184. settings.walls = false
  1185. end
  1186. end
  1187. end
  1188. end
  1189. if menuVars["drawOptions"].scroll > 0 then
  1190. menuVars["drawOptions"].scroll = 0
  1191. elseif menuVars["drawOptions"].scroll < -(5+menuVars["drawOptions"].shift+menuVars["drawOptions"].shift2) then
  1192. menuVars["drawOptions"].scroll = -(5+menuVars["drawOptions"].shift+menuVars["drawOptions"].shift2)
  1193. end
  1194.  
  1195. if settings.torches == false then
  1196. if menuVars["drawOptions"].focus == 9+menuVars["drawOptions"].scroll then
  1197. printLeft(lang.layout(settings.language, 31), menuVars["drawOptions"].focus)
  1198. if settings.mainTorches == true then
  1199. printRight(">"..lang.layout(settings.language, 29).."< "..lang.layout(settings.language, 30).." ", menuVars["drawOptions"].focus)
  1200. else
  1201. printRight(lang.layout(settings.language, 29).." >"..lang.layout(settings.language, 30).."<", menuVars["drawOptions"].focus)
  1202. end
  1203. elseif menuVars["drawOptions"].focus == 10+menuVars["drawOptions"].scroll then
  1204. printLeft(lang.layout(settings.language, 32), menuVars["drawOptions"].focus)
  1205. term.setCursorPos(w-2, menuVars["drawOptions"].focus)
  1206. settings.lateralTorches = tonumber(read())
  1207. term.clear()
  1208. drawHeader()
  1209. return drawOptions("key", 28)
  1210. end
  1211. menuVars["drawOptions"].shift = 0
  1212. else
  1213. menuVars["drawOptions"].shift = -2
  1214. end
  1215. if Version >= 1.64 then
  1216. if menuVars["drawOptions"].focus == 14+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1217. printLeft(lang.layout(settings.language, 39), menuVars["drawOptions"].focus)
  1218. if settings.trash == true then
  1219. printRight(">"..lang.layout(settings.language, 29).."< "..lang.layout(settings.language, 30).." ", menuVars["drawOptions"].focus)
  1220. else
  1221. printRight(lang.layout(settings.language, 29).." >"..lang.layout(settings.language, 30).."<", menuVars["drawOptions"].focus)
  1222. end
  1223. end
  1224. end
  1225. if menuVars["drawOptions"].focus == 3+menuVars["drawOptions"].scroll then
  1226. printLeft(lang.layout(settings.language, 34), menuVars["drawOptions"].focus)
  1227. if settings.language == "en" then
  1228. printRight(">en< de ", menuVars["drawOptions"].focus)
  1229. else
  1230. printRight("en >de<", menuVars["drawOptions"].focus)
  1231. end
  1232. elseif menuVars["drawOptions"].focus == 4+menuVars["drawOptions"].scroll then
  1233. printLeft(lang.layout(settings.language, 22), menuVars["drawOptions"].focus)
  1234. if settings.tunnelspace == 3 then
  1235. printRight(">2< 3 ", menuVars["drawOptions"].focus)
  1236. else
  1237. printRight("2 >3<", menuVars["drawOptions"].focus)
  1238. end
  1239. elseif menuVars["drawOptions"].focus == 5+menuVars["drawOptions"].scroll then
  1240. printLeft(lang.layout(settings.language, 23), menuVars["drawOptions"].focus)
  1241. term.setCursorPos(w-2, menuVars["drawOptions"].focus)
  1242. settings.quantity = tonumber(read())
  1243. term.clear()
  1244. drawHeader()
  1245. return drawOptions("key", 28)
  1246. elseif menuVars["drawOptions"].focus == 6+menuVars["drawOptions"].scroll then
  1247. printLeft(lang.layout(settings.language, 24), menuVars["drawOptions"].focus)
  1248. term.setCursorPos(w-2, menuVars["drawOptions"].focus)
  1249. settings.length = tonumber(read())
  1250. term.clear()
  1251. drawHeader()
  1252. return drawOptions("key", 28)
  1253. elseif menuVars["drawOptions"].focus == 7+menuVars["drawOptions"].scroll then
  1254. printLeft(lang.layout(settings.language, 18), menuVars["drawOptions"].focus)
  1255. variables.slots[16] = "C"
  1256. if settings.chestSelect == 1 then
  1257. printRight(">"..lang.layout(settings.language, 25).."< "..lang.layout(settings.language, 26).." "..lang.layout(settings.language, 27).." ", menuVars["drawOptions"].focus)
  1258. elseif settings.chestSelect == 2 then
  1259. printRight(lang.layout(settings.language, 25).." >"..lang.layout(settings.language, 26).."< "..lang.layout(settings.language, 27).." ", menuVars["drawOptions"].focus)
  1260. else
  1261. printRight(lang.layout(settings.language, 25).." "..lang.layout(settings.language, 26).." >"..lang.layout(settings.language, 27).."<", menuVars["drawOptions"].focus)
  1262. if variables.slots[16] == "C" then
  1263. variables.slots[16] = "_"
  1264. end
  1265. end
  1266. elseif menuVars["drawOptions"].focus == 8+menuVars["drawOptions"].scroll then
  1267. printLeft(lang.layout(settings.language, 28), menuVars["drawOptions"].focus)
  1268. if settings.torches == true then
  1269. printRight(">"..lang.layout(settings.language, 29).."< "..lang.layout(settings.language, 30).." ", menuVars["drawOptions"].focus)
  1270. else
  1271. printRight(" "..lang.layout(settings.language, 29).." >"..lang.layout(settings.language, 30).."<", menuVars["drawOptions"].focus)
  1272. end
  1273. elseif menuVars["drawOptions"].focus == 11+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1274. printLeft(lang.layout(settings.language, 19), menuVars["drawOptions"].focus)
  1275. if settings.Autofuel == true then
  1276. printRight(">"..lang.layout(settings.language, 29).."< "..lang.layout(settings.language, 30).." ", menuVars["drawOptions"].focus)
  1277. else
  1278. printRight(lang.layout(settings.language, 29).." >"..lang.layout(settings.language, 30).."<", menuVars["drawOptions"].focus)
  1279. end
  1280. elseif menuVars["drawOptions"].focus == 12+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1281. printLeft(lang.layout(settings.language, 33), menuVars["drawOptions"].focus)
  1282. if settings.floor == true then
  1283. printRight(">"..lang.layout(settings.language, 29).."< "..lang.layout(settings.language, 30).." ", menuVars["drawOptions"].focus)
  1284. else
  1285. printRight(lang.layout(settings.language, 29).." >"..lang.layout(settings.language, 30).."<", menuVars["drawOptions"].focus)
  1286. end
  1287. elseif menuVars["drawOptions"].focus == 13+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1288. if Version >= 1.64 then
  1289. printLeft(lang.layout(settings.language, 36), 3)
  1290. local ypos = printWrapped(textutils.unserialize(string.gsub(textutils.serialize(settings.ignor), "minecraft:(%a+)", function(q) return q.."," end)), 1, 4, w)
  1291. menuVars["drawOptions"].ypos = printWrapped(Splitter(lang.layout(settings.language, 37, label)), 1, ypos+2+menuVars["drawOptions"].scroll2, w-1)
  1292. for i = 1, ypos+1 do
  1293. printLeft(string.rep(" ", w), i)
  1294. end
  1295. drawHeader()
  1296. printLeft(lang.layout(settings.language, 36), 3)
  1297. printWrapped(textutils.unserialize(string.gsub(textutils.serialize(settings.ignor), "minecraft:(%a+_*%a*)", function(q) return q.."," end)), 1, 4, w)
  1298. printLine(w, ypos+2, h, "^", "v")
  1299. else
  1300. printLeft(lang.layout(settings.language, 38), menuVars["drawOptions"].focus)
  1301. term.setCursorPos(w-2, menuVars["drawOptions"].focus)
  1302. settings.ignor = tonumber(read())
  1303. term.clear()
  1304. drawHeader()
  1305. return drawOptions("key", 28)
  1306. end
  1307. elseif menuVars["drawOptions"].focus == 15+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1308. printLeft(lang.layout(settings.language, 40), menuVars["drawOptions"].focus)
  1309. if settings.walls == true then
  1310. printRight(">"..lang.layout(settings.language, 29).."< "..lang.layout(settings.language, 30).." ", menuVars["drawOptions"].focus)
  1311. else
  1312. printRight(lang.layout(settings.language, 29).." >"..lang.layout(settings.language, 30).."<", menuVars["drawOptions"].focus)
  1313. end
  1314. elseif menuVars["drawOptions"].focus == 100 then
  1315. printLeft(lang.layout(settings.language, 34), 3+menuVars["drawOptions"].scroll)
  1316. printLeft(lang.layout(settings.language, 22), 4+menuVars["drawOptions"].scroll)
  1317. printLeft(lang.layout(settings.language, 23), 5+menuVars["drawOptions"].scroll)
  1318. printLeft(lang.layout(settings.language, 24), 6+menuVars["drawOptions"].scroll)
  1319. printLeft(lang.layout(settings.language, 18), 7+menuVars["drawOptions"].scroll)
  1320. printLeft(lang.layout(settings.language, 28), 8+menuVars["drawOptions"].scroll)
  1321. if settings.torches == false then
  1322. printLeft(lang.layout(settings.language, 31), 9+menuVars["drawOptions"].scroll)
  1323. printLeft(lang.layout(settings.language, 32), 10+menuVars["drawOptions"].scroll)
  1324. end
  1325. printLeft(lang.layout(settings.language, 19), 11+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift)
  1326. printLeft(lang.layout(settings.language, 33), 12+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift)
  1327. printLeft("#"..lang.layout(settings.language, 36), 13+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift)
  1328. printLeft(lang.layout(settings.language, 39), 14+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift)
  1329. printLeft(lang.layout(settings.language, 40), 15+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift)
  1330. printRight(settings.language, 3+menuVars["drawOptions"].scroll, 1)
  1331. printRight(tostring(settings.tunnelspace-1), 4+menuVars["drawOptions"].scroll, 1)
  1332. printRight(tostring(settings.quantity), 5+menuVars["drawOptions"].scroll, 1)
  1333. printRight(tostring(settings.length), 6+menuVars["drawOptions"].scroll, 1)
  1334. printRight(translate(chest[tonumber(settings.chestSelect)], "layout"), 7+menuVars["drawOptions"].scroll, 1)
  1335. printRight(translate(tostring(settings.torches), "layout"), 8+menuVars["drawOptions"].scroll, 1)
  1336. if settings.torches == false then
  1337. printRight(translate(tostring(settings.mainTorches), "layout"), 9+menuVars["drawOptions"].scroll, 1)
  1338. printRight(tostring(settings.lateralTorches), 10+menuVars["drawOptions"].scroll, 1)
  1339. end
  1340. printRight(translate(tostring(settings.Autofuel), "layout"), 11+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift, 1)
  1341. printRight(translate(tostring(settings.floor), "layout"), 12+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift, 1)
  1342. if Version >= 1.64 then
  1343. printRight(tostring(#settings.ignor-4), 13+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift, 1)
  1344. else
  1345. printRight(tostring(settings.ignor), 13+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift, 1)
  1346. end
  1347. printRight(translate(tostring(settings.trash), "layout"), 14+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift, 1)
  1348. printRight(translate(tostring(settings.walls), "layout"), 15+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift, 1)
  1349. printLeft(string.rep(" ", w-1), h)
  1350. printLeft(string.rep(" ", w-1), h-1)
  1351. printLeft(string.rep(" ", w-1), h-2)
  1352. printB({lang.layout(settings.language, 9), lang.layout(settings.language, 21), lang.layout(settings.language, 35)}, 12)
  1353. if select == 1 then
  1354. printB({string.rep("_", #lang.layout(settings.language, 9)), string.rep(" ", #lang.layout(settings.language, 21)), string.rep(" ", #lang.layout(settings.language, 35))}, 13)
  1355. elseif select == 2 then
  1356. printB({string.rep(" ", #lang.layout(settings.language, 9)), string.rep("_", #lang.layout(settings.language, 21)), string.rep(" ", #lang.layout(settings.language, 35))}, 13)
  1357. else
  1358. printB({string.rep(" ", #lang.layout(settings.language, 9)), string.rep(" ", #lang.layout(settings.language, 21)), string.rep("_", #lang.layout(settings.language, 35))}, 13)
  1359. end
  1360. printLine(w, 3, h-2, "^", "v")
  1361. drawHeader()
  1362. end
  1363. end
  1364.  
  1365. function drawResume(time)
  1366. term.setCursorPos(1, 3)
  1367. print("Program will resume in "..tostring(time).." seconds.\n")
  1368. print("Press Enter to stop resuming...")
  1369. end
  1370.  
  1371. menu = {
  1372. ["Update"] = {
  1373. options = {"News", "Home"},
  1374. orientation = "horizontal",
  1375. draw = drawUpdate
  1376. },
  1377. ["News"] = {
  1378. options = {"Home"},
  1379. orientation = "horizontal",
  1380. draw = drawNews
  1381. },
  1382. ["Home"] = {
  1383. options = {"Start", "Options", "Quit"},
  1384. orientation = "vertical",
  1385. draw = drawHome
  1386. },
  1387. ["Start"] = {
  1388. options = {"Go!", "Options", "Home"},
  1389. orientation = "horizontal",
  1390. draw = drawStart
  1391. },
  1392. ["Options"] = {
  1393. options = {"Start", "Home", "Save as default"},
  1394. orientation = "horizontal",
  1395. draw = drawOptions
  1396. },
  1397. ["Popup"] = {
  1398. options = {"Go!", "Start", "Quit"},
  1399. orientation = "horizontal",
  1400. draw = drawPopup
  1401. }
  1402. }
  1403.  
  1404. -----###-----sequences-----###-----
  1405.  
  1406. function Return()
  1407. face(1)
  1408. if #variables.cache == 0 then
  1409. return
  1410. elseif variables.cache[#variables.cache] == 5 then
  1411. insert('FreewayDown()')
  1412. elseif variables.cache[#variables.cache] == 6 then
  1413. insert('FreewayUp()')
  1414. else
  1415. insert('FreewayBack()')
  1416. insert('variables.direction = variables.cache[#variables.cache]')
  1417. end
  1418. insert('face(1)')
  1419. insert('table.remove(variables.cache, #variables.cache)')
  1420. end
  1421.  
  1422. function compare(method, slotNum)
  1423. turtle.select(slotNum)
  1424. if method == "down" then
  1425. return turtle.compareDown()
  1426. elseif method == "up" then
  1427. return turtle.compareUp()
  1428. elseif method == "front" then
  1429. return turtle.compare()
  1430. end
  1431. end
  1432.  
  1433. function CompareDown(walls)
  1434. if Version >= 1.64 then
  1435. local boolean, data = turtle.inspectDown()
  1436. if boolean then
  1437. for k, v in pairs(settings.ignor) do
  1438. if v == data.name then
  1439. return
  1440. end
  1441. end
  1442. else
  1443. return
  1444. end
  1445. elseif turtle.detectDown() then
  1446. for k, v in pairs(SlotCalculator("I")) do
  1447. if compare("down", k) == true then
  1448. return
  1449. end
  1450. end
  1451. else
  1452. return
  1453. end
  1454. insert('variables.searching = true')
  1455. insert('turtle.select(SlotCalculator("_", "empty")[1])')
  1456. insert('digDown()')
  1457. insert('FreewayDown()')
  1458. insert('table.insert(variables.cache, 6)')
  1459. insert('CompareAll("CompareUp()")')
  1460. end
  1461.  
  1462. function CompareUp(walls)
  1463. if Version >= 1.64 then
  1464. local boolean, data = turtle.inspectUp()
  1465. if boolean then
  1466. for k, v in pairs(settings.ignor) do
  1467. if v == data.name then
  1468. return (walls and placeWall("placeUp")) or nil
  1469. end
  1470. end
  1471. else
  1472. return (walls and placeWall("placeUp")) or nil
  1473. end
  1474. elseif turtle.detectUp() then
  1475. for k, v in pairs(SlotCalculator("I")) do
  1476. if compare("up", k) == true then
  1477. return
  1478. end
  1479. end
  1480. else
  1481. return (walls and placeWall("placeUp")) or nil
  1482. end
  1483. insert('variables.searching = true')
  1484. insert('turtle.select(SlotCalculator("_", "empty")[1])')
  1485. insert('digUp()')
  1486. insert('FreewayUp()')
  1487. insert('table.insert(variables.cache, 5)')
  1488. if walls == true then
  1489. insert('placeWall()')
  1490. end
  1491. insert('CompareAll("CompareDown()")')
  1492. end
  1493.  
  1494. function CompareRight(walls)
  1495. Compare(4, walls)
  1496. end
  1497.  
  1498. function CompareBack(walls)
  1499. Compare(3, walls)
  1500. end
  1501.  
  1502. function CompareLeft(walls)
  1503. Compare(2, walls)
  1504. end
  1505.  
  1506. function Compare(facing, walls)
  1507. if facing == nil then
  1508. facing = 1
  1509. elseif type(facing) == "boolean" then
  1510. walls = facing
  1511. facing = 1
  1512. end
  1513. face(facing)
  1514. if Version >= 1.64 then
  1515. local boolean, data = turtle.inspect()
  1516. if boolean then
  1517. for k, v in pairs(settings.ignor) do
  1518. if v == data.name then
  1519. return (walls and placeWall("placeUp")) or nil
  1520. end
  1521. end
  1522. else
  1523. return (walls and placeWall()) or nil
  1524. end
  1525. elseif turtle.detect() then
  1526. for k, v in pairs(SlotCalculator("I")) do
  1527. if compare("front", k) == true then
  1528. return
  1529. end
  1530. end
  1531. else
  1532. return (walls and placeWall()) or nil
  1533. end
  1534. insert('variables.searching = true')
  1535. insert('turtle.select(SlotCalculator("_", "empty")[1])')
  1536. insert('dig()')
  1537. insert('Freeway()')
  1538. insert('table.insert(variables.cache, variables.direction)')
  1539. if walls == true then
  1540. insert('placeWall("placeUp")')
  1541. end
  1542. insert('variables.direction = 1')
  1543. insert('CompareAll("CompareBack()")')
  1544. end
  1545.  
  1546. function CompareAll(...)
  1547. local exceptions = {...}
  1548. local walls
  1549. if type(exceptions[1]) == "boolean" then
  1550. walls = exceptions[1]
  1551. table.remove(exceptions, 1)
  1552. end
  1553. insert('Compare()')
  1554. insert('CompareLeft()')
  1555. insert('CompareBack()')
  1556. insert('CompareRight()')
  1557. insert('CompareUp()')
  1558. insert('CompareDown()')
  1559. insert('Return()')
  1560. local sub = 0
  1561. for j = 2, 8-sub do
  1562. for k, v in ipairs(exceptions) do
  1563. if v == todoList[j] then
  1564. table.remove(todoList, j)
  1565. table.remove(exceptions, k)
  1566. j = j - 1
  1567. sub = sub + 1
  1568. end
  1569. end
  1570. end
  1571. if walls == true then
  1572. for i = 2, 15 do
  1573. if todoList[i] == 'Return()' then
  1574. break
  1575. elseif string.find(todoList[i], 'placeWall(') == nil then
  1576. if string.find(todoList[i], 'Up') ~= nil then
  1577. table.insert(todoList, i+1, 'placeWall("placeUp")')
  1578. elseif string.find(todoList[i], 'Down') == nil then
  1579. table.insert(todoList, i+1, 'placeWall()')
  1580. end
  1581. end
  1582. end
  1583. end
  1584. end
  1585.  
  1586. function trash(keptCobble)
  1587. for k, v in ipairs(SlotCalculator("_")) do
  1588. local data = turtle.getItemDetail(v)
  1589. for k2, v2 in pairs(settings.ignor) do
  1590. if v2 == data.name then
  1591. if not keptCobble and v2 == "minecraft:cobblestone" then
  1592. keptCobble = true
  1593. else
  1594. turtle.select(v)
  1595. turtle.drop()
  1596. end
  1597. end
  1598. end
  1599. end
  1600. end
  1601.  
  1602. function Enderchest(keptCoal, keptCobble)
  1603. if (#SlotCalculator("_") >= #SlotCalculator("_", "empty")-1-math.ceil(settings.length/12) or keptCoal == true) and #SlotCalculator("C", "check") ~= 0 then
  1604. turtle.select(SlotCalculator("C", "check")[1])
  1605. if variables.level == 1 then
  1606. insert('FreewayDown()')
  1607. end
  1608. insert('FreewayBack()')
  1609. insert([[while not turtle.place() do
  1610. turtle.attack()
  1611. end]])
  1612. insert([[for k, v in ipairs(SlotCalculator("_")) do
  1613. if settings.Autofuel and not keptCoal and Version >= 1.64 and turtle.getItemDetail(v).name == "minecraft:coal" then
  1614. keptCoal = true
  1615. elseif not keptCobble and v == "minecraft:cobblestone" then
  1616. keptCobble = true
  1617. else
  1618. turtle.select(v)
  1619. while not turtle.drop() do
  1620. print(lang.status(settings.language, 3))
  1621. sleep(10)
  1622. end
  1623. end
  1624. end
  1625. turtle.select(SlotCalculator("C", "empty")[1])]])
  1626. insert('dig()')
  1627. insert('Freeway()')
  1628. insert([[turtle.select(SlotCalculator("_", "empty")[1])
  1629. print(lang.status(settings.language, 4))]])
  1630. end
  1631. end
  1632.  
  1633. function NormalChest(keptCoal, keptCobble)
  1634. local function goToOrigin()
  1635. insert('turn()')
  1636. insert([[if variables.level == 1 then
  1637. FreewayDown()
  1638. end
  1639. for Way_Back = 1, variables.CrosswayAmount*settings.tunnelspace do
  1640. Freeway()
  1641. end]])
  1642. insert('turn()')
  1643. end
  1644. local function dropOff()
  1645. insert([[for k, v in ipairs(SlotCalculator("_")) do
  1646. if settings.Autofuel and not keptCoal and Version >= 1.64 and turtle.getItemDetail(v).name == "minecraft:coal" then
  1647. keptCoal = true
  1648. elseif not keptCobble and v == "minecraft:cobblestone" then
  1649. keptCobble = true
  1650. else
  1651. turtle.select(v)
  1652. while not turtle.dropDown() and turtle.getItemCount() ~= 0 do
  1653. print(lang.status(settings.language, 3))
  1654. sleep(10)
  1655. end
  1656. end
  1657. end]])
  1658. end
  1659. if variables.setup == true then
  1660. goToOrigin()
  1661. dropOff()
  1662. insert([[for Way_Back = 1, variables.CrosswayAmount*settings.tunnelspace do
  1663. Freeway()
  1664. end]])
  1665. insert('print(lang.status(settings.language, 4))')
  1666. elseif #SlotCalculator("C", "check") == 0 then
  1667. variables.setup = false
  1668. elseif #SlotCalculator("_") >= #SlotCalculator("_", "empty")-1-math.ceil(settings.length/12) then
  1669. goToOrigin()
  1670. insert('turtle.select(SlotCalculator("C", "check")[1])')
  1671. insert([[while not turtle.placeDown() do
  1672. digDown()
  1673. end]])
  1674. insert('variables.setup = true')
  1675. dropOff()
  1676. insert([[for Way_Back = 1, variables.CrosswayAmount*settings.tunnelspace do
  1677. Freeway()
  1678. end]])
  1679. insert('print(lang.status(settings.language, 4))')
  1680. end
  1681. end
  1682.  
  1683. function Fuel()
  1684. local FuelAmount = math.ceil(3*variables.FuelDemand/settings.quantity/80)
  1685. fuelLevel = turtle.getFuelLevel()
  1686. if fuelLevel < 3*variables.FuelDemand/settings.quantity then
  1687. while true do
  1688. while #SlotCalculator("_", "minecraft:coal") > 0 do
  1689. turtle.select(SlotCalculator("_", "minecraft:coal")[1])
  1690. local output = refuel(FuelAmount, true)
  1691. if output == true then
  1692. print(lang.status(settings.language, 5))
  1693. return
  1694. else
  1695. FuelAmount = FuelAmount - output
  1696. end
  1697. end
  1698. term.clear()
  1699. term.setCursorPos(1,1)
  1700. print(lang.status(settings.language, 6))
  1701. write(lang.status(settings.language, 7))
  1702. for k, v in ipairs(SlotCalculator("_", "empty")) do
  1703. if k == #SlotCalculator("_", "empty") then
  1704. print(v)
  1705. else
  1706. write(v..", ")
  1707. end
  1708. end
  1709. os.pullEvent()
  1710. end
  1711. end
  1712. end
  1713.  
  1714. function placeFloor()
  1715. if settings.floor == true and turtle.detectDown() == false and #SlotCalculator("_", "minecraft:cobblestone") ~= 0 then
  1716. turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])
  1717. turtle.placeDown()
  1718. end
  1719. end
  1720.  
  1721. function placeWall(param)
  1722. if param == true then
  1723. param = "place"
  1724. else
  1725. param = param or "place"
  1726. end
  1727. if #SlotCalculator("_", "minecraft:cobblestone") > 0 then
  1728. turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])
  1729. turtle[param]()
  1730. return true
  1731. end
  1732. return false
  1733. end
  1734.  
  1735. -----###-----Processing-----###-----
  1736. function TorchCalculator()
  1737. local Tspace
  1738. if settings.torches == true then
  1739. if (settings.tunnelspace == 4 and settings.length <= 8) or (settings.tunnelspace == 3 and settings.length <= 10) then
  1740. settings.lateralTorches = 1
  1741. else
  1742. settings.lateralTorches = math.floor((settings.length-math.floor(16/settings.tunnelspace))/12)+1
  1743. end
  1744. if (settings.tunnelspace == 4 and settings.length <= 3) or (settings.tunnelspace == 3 and settings.length <= 4) then
  1745. settings.mainTorches = true
  1746. settings.lateralTorches = 0
  1747. elseif (settings.tunnelspace == 4 and ((settings.length+2)%12 <= 5 or settings.length == 9)) or (settings.tunnelspace == 3 and (settings.length+1)%12 <= 5) then
  1748. settings.mainTorches = true
  1749. else
  1750. settings.mainTorches = false
  1751. end
  1752. end
  1753. if settings.lateralTorches >= 1 then
  1754. if settings.mainTorches == true then
  1755. Tspace = round((settings.length+(settings.tunnelspace-1)-settings.lateralTorches)/(settings.lateralTorches+0.5), "u")
  1756. else
  1757. Tspace = (settings.length+(settings.tunnelspace-1)-settings.lateralTorches)/settings.lateralTorches
  1758. end
  1759. if Tspace == 11 then
  1760. variables.maxSpace = true
  1761. else
  1762. variables.maxSpace = false
  1763. end
  1764. local done = false
  1765. while not done do
  1766. variables.torchPositions = {}
  1767. table.insert(variables.torchPositions, round(Tspace/2, "d")+1)
  1768. for i = 2, settings.lateralTorches do
  1769. table.insert(variables.torchPositions, round(Tspace+1+variables.torchPositions[i-1], "d"))
  1770. end
  1771. if variables.torchPositions[#variables.torchPositions] > settings.length then
  1772. Tspace = Tspace - 0.1
  1773. else
  1774. done = true
  1775. end
  1776. end
  1777. else
  1778. variables.maxSpace = false
  1779. variables.torchPositions = {}
  1780. end
  1781. variables.TorchDemand = 2*(settings.lateralTorches*settings.quantity)+1
  1782. if settings.mainTorches == true then
  1783. variables.TorchDemand = variables.TorchDemand + settings.quantity
  1784. end
  1785. for k, v in ipairs(SlotCalculator("T", "empty")) do
  1786. variables.slots[v] = "_"
  1787. end
  1788. local stupid = SlotCalculator("_", "empty")
  1789. for k, v in ipairs(stupid) do
  1790. if k > #stupid-math.ceil(variables.TorchDemand/64) then
  1791. variables.slots[v] = "T"
  1792. end
  1793. end
  1794. end
  1795.  
  1796. function calculateFuelDemand()
  1797. if settings.chestSelect == 1 then
  1798. variables.FuelDemand = ((settings.length*2+settings.tunnelspace)*3+3)*settings.quantity
  1799. elseif settings.chestSelect == 2 then
  1800. variables.FuelDemand = math.ceil(((settings.length*2+settings.tunnelspace)*3+2)*settings.quantity+settings.tunnelspace*(settings.quantity/2)^2)
  1801. else
  1802. variables.FuelDemand = ((settings.length*2+settings.tunnelspace)*3+2)*settings.quantity
  1803. end
  1804. if variables.maxSpace == true then
  1805. variables.FuelDemand = variables.FuelDemand + #variables.torchPositions
  1806. end
  1807. end
  1808.  
  1809.  
  1810. -----###-----Core functions-----###-----
  1811. function update()
  1812. if not fs.exists("database/"..programName.."/state") then
  1813. save("database/"..programName.."/state", "0")
  1814. end
  1815. file = fs.open("database/"..programName.."/state", "r")
  1816. local fileData = {}
  1817. local line = file.readLine()
  1818. repeat
  1819. table.insert(fileData, line)
  1820. line = file.readLine()
  1821. until line == nil
  1822. file.close()
  1823. updated = fileData[1]
  1824.  
  1825. if updated == "0" then
  1826. kill = true
  1827. term.clear()
  1828. print("loading...")
  1829. shell.run("pastebin get cR9vEiTc database/"..programName.."/lang")
  1830. term.clear()
  1831. local function installAsStartup()
  1832. if fs.exists("startup") then
  1833. os.loadAPI("startup")
  1834. if startup.name == "SupHa - Startup Handler by BrunoZockt" then
  1835. for k, v in ipairs(startup.getList()) do
  1836. if v == programName then
  1837. return
  1838. end
  1839. end
  1840. startup.set(programName)
  1841. else
  1842. os.unloadAPI("startup")
  1843. fs.move("startup", "old_startup")
  1844. shell.run("pastebin get 19VG8eD6 startup")
  1845. os.loadAPI("startup")
  1846. startup.set("old_startup", "standart")
  1847. startup.set(programName)
  1848. end
  1849. else
  1850. shell.run("pastebin get 19VG8eD6 startup")
  1851. os.loadAPI("startup")
  1852. startup.set(programName)
  1853. end
  1854. end
  1855. installAsStartup()
  1856. if programName ~= "OCM" then
  1857. fs.delete("database/OCM")
  1858. end
  1859. if shell.run("database/"..programName.."/updaterV2") == false then
  1860. fs.delete("database/"..programName.."/updater")
  1861. term.clear()
  1862. print("loading...")
  1863. shell.run("pastebin get rUMt9siN database/"..programName.."/updaterV2")
  1864. term.clear()
  1865. shell.run("database/"..programName.."/updaterV2")
  1866. end
  1867. end
  1868. end
  1869.  
  1870. function getVariables(path)
  1871. local extSettings = {}
  1872. if fs.exists("database/"..programName.."/"..path) then
  1873. file = fs.open("database/"..programName.."/"..path, "r")
  1874. local line = Splitter(file.readLine(), " = ")
  1875. repeat
  1876. if line[2] == "{" or line[2] == "{}" then
  1877. local str = line[2]
  1878. if line[2] == "{" then
  1879. repeat
  1880. local tline = file.readLine()
  1881. if tline ~= nil then
  1882. str = str..tline
  1883. end
  1884. until tline == "}"
  1885. end
  1886. extSettings[line[1]] = textutils.unserialize(str)
  1887. else
  1888. extSettings[line[1]] = line[2]
  1889. end
  1890. line = Splitter(file.readLine(), " = ")
  1891. until line == nil
  1892. file.close()
  1893. for k, v in pairs(extSettings) do
  1894. if type(extSettings[k]) ~= "table" then
  1895. if not tonumber(extSettings[k]) then
  1896. if extSettings[k] == "true" or extSettings[k] == "false" then
  1897. extSettings[k] = extSettings[k] == "true"
  1898. end
  1899. else
  1900. extSettings[k] = tonumber(extSettings[k])
  1901. end
  1902. end
  1903. if Splitter(path, "/")[#Splitter(path, "/")] == "settings" then
  1904. settings[k] = extSettings[k]
  1905. elseif Splitter(path, "/")[#Splitter(path, "/")] == "variables" then
  1906. variables[k] = extSettings[k]
  1907. end
  1908. end
  1909. end
  1910. if fs.exists("database/"..programName.."/updateCheckbox/V2.6") then
  1911. local file = fs.open("database/"..programName.."/updateCheckbox/V2.6", "r")
  1912. checkbox = file.readLine() == "true"
  1913. file.close()
  1914. end
  1915. if checkbox == true then
  1916. menustate = "Home"
  1917. else
  1918. menustate = "Update"
  1919. end
  1920. if settings.chestSelect < 3 and #SlotCalculator("C", "empty") == 0 then
  1921. variables.slots[16] = "C"
  1922. end
  1923. calculateFuelDemand()
  1924. TorchCalculator()
  1925. end
  1926.  
  1927. function getList(path)
  1928. local file = fs.open("database/"..programName.."/"..path, "r")
  1929. todoList = textutils.unserialize(Splitter(file.readLine(), " = ")[2]..file.readAll())
  1930. file.close()
  1931. end
  1932.  
  1933. function saveVars(path, content)
  1934. save("database/"..programName.."/"..path, content)
  1935. end
  1936.  
  1937. function compStep(n)
  1938. if n == nil then
  1939. n = 1
  1940. else
  1941. n = tonumber(n)
  1942. end
  1943. for i = 1, n do
  1944. insert('turtle.select(SlotCalculator("T", "empty")[1])')
  1945. insert('Freeway()')
  1946. if variables.level == 0 then
  1947. insert('CompareAll("Compare()", "CompareBack()", "CompareUp()")')
  1948. insert('placeFloor()')
  1949. insert('turtle.select(SlotCalculator("T", "empty")[1])')
  1950. insert('FreewayUp()')
  1951. insert('CompareAll("Compare()", "CompareBack()", "CompareDown()")')
  1952. elseif variables.level == 1 then
  1953. insert('CompareAll("Compare()", "CompareBack()", "CompareDown()")')
  1954. insert('turtle.select(SlotCalculator("T", "empty")[1])')
  1955. insert('FreewayDown()')
  1956. insert('CompareAll("Compare()", "CompareBack()", "CompareUp()")')
  1957. insert('placeFloor()')
  1958. end
  1959. end
  1960. end
  1961.  
  1962. function mainstep(n, first)
  1963. if n == nil then
  1964. n = 1
  1965. else
  1966. n = tonumber(n)
  1967. end
  1968. turtle.select(SlotCalculator("_", "empty")[1])
  1969. for i = 1, n do
  1970. insert('variables.searching = false')
  1971. insert('dig()')
  1972. insert('Freeway()')
  1973. insert([[if variables.level == 0 then
  1974. insert('placeFloor()')
  1975. insert('digUp()')
  1976. if ]]..tostring(first)..[[ and ]]..tostring(i)..[[ == 1 or (settings.walls == true and ]]..tostring(i)..[[ == 2 and settings.tunnelspace == 4) then
  1977. insert('CompareAll("Compare()", "CompareBack()", "CompareUp()")')
  1978. else
  1979. insert('CompareDown()')
  1980. end
  1981. insert('FreewayUp()')
  1982. if ]]..tostring(first)..[[ and ]]..tostring(i)..[[ == 1 or (settings.walls == true and ]]..tostring(i)..[[ == 2 and settings.tunnelspace == 4) then
  1983. insert('CompareAll("Compare()", "CompareBack()", "CompareDown()")')
  1984. else
  1985. insert('CompareUp()')
  1986. insert('placeWall("placeUp")')
  1987. end
  1988. elseif variables.level == 1 then
  1989. insert('digDown()')
  1990. if ]]..tostring(first)..[[ and ]]..tostring(i)..[[ == 1 or (settings.walls == true and ]]..tostring(i)..[[ == 2 and settings.tunnelspace == 4) then
  1991. insert('CompareAll("Compare()", "CompareBack()", "CompareDown()")')
  1992. else
  1993. insert('CompareUp()')
  1994. insert('placeWall("placeUp")')
  1995. end
  1996. if i == 2 and settings.mainTorches then
  1997. insert('variables.searching = false')
  1998. insert('dig(true)')
  1999. end
  2000. insert('FreewayDown()')
  2001. if ]]..tostring(first)..[[ and ]]..tostring(i)..[[ == 1 or (settings.walls == true and ]]..tostring(i)..[[ == 2 and settings.tunnelspace == 4) then
  2002. insert('CompareAll("Compare()", "CompareBack()", "CompareUp()")')
  2003. else
  2004. insert('CompareDown()')
  2005. end
  2006. insert('placeFloor()')
  2007. end]])
  2008. if settings.mainTorches == true then
  2009. if i == 2 and #SlotCalculator('T', 'check') ~= 0 then
  2010. insert([[turtle.select(SlotCalculator('T', 'check')[1])
  2011. if variables.level == 1 then
  2012. FreewayDown()
  2013. end]])
  2014. insert([[if not turtle.placeUp() then
  2015. insert('FreewayUp()')
  2016. insert('left()')
  2017. insert('turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])')
  2018. insert('dig()')
  2019. insert('turtle.place()')
  2020. insert('right()')
  2021. insert('FreewayDown()')
  2022. insert('turtle.select(SlotCalculator("T", "check")[1])')
  2023. insert('turtle.placeUp()')
  2024. end]])
  2025. insert([[for k, v in ipairs(SlotCalculator('T', 'empty')) do
  2026. variables.slots[v] = '_'
  2027. end
  2028. local stupid = SlotCalculator('_', 'empty')
  2029. for k, v in ipairs(stupid) do
  2030. if k > #stupid-math.ceil(variables.TorchDemand/64) then
  2031. variables.slots[v] = 'T'
  2032. end
  2033. end
  2034. variables.TorchDemand = variables.TorchDemand - 1]])
  2035. end
  2036. end
  2037. end
  2038. end
  2039.  
  2040. function stepAside(n)
  2041. if n == nil then
  2042. n = 1
  2043. else
  2044. n = tonumber(n)
  2045. end
  2046. for i = 1, n do
  2047. insert('variables.searching = false')
  2048. insert('dig()')
  2049. insert('Freeway()')
  2050. if variables.level == 1 then
  2051. insert('digDown()')
  2052. elseif variables.level == 0 then
  2053. insert('placeFloor()')
  2054. insert('digUp()')
  2055. end
  2056. end
  2057. end
  2058.  
  2059. function youJustGotLittUp(steps, func, left)
  2060. if left == nil then
  2061. left = false
  2062. end
  2063. for Steprepeat = 1, steps do
  2064. if func == stepAside then
  2065. insert('stepAside()')
  2066. end
  2067. for k, v in ipairs(variables.torchPositions) do
  2068. if ((func == stepAside and settings.length-v+1 == Steprepeat) or (func == compStep and v == Steprepeat)) and #SlotCalculator("T", "check") > 0 then
  2069. insert([[turtle.select(SlotCalculator("T", "check")[1])
  2070. if variables.maxSpace == true then
  2071. if settings.mainTorches == false and left == true then
  2072. if k%2 == #variables.torchPositions%2 then
  2073. if variables.level == 1 then
  2074. if variables.orientation[1] == "North" or variables.orientation[1] == "South" then
  2075. insert('dig()')
  2076. end
  2077. insert('FreewayDown()')
  2078. elseif variables.orientation[1] == "North" or variables.orientation[1] == "South" then
  2079. insert('FreewayUp()')
  2080. insert('dig()')
  2081. insert('FreewayDown()')
  2082. end
  2083. else
  2084. if variables.level == 0 then
  2085. insert('FreewayUp()')
  2086. end
  2087. end
  2088. else
  2089. if k%2 == #variables.torchPositions%2 then
  2090. if variables.level == 0 then
  2091. insert('FreewayUp()')
  2092. end
  2093. else
  2094. if variables.level == 1 then
  2095. if variables.orientation[1] == "North" or variables.orientation[1] == "South" then
  2096. insert('dig()')
  2097. end
  2098. insert('FreewayDown()')
  2099. elseif variables.orientation[1] == "North" or variables.orientation[1] == "South" then
  2100. insert('FreewayDown()')
  2101. insert('dig()')
  2102. insert('FreewayUp()')
  2103. end
  2104. end
  2105. end
  2106. elseif variables.orientation[1] == "North" or variables.orientation[1] == "South" then
  2107. if variables.level == 0 then
  2108. insert('FreewayUp()')
  2109. end
  2110. end]])
  2111. insert([[if variables.level == 1 then
  2112. turtle.placeDown()
  2113. elseif variables.level == 0 then
  2114. if not turtle.placeUp() then
  2115. insert('FreewayUp()')
  2116. insert('left()')
  2117. insert('turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])')
  2118. insert('dig()')
  2119. insert('turtle.place()')
  2120. insert('right()')
  2121. insert('FreewayDown()')
  2122. insert('turtle.select(SlotCalculator("T", "check")[1])')
  2123. insert('turtle.placeUp()')
  2124. end
  2125. end]])
  2126. insert([[for k, v in ipairs(SlotCalculator("T", "empty")) do
  2127. variables.slots[v] = "_"
  2128. end
  2129. local stupid = SlotCalculator("_", "empty")
  2130. for k, v in ipairs(stupid) do
  2131. if k > #stupid-math.ceil(variables.TorchDemand/64) then
  2132. variables.slots[v] = "T"
  2133. end
  2134. end]])
  2135. insert([[if func == compStep then
  2136. variables.TorchDemand = variables.TorchDemand - 1
  2137. end
  2138. turtle.select(SlotCalculator("_", "empty")[1])]])
  2139. end
  2140. end
  2141. if func == compStep then
  2142. if Steprepeat == settings.length then
  2143. insert('Freeway()')
  2144. else
  2145. insert('compStep()')
  2146. end
  2147. end
  2148. end
  2149. end
  2150.  
  2151. function tunnel(first)
  2152. if settings.Autofuel == true then
  2153. insert('Fuel()')
  2154. end
  2155. if settings.trash == true then
  2156. insert('trash()')
  2157. end
  2158. if settings.chestSelect == 1 then
  2159. insert('Enderchest()')
  2160. elseif settings.chestSelect == 2 then
  2161. insert('NormalChest()')
  2162. end
  2163. insert("mainstep(settings.tunnelspace, "..tostring(first)..")")
  2164. insert("turtle.turnRight()")
  2165. insert('old_orientation = {}')
  2166. insert([[for k,v in ipairs(variables.orientation) do
  2167. old_orientation[k] = v
  2168. end]])
  2169. for i = 1, 4 do
  2170. insert('variables.orientation['..tostring(i)..'] = old_orientation[('..tostring(i)..'+2)%4+1]')
  2171. end
  2172. insert("youJustGotLittUp(settings.length, stepAside)")
  2173. insert([[if variables.level == 1 then
  2174. insert('CompareAll("CompareBack()", "CompareDown()")')
  2175. insert('FreewayDown()')
  2176. insert('CompareAll("CompareBack()", "CompareUp()")')
  2177. else
  2178. insert('CompareAll("CompareBack()", "CompareUp()")')
  2179. insert('FreewayUp()')
  2180. insert('CompareAll("CompareBack()", "CompareDown()")')
  2181. end]])
  2182. insert('face(3)')
  2183. insert('old_orientation = {}')
  2184. insert([[for k,v in ipairs(variables.orientation) do
  2185. old_orientation[k] = v
  2186. end]])
  2187. for i = 1, 4 do
  2188. insert('variables.orientation['..tostring(i)..'] = old_orientation[('..tostring(i)..'+1)%4+1]')
  2189. end
  2190. insert('variables.direction = 1')
  2191. insert("youJustGotLittUp(settings.length, compStep)")
  2192. insert("youJustGotLittUp(settings.length, stepAside, true)")
  2193. insert([[if variables.level == 1 then
  2194. insert('CompareAll("CompareBack()", "CompareDown()")')
  2195. insert('FreewayDown()')
  2196. insert('CompareAll("CompareBack()", "CompareUp()")')
  2197. else
  2198. insert('CompareAll("CompareBack()", "CompareUp()")')
  2199. insert('FreewayUp()')
  2200. insert('CompareAll("CompareBack()", "CompareDown()")')
  2201. end]])
  2202. insert('face(3)')
  2203. insert('old_orientation = {}')
  2204. insert([[for k,v in ipairs(variables.orientation) do
  2205. old_orientation[k] = v
  2206. end]])
  2207. for i = 1, 4 do
  2208. insert('variables.orientation['..tostring(i)..'] = old_orientation[('..tostring(i)..'+1)%4+1]')
  2209. end
  2210. insert('variables.direction = 1')
  2211. insert("youJustGotLittUp(settings.length, compStep, true)")
  2212. insert('turtle.turnLeft()')
  2213. insert('old_orientation = {}')
  2214. insert([[for k,v in ipairs(variables.orientation) do
  2215. old_orientation[k] = v
  2216. end]])
  2217. for i = 1, 4 do
  2218. insert('variables.orientation['..tostring(i)..'] = old_orientation[('..tostring(i)..')%4+1]')
  2219. end
  2220. end
  2221.  
  2222. function go()
  2223. saveVars("resume/settings", settings)
  2224. variables.startDay = os.day()
  2225. variables.startTime = os.time()
  2226. for Tunnelrepeat = 1, settings.quantity do
  2227. insert("tunnel("..tostring(Tunnelrepeat == 1)..")")
  2228. insert([[variables.CrosswayAmount = variables.CrosswayAmount + 1
  2229. print(lang.status(settings.language, 8, variables.CrosswayAmount, settings.quantity))]])
  2230. end
  2231. insert('print(lang.status(settings.language, 9))')
  2232. insert('turn()')
  2233. insert([[if variables.level == 1 then
  2234. FreewayDown()
  2235. end]])
  2236. for Way_Back = 1, settings.quantity*settings.tunnelspace do
  2237. insert('Freeway()')
  2238. end
  2239. if settings.trash == true then
  2240. insert('trash()')
  2241. end
  2242. if settings.chestSelect == 1 then
  2243. insert("Enderchest(true)")
  2244. elseif settings.chestSelect == 2 then
  2245. insert("NormalChest(true, true)")
  2246. end
  2247. insert([[local endDay = os.day()
  2248. local endTime = os.time()
  2249. variables.stats["time"] = (endDay-variables.startDay)*24.000+(endTime-variables.startTime)]])
  2250. end
  2251.  
  2252. function Navigation()
  2253. table.insert(timer, os.startTimer(0.05))
  2254. while true do
  2255. local tempState = menustate
  2256. local event, p1, p2, p3 = os.pullEvent()
  2257. while (event == "timer" and p1 ~= timer[#timer]) or event == "key_up" do
  2258. event, p1, p2, p3 = os.pullEvent()
  2259. end
  2260. if menuVars["drawOptions"].focus == 100 then
  2261. basicInputHandler(menu[menustate].orientation, event, p1)
  2262. end
  2263. if menustate == "Quit" then
  2264. break
  2265. elseif menustate == "Save as default" then
  2266. saveVars("settings", settings)
  2267. menuVars["drawOptions"].saved = true
  2268. menustate = "Options"
  2269. elseif menustate == "Go!" then
  2270. menustate = "Popup"
  2271. local ready = true
  2272. for i = 1, #errors do
  2273. if errors[i] == true then
  2274. ready = false
  2275. end
  2276. end
  2277. if (Fuellevel ~= "low" and ready == true) or tempState == "Popup" then
  2278. return execute()
  2279. end
  2280. end
  2281. term.clear()
  2282. drawHeader()
  2283. if tempState == menustate then
  2284. menu[menustate].draw(event, p1, p2, p3)
  2285. else
  2286. menu[menustate].draw()
  2287. end
  2288. if tempState == "Update" then
  2289. save("database/"..programName.."/updateCheckbox/V2.6", checkbox)
  2290. end
  2291. table.insert(timer, os.startTimer(0.5))
  2292. end
  2293. end
  2294.  
  2295. function extractstats()
  2296. save("database/"..programName.."/variables.stats", variables.stats)
  2297. end
  2298.  
  2299. function close()
  2300. fs.delete("database/"..programName.."/resume")
  2301. term.clear()
  2302. term.setCursorPos(1,1)
  2303. if Color() then
  2304. term.setTextColor(colors.yellow)
  2305. print(os.version())
  2306. term.setTextColor(colors.white)
  2307. else
  2308. print(os.version())
  2309. end
  2310. term.setCursorPos(1, 2)
  2311. end
  2312.  
  2313. -----###-----Executive-----###------
  2314.  
  2315. local function compile(chunk) -- returns compiled chunk or nil and error message
  2316. if type(chunk) ~= "string" then
  2317. error("expected string, got ".. type(chunk), 2)
  2318. end
  2319.  
  2320. local function findChunkName(var)
  2321. for k,v in pairs(HOST_ENV) do
  2322. if v==var then
  2323. return k
  2324. end
  2325. end
  2326. return "Unknown chunk"
  2327. end
  2328.  
  2329. return load(chunk, findChunkName(chunk), "t", OUR_ENV)
  2330. end
  2331.  
  2332. function getOrientation(resume)
  2333. if resume then
  2334. for i = 1, 2-variables.level do
  2335. insert('FreewayUp()')
  2336. end
  2337. end
  2338. if #SlotCalculator("T", "check") ~= 0 then
  2339. insert('Freeway()')
  2340. if Version >= 1.64 then
  2341. insert('FreewayUp()')
  2342. for i = 1, 3 do
  2343. insert('right()')
  2344. insert('dig(true)')
  2345. end
  2346. insert('right()')
  2347. insert([[if turtle.detect() == false then
  2348. turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])
  2349. turtle.place()
  2350. end]])
  2351. insert('FreewayDown()')
  2352. insert('turtle.select(SlotCalculator("T", "check")[1])')
  2353. insert('turtle.placeUp()')
  2354.  
  2355. insert('torch = {"West", "East", "North", "South"}')
  2356. insert('_, data = turtle.inspectUp()')
  2357. insert('new_orientation = torch[data.metadata]')
  2358.  
  2359. insert('digUp()')
  2360. insert('FreewayBack()')
  2361. insert('_, data, torch = nil, nil, nil')
  2362. else
  2363. insert('Freeway()')
  2364. insert('digDown()')
  2365. insert('FreewayUp()')
  2366. for i = 1, 4 do
  2367. insert([[if turtle.detect() == false then
  2368. turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])
  2369. turtle.place()
  2370. end]])
  2371. insert('right()')
  2372. end
  2373. insert('FreewayDown()')
  2374. insert('turtle.select(SlotCalculator("T", "check")[1])')
  2375. insert('turtle.placeUp()')
  2376.  
  2377. insert('torch = {"West", "South", "East", "North"}')
  2378. for i = 1, 4 do
  2379. insert('Freeway()')
  2380. insert('digUp()')
  2381. insert('os.sleep(0.5)')
  2382. insert('FreewayBack()')
  2383. insert([[if turtle.detectUp() == false then
  2384. i = ]]..tostring(i)..[[
  2385. insert('turtle.select(SlotCalculator("T", "check")[1])')
  2386. insert('turtle.suckDown()')
  2387. insert('new_orientation = torch[i]')
  2388. insert('i = nil')
  2389. end]])
  2390. insert('turtle.turnLeft()')
  2391. end
  2392. insert('face(variables.direction)')
  2393. insert('FreewayBack()')
  2394. end
  2395. end
  2396. if resume then
  2397. for i = 1, 2-variables.level do
  2398. insert('FreewayDown()')
  2399. end
  2400. insert([[for k, v in pairs(cardinal) do
  2401. if v == new_orientation then
  2402. new_orientation = k
  2403. end
  2404. if v == variables.orientation[variables.direction] then
  2405. variables.orientation[variables.direction] = k
  2406. end
  2407. end]])
  2408. insert([[if new_orientation ~= variables.orientation[variables.direction] then
  2409. if math.abs(new_orientation-variables.orientation[variables.direction]) == 2 then
  2410. insert('turtle.turnLeft()')
  2411. insert('turtle.turnLeft()')
  2412. elseif (new_orientation-variables.orientation[variables.direction]+1)%4 == 0 then
  2413. insert('turtle.turnLeft()')
  2414. elseif (new_orientation-variables.orientation[variables.direction]-1)%4 == 0 then
  2415. insert('turtle.turnRight()')
  2416. end
  2417. end]])
  2418. insert('variables.orientation[variables.direction] = cardinal[variables.orientation[variables.direction]]')
  2419. else
  2420. insert([[for k, v in ipairs(cardinal) do
  2421. if new_orientation == v then
  2422. for i = 1, 4 do
  2423. table.insert(variables.orientation, cardinal[(k+i-2)%4+1])
  2424. end
  2425. end
  2426. end]])
  2427. end
  2428. end
  2429.  
  2430. function execute(resume)
  2431. if not resume then
  2432. todoList = {"go()"}
  2433. end
  2434. table.insert(todoList, 1, 'getOrientation('..tostring(resume)..')')
  2435. while #todoList > 0 do
  2436. compile(todoList[1])()
  2437. table.remove(todoList, 1)
  2438. variables.index = 2
  2439. save("database/"..programName.."/resume/todoList", todoList, true)
  2440. saveVars("resume/variables", variables)
  2441. end
  2442. end
  2443.  
  2444. function main()
  2445. if fs.exists("database/"..programName.."/resume") then
  2446. os.loadAPI("database/"..programName.."/lang")
  2447. local countdown = 10
  2448. local count = {}
  2449. term.clear()
  2450. drawResume(countdown)
  2451. table.insert(count, os.startTimer(1))
  2452. repeat
  2453. local event, p1 = os.pullEvent()
  2454. while (event == "timer" and p1 ~= count[#count]) do
  2455. event, p1 = os.pullEvent()
  2456. end
  2457. if event == "key" then
  2458. if p1 == 28 then
  2459. fs.delete("database/"..programName.."/resume")
  2460. return main()
  2461. end
  2462. elseif event == "timer" and p1 == count[#count] then
  2463. countdown = countdown - 1
  2464. end
  2465. term.clear()
  2466. drawResume(countdown)
  2467. table.insert(count, os.startTimer(1))
  2468. until countdown == 0
  2469. getVariables("resume/settings")
  2470. getVariables("resume/variables")
  2471. getList("resume/todoList")
  2472. execute(true)
  2473. else
  2474. update()
  2475. if kill == true then
  2476. return
  2477. end
  2478. save("database/"..programName.."/state", "0")
  2479. os.loadAPI("database/"..programName.."/lang")
  2480. getVariables("settings")
  2481. Navigation()
  2482. end
  2483. --extractstats()
  2484. close()
  2485. end
  2486.  
  2487. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement