Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 92.82 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"] = true,
  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 = turtle.getFuelLevel()
  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. table.insert(todoList, variables.index, 'print("executed instruction: '..code..'"')
  483. variables.index = variables.index + 1
  484. save("database/OCM/resume/todoList", todoList, true)
  485. end
  486.  
  487. -----###-----improved functions-----###-----
  488.  
  489. function dig(gravel)
  490. local a = false
  491. insert('OreCounter()')
  492. variables.stats["dug"] = variables.stats["dug"] + 1
  493. if gravel then
  494. while turtle.dig() do
  495. os.sleep(0.05)
  496. a = true
  497. end
  498. return a
  499. else
  500. return turtle.dig()
  501. end
  502. end
  503.  
  504. function digUp()
  505. insert('OreCounter()')
  506. variables.stats["dug"] = variables.stats["dug"] + 1
  507. return turtle.digUp()
  508. end
  509.  
  510. function digDown()
  511. insert('OreCounter()')
  512. variables.stats["dug"] = variables.stats["dug"] + 1
  513. return turtle.digDown()
  514. end
  515.  
  516. function face(int)
  517. if int == variables.direction then
  518. return
  519. elseif (int + variables.direction)%2 == 0 then
  520. return turn()
  521. elseif math.abs(int - variables.direction) == 1 then
  522. if variables.direction < int then
  523. return left()
  524. else
  525. return right()
  526. end
  527. else
  528. if variables.direction < int then
  529. return right()
  530. else
  531. return left()
  532. end
  533. end
  534. end
  535.  
  536. function right()
  537. turtle.turnRight()
  538. variables.direction = variables.direction - 1
  539. if variables.direction == 0 then
  540. variables.direction = 4
  541. end
  542. end
  543.  
  544. function left()
  545. turtle.turnLeft()
  546. variables.direction = variables.direction + 1
  547. if variables.direction == 5 then
  548. variables.direction = 1
  549. end
  550. end
  551.  
  552. function turn()
  553. left()
  554. left()
  555. end
  556.  
  557. function Freeway()
  558. variables.searching = false
  559. insert([[while not turtle.forward() do
  560. if turtle.getFuelLevel() == 0 then
  561. Fuel()
  562. elseif dig() == false then
  563. turtle.attack()
  564. end
  565. end]])
  566. variables.stats["moves"] = variables.stats["moves"] + 1
  567. end
  568.  
  569. function FreewayUp()
  570. variables.searching = false
  571. insert("variables.level = variables.level + 1")
  572. insert([[while not turtle.up() do
  573. if turtle.getFuelLevel() == 0 then
  574. Fuel()
  575. elseif digUp() == false then
  576. turtle.attackUp()
  577. end
  578. end]])
  579. variables.stats['moves'] = variables.stats['moves'] + 1
  580. end
  581.  
  582. function FreewayDown()
  583. variables.searching = false
  584. insert("variables.level = variables.level - 1")
  585. insert([[while not turtle.down() do
  586. if turtle.getFuelLevel() == 0 then
  587. Fuel()
  588. elseif digDown() == false then
  589. turtle.attackDown()
  590. end
  591. end]])
  592. variables.stats['moves'] = variables.stats['moves'] + 1
  593. end
  594.  
  595. function FreewayBack()
  596. variables.searching = false
  597. while not turtle.back() do
  598. if turtle.getFuelLevel() == 0 then
  599. Fuel()
  600. else
  601. turn()
  602. insert([[if dig() == false then
  603. for i = 1, 20 do
  604. turtle.attack()
  605. os.sleep(0.05)
  606. end
  607. end]])
  608. turn()
  609. end
  610. end
  611. variables.stats["moves"] = variables.stats["moves"] + 1
  612. end
  613.  
  614.  
  615. -----###-----drawMenus-----###-----
  616.  
  617. function notificationCenter()
  618. local advice = {
  619. lang.adv(settings.language, 1, ErrorSlot),
  620. lang.adv(settings.language, 2, 1),
  621. lang.adv(settings.language, 3, chestSlot),
  622. lang.adv(settings.language, 4, chestSlot),
  623. lang.adv(settings.language, 5, chestSlot),
  624. lang.adv(settings.language, 6, chestSlot),
  625. lang.adv(settings.language, 7, 1),
  626. lang.adv(settings.language, 8, 1)
  627. }
  628. if menuVars["notificationCenter"].time > 5 then
  629. for i = 1, #errors do
  630. if errors[i] ~= false then
  631. printWrapped(Splitter(advice[i], " "), 1, objects[8], w - 10)
  632. return
  633. end
  634. end
  635. end
  636. for i = 1, 4 do
  637. printLeft(lang.layout(settings.language, i), objects[i+7])
  638. end
  639. menuVars["notificationCenter"].time = menuVars["notificationCenter"].time + 0.5
  640. end
  641.  
  642. function drawPopup(event, p1, p2, p3)
  643. local errorMessages = {
  644. lang.popup(settings.language, 1, ErrorSlot),
  645. lang.popup(settings.language, 2),
  646. lang.popup(settings.language, 1, chestSlot),
  647. lang.popup(settings.language, 3),
  648. lang.popup(settings.language, 1, chestSlot),
  649. lang.popup(settings.language, 4),
  650. lang.popup(settings.language, 5),
  651. lang.popup(settings.language, 6)
  652. }
  653. local leftBorder = round(w/9, "u")
  654. local rightBorder = round(w+1-w/9, "u")
  655. local winWidth = rightBorder-leftBorder-1
  656.  
  657. menuVars["drawPopup"].lastscroll = menuVars["drawPopup"].scroll
  658.  
  659. if event == "mouse_scroll" then
  660. menuVars["drawPopup"].scroll = menuVars["drawPopup"].scroll - p1
  661. elseif event == "mouse_click" and p1 == 1 then
  662. if p2 == leftBorder+winWidth then
  663. if p3 == 6 then
  664. menuVars["drawPopup"].scroll = menuVars["drawPopup"].scroll + 1
  665. elseif p3 == h-3 then
  666. menuVars["drawPopup"].scroll = menuVars["drawPopup"].scroll - 1
  667. end
  668. end
  669. elseif event == "key" then
  670. if p1 == 208 then
  671. menuVars["drawPopup"].scroll = menuVars["drawPopup"].scroll - 1
  672. elseif p1 == 200 then
  673. menuVars["drawPopup"].scroll = menuVars["drawPopup"].scroll + 1
  674. end
  675. end
  676. if menuVars["drawPopup"].scroll < -(menuVars["drawPopup"].ypos-menuVars["drawPopup"].lastscroll-(math.ceil((h-6)/10)+6)) then
  677. menuVars["drawPopup"].scroll = -(menuVars["drawPopup"].ypos-menuVars["drawPopup"].lastscroll-(math.ceil((h-6)/10)+6))
  678. elseif menuVars["drawPopup"].scroll > 0 then
  679. menuVars["drawPopup"].scroll = 0
  680. end
  681.  
  682. printLine(leftBorder, 4, h-1, "+")
  683. printLine(rightBorder, 4, h-1, "+")
  684. menuVars["drawPopup"].ypos = math.ceil((h-6)/10)+5+menuVars["drawPopup"].scroll
  685. for i = 1, #errors do
  686. if errors[i] == true then
  687. menuVars["drawPopup"].ypos = printWrapped(Splitter("- "..errorMessages[i]), leftBorder+1, menuVars["drawPopup"].ypos+1, winWidth, " ")
  688. end
  689. end
  690. printCentered(string.rep("-", winWidth), 4)
  691. printCentered(string.rep("-", winWidth), h-1)
  692. printCentered(string.rep(" ", winWidth), 5)
  693. printCentered(string.rep(" ", winWidth), 6)
  694. printWrapped(Splitter(lang.popup(settings.language, 7, label)), leftBorder+1, math.ceil((h-6)/10)+4, winWidth, " ")
  695. printCentered(string.rep(" ", winWidth), h-3)
  696. printCentered(string.rep(" ", winWidth), 3)
  697. drawHeader()
  698. printLine(rightBorder-1, 6, h-3, "^", "v")
  699. if select == 1 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. elseif select == 2 then
  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. else
  704. 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)
  705. end
  706. end
  707.  
  708. function drawHeader()
  709. printCentered("ORE SEARCHING STRIP MINER by BrunoZockt", 1)
  710. printLeft(string.rep("-", w), 2)
  711. end
  712.  
  713. function drawUpdate(event, p1, p2, p3)
  714. local leftBorder = round(w/6, "u")
  715. local rightBorder = round(w/6*5, "u")
  716. local winWidth = rightBorder-leftBorder-1
  717. local space = round(winWidth-13, "u")
  718. if event == "mouse_click" and p1 == 1 then
  719. if p2 == leftBorder+3 and p3 == math.ceil((h-6)/2)+5 then
  720. checkbox = not checkbox
  721. elseif p3 == math.ceil((h-6)/10*9)+4 then
  722. if p2 >= leftBorder+round(0.25*space, "u")+1 and p2 <= leftBorder+round(0.25*space, "u")+11 then
  723. if select == 1 then
  724. menustate = menu[menustate].options[select]
  725. else
  726. select = 1
  727. end
  728. elseif leftBorder+round(0.75*space, "u")+12 <= p2 and p2 <= leftBorder+round(0.75*space, "u")+13 then
  729. if select == 2 then
  730. menustate = menu[menustate].options[select]
  731. else
  732. select = 2
  733. end
  734. end
  735. end
  736. elseif event == "key" then
  737. if p1 == 203 and select > 1 then
  738. select = select - 1
  739. elseif p1 == 205 and select < #menu[menustate].options then
  740. select = select + 1
  741. elseif p1 == 28 then
  742. menustate = menu[menustate].options[select]
  743. end
  744. end
  745. printCentered(lang.layout(settings.language, 5), math.ceil((h-6)/6.9)+4)
  746. printCentered(string.rep("-", math.floor(w/3*2)), 4)
  747. printCentered(string.rep("-", math.floor(w/3*2)), 12)
  748. printLine(leftBorder, 4, 12, "+")
  749. printLine(rightBorder, 4, 12, "+")
  750. Sprint("_", leftBorder+3, math.ceil((h-6)/2)+4)
  751. Sprint("|_|"..lang.layout(settings.language, 6), leftBorder+2, math.ceil((h-6)/2)+5)
  752. if select == 1 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. elseif select == 2 then
  755. printB({" "..lang.layout(settings.language, 7).." ", ">"..lang.layout(settings.language, 8).."<"}, math.ceil((h-6)/10*9)+4, rightBorder-1, leftBorder+1)
  756. end
  757. if checkbox == true then
  758. Sprint("X", leftBorder+3, math.ceil((h-6)/2)+5)
  759. end
  760. end
  761.  
  762. function drawNews(event, p1, p2, p3)
  763. if event == "mouse_scroll" then
  764. menuVars["drawNews"].scroll = menuVars["drawNews"].scroll - p1
  765. elseif event == "key" then
  766. if p1 == 28 then
  767. menustate = menu[menustate].options[select]
  768. select = 1
  769. menuVars["drawNews"].scroll = 0
  770. elseif p1 == 208 then
  771. menuVars["drawNews"].scroll = menuVars["drawNews"].scroll - 1
  772. elseif p1 == 200 then
  773. menuVars["drawNews"].scroll = menuVars["drawNews"].scroll + 1
  774. end
  775. elseif event == "mouse_click" then
  776. if p1 == 1 then
  777. if p2 == w then
  778. if p3 == 3 then
  779. menuVars["drawNews"].scroll = menuVars["drawNews"].scroll + 1
  780. elseif p3 == h then
  781. menuVars["drawNews"].scroll = menuVars["drawNews"].scroll - 1
  782. end
  783. elseif p2 >= w/2-2 and p2 <= w/2+2 and p3 == h then
  784. menustate = menu[menustate].options[select]
  785. select = 1
  786. menuVars["drawNews"].scroll = 0
  787. end
  788. end
  789. end
  790. if menuVars["drawNews"].scroll > 0 then
  791. menuVars["drawNews"].scroll = 0
  792. elseif menuVars["drawNews"].scroll < -283 then
  793. menuVars["drawNews"].scroll = -283
  794. end
  795. Sprint("Patch 2.6", 1, 3+menuVars["drawNews"].scroll)
  796. Sprint("-----------", 1, 4+menuVars["drawNews"].scroll)
  797. Sprint("1.NEW FEATURES", 2, 6+menuVars["drawNews"].scroll)
  798. local ypos = printWrapped(Splitter("- The program will now continue automatically after a server restart."), 3, 7+menuVars["drawNews"].scroll, w-3, " ")
  799. 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, " ")
  800. 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, " ")
  801. 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, " ")
  802. 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, " ")
  803. Sprint("2.OPTIMIZATIONS", 2, ypos+2)
  804. 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, " ")
  805. ypos = printWrapped(Splitter("- This page looks a lot cleaner now."), 3, ypos+3, w-3, " ")
  806. ypos = printWrapped(Splitter("- The variables are now ordered a lot better by splitting them into categories."), 3, ypos+1, w-3, " ")
  807. ypos = printWrapped(Splitter("- Many minor changes in program structure to save a few bytes."), 3, ypos+1, w-3, " ")
  808. Sprint("3.Bug fixes", 2, ypos+2)
  809. 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, " ")
  810. Sprint("Patch 2.5.1", 1, ypos+2)
  811. Sprint("-----------", 1, ypos+3)
  812. Sprint("1.NEW FEATURES", 2, ypos+5)
  813. 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, " ")
  814. 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, " ")
  815. ypos = printWrapped(Splitter("- Torches will -now for real- be placed under all circumstances (see 'Bug fixes')."), 3, ypos+1, w-3, " ")
  816. Sprint("2.OPTIMIZATIONS", 2, ypos+2)
  817. 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, " ")
  818. ypos = printWrapped(Splitter("- Added the page counter in the bottom left"), 3, ypos+1, w-3, " ")
  819. Sprint("3.Bug fixes", 2, ypos+2)
  820. 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, " ")
  821. 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, " ")
  822. 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, " ")
  823. Sprint("Patch 2.5", 1, ypos+2)
  824. Sprint("---------", 1, ypos+3)
  825. Sprint("1.NEW FEATURES", 2, ypos+5)
  826. 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, " ")
  827. ypos = printWrapped(Splitter("- If you want to, the turtle will now throw away items contained on the Ignor-list."), 3, ypos+1, w-3, " ")
  828. 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, " ")
  829. 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, " ")
  830. 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, " ")
  831. 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, " ")
  832. 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, " ")
  833. Sprint("2.OPTIMIZATIONS", 2, ypos+2)
  834. 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, " ")
  835. 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, " ")
  836. 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, " ")
  837. ypos = printWrapped(Splitter("- The inventory will now be cleared after finishing."), 3, ypos+1, w-3, " ")
  838. ypos = printWrapped(Splitter("- Optimized the dig() function to run faster, increasing the overall speed of the program drasticly."), 3, ypos+1, w-3, " ")
  839. Sprint("3.Bug fixes", 2, ypos+2)
  840. 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, " ")
  841. 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, " ")
  842. ypos = printWrapped(Splitter("- Asking for fuel and taking that fuel wasn't always sync."), 3, ypos+1, w-3, " ")
  843. ypos = printWrapped(Splitter("- The turtle would sometimes put the coal it needs to fuel itself into the chest."), 3, ypos+1, w-3, " ")
  844. ypos = printWrapped(Splitter("- When a tunnellength <= 4 was chosen the turtle placed way too much torches."), 3, ypos+1, w-3, " ")
  845. ypos = printWrapped(Splitter("- Many variables weren't refreshed after changing some options, messing up the preparation page."), 3, ypos+1, w-3, " ")
  846. 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, " ")
  847. Sprint("Patch 2.4", 1, ypos+2)
  848. Sprint("---------", 1, ypos+3)
  849. Sprint("1.NEW FEATURES", 2, ypos+5)
  850. ypos = printWrapped(Splitter("- Option to place a floor, if needed"), 3, ypos+6, w-3, " ")
  851. ypos = printWrapped(Splitter("- Option to change language. Currently available: english, german"), 3, ypos+1, w-3, " ")
  852. ypos = printWrapped(Splitter("- Added a scrollbar to the options page, too"), 3, ypos+1, w-3, " ")
  853. Sprint("2.OPTIMIZATIONS", 2, ypos+2)
  854. 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, " ")
  855. 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, " ")
  856. 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, " ")
  857. Sprint("3.Bug fixes", 2, ypos+2)
  858. 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, " ")
  859. 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, " ")
  860. 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, " ")
  861. 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, " ")
  862. Sprint("Patch 2.3", 1, ypos+2)
  863. Sprint("---------", 1, ypos+3)
  864. Sprint("1.LAYOUT", 2, ypos+5)
  865. ypos = printWrapped(Splitter("- Popup on execution in case of Errors"), 3, ypos+6, w-3, " ")
  866. ypos = printWrapped(Splitter("- Tiny optical improvement on the scrollbar"), 3, ypos+1, w-3, " ")
  867. Sprint("2.NEW FEATURES", 2, ypos+2)
  868. ypos = printWrapped(Splitter("- Option to make the turtle place the floor when it's missing"), 3, ypos+3, w-3, " ")
  869. ypos = printWrapped(Splitter("- Captions in the startmenu are visible for at least 5 seconds now"), 3, ypos+1, w-3, " ")
  870. Sprint("3.Bug fixes", 2, ypos+2)
  871. ypos = printWrapped(Splitter("- Autofuel would always refuel 5 coal, no matter how much was needed"), 3, ypos+3, w-3, " ")
  872. ypos = printWrapped(Splitter("- Options sometimes couldn't be selected or the layout got ugly"), 3, ypos+1, w-3, " ")
  873. ypos = printWrapped(Splitter("- In the startmenu the displayed amount of necessary torches was wrong"), 3, ypos+1, w-3, " ")
  874. Sprint("Patch 2.2", 1, ypos+2)
  875. Sprint("---------", 1, ypos+3)
  876. Sprint("1.NEW LAYOUT", 2, ypos+5)
  877. ypos = printWrapped(Splitter("- The awesome update window!"), 3, ypos+6, w-3, " ")
  878. ypos = printWrapped(Splitter("-> Anti-Annoying-Checkbox ;)"), 4, ypos+1, w-4, " ")
  879. ypos = printWrapped(Splitter("- This awesome news window!"), 3, ypos+1, w-3, " ")
  880. ypos = printWrapped(Splitter("-> Very functional scrollbar (mouse_wheel, arrow-keys or arrow-buttons can be used)"), 4, ypos+1, w-4, " ")
  881. Sprint("2.NEW FEATURES", 2, ypos+2)
  882. ypos = printWrapped(Splitter("- Favorite options are now savable"), 3, ypos+3, w-3, " ")
  883. 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, " ")
  884. ypos = printWrapped(Splitter("- Torches on the main floor are placed instantly now, to prevent mobs from spawning"), 3, ypos+1, w-3, " ")
  885. Sprint("3.Bug fixes", 2, ypos+2)
  886. ypos = printWrapped(Splitter("- Putting wrong items into a torchslot resulted in a wrong Errormessage"), 3, ypos+3, w-3, " ")
  887. ypos = printWrapped(Splitter("- When normal chest was selected, the program crashed trying to deploy the chest"), 3, ypos+1, w-3, " ")
  888. printLeft(string.rep(" ", w-2), h)
  889. printLeft("Page "..tostring(math.ceil((-menuVars["drawNews"].scroll+1)/10)).."/"..tostring(math.ceil((ypos-menuVars["drawNews"].scroll)/10)-1), h)
  890. printCentered(">Ok<", h)
  891. printLine(w, 3, h, "^", "v")
  892. drawHeader()
  893. end
  894.  
  895. function drawHome(event, p1, p2, p3)
  896. for i = 1, 3 do
  897. printCentered(lang.layout(settings.language, i+8), round((h-5)*(i/4), "u")+i+2)
  898. end
  899. printCentered(string.rep("-", #lang.layout(settings.language, select+8)), round((h-5)*(select/4), "u")+select+3)
  900. end
  901.  
  902. function drawStart(event, p1, p2, p3)
  903. --Fuellevel
  904. if turtle.getFuelLevel() ~= "unlimited" then
  905. MoveObjects(3, 2)
  906. printLeft(lang.layout(settings.language, 12), objects[3])
  907. if settings.Autofuel then
  908. fuelLevel = turtle.getFuelLevel()
  909. if fuelLevel < 3*variables.FuelDemand/settings.quantity then
  910. Fuellevel = "low"
  911. errors[8] = true
  912. printCentered(lang.layout(settings.language, 13), objects[3])
  913. elseif fuelLevel >= variables.FuelDemand then
  914. Fuellevel = "perfect"
  915. errors[8] = false
  916. elseif fuelLevel > variables.FuelDemand*0.5 then
  917. Fuellevel = "ready"
  918. errors[8] = false
  919. else
  920. Fuellevel = "risky"
  921. errors[8] = false
  922. end
  923. else
  924. if fuelLevel >= variables.FuelDemand*1.5 then
  925. Fuellevel = "perfect"
  926. elseif fuelLevel >= variables.FuelDemand*1 then
  927. Fuellevel = "ready"
  928. else
  929. Fuellevel = "low"
  930. printCentered(lang.layout(settings.language, 13), objects[3])
  931. end
  932. end
  933. if help[1] == false then
  934. help[1] = fuelLevel
  935. end
  936. if Color() then
  937. if Fuellevel == "perfect" then
  938. term.setBackgroundColor(colors.lime)
  939. elseif Fuellevel == "ready" or Fuellevel == "risky" then
  940. term.setBackgroundColor(colors.yellow)
  941. elseif Fuellevel == "low" then
  942. term.setBackgroundColor(colors.red)
  943. end
  944. printRight(fuelLevel.."/"..variables.FuelDemand, objects[3])
  945. term.setBackgroundColor(colors.black)
  946. else
  947. if Fuellevel == "perfect" then
  948. printRight("+ "..fuelLevel.."/"..variables.FuelDemand, objects[3])
  949. elseif Fuellevel == "ready" or Fuellevel == "risky" then
  950. printRight("+/- "..fuelLevel.."/"..variables.FuelDemand, objects[3])
  951. elseif Fuellevel == "low" then
  952. printRight("- "..fuelLevel.."/"..variables.FuelDemand, objects[3])
  953. end
  954. end
  955. else
  956. MoveObjects(3, 1)
  957. end
  958.  
  959. --Torches
  960. local TorchAmount = 0
  961. ErrorSlot = 0
  962. for i = 1, #variables.slots do
  963. if variables.slots[i] == "T" then
  964. if ItemCount("minecraft:torch", i) ~= false then
  965. TorchAmount = TorchAmount + ItemCount("minecraft:torch", i)
  966. else
  967. ErrorSlot = i
  968. end
  969. end
  970. end
  971. if ErrorSlot ~= 0 then
  972. errors[1] = true
  973. else
  974. errors[1] = false
  975. end
  976. if variables.TorchDemand ~= 0 then
  977. MoveObjects(4, 2)
  978. printLeft(lang.layout(settings.language, 14), objects[4])
  979. if TorchAmount < variables.TorchDemand then
  980. Check.torch = false
  981. if Color() then
  982. term.setBackgroundColor(colors.red)
  983. end
  984. else
  985. Check.torch = true
  986. if Color() then
  987. term.setBackgroundColor(colors.lime)
  988. end
  989. end
  990. printRight(TorchAmount.."/"..variables.TorchDemand, objects[4])
  991. if Check.torch == false then
  992. errors[7] = true
  993. else
  994. errors[7] = false
  995. end
  996. term.setBackgroundColor(colors.black)
  997. else
  998. MoveObjects(4, 1)
  999. errors[7] = false
  1000. end
  1001.  
  1002. --Chest
  1003. errors[2] = false
  1004. errors[3] = false
  1005. errors[4] = false
  1006. errors[5] = false
  1007. errors[6] = false
  1008. Check.chest = false
  1009. if settings.chestSelect == 1 then
  1010. MoveObjects(5, 2)
  1011. printLeft(lang.layout(settings.language, 15), objects[5])
  1012. if Version < 1.64 then
  1013. if turtle.getItemCount(chestSlot) == 0 then
  1014. errors[4] = true
  1015. else
  1016. Check.chest = true
  1017. end
  1018. else
  1019. if ItemCount("minecraft:ender_chest", chestSlot) ~= false and ItemCount("minecraft:ender_chest", chestSlot) > 0 then
  1020. errors[2] = true
  1021. elseif ItemCount(enderChestList, chestSlot) == false then
  1022. errors[3] = true
  1023. elseif ItemCount(enderChestList, chestSlot) == 0 then
  1024. errors[4] = true
  1025. else
  1026. Check.chest = true
  1027. end
  1028. end
  1029. elseif settings.chestSelect == 2 then
  1030. MoveObjects(5, 2)
  1031. printLeft(lang.layout(settings.language, 18), objects[5])
  1032. if ItemCount(chestList, chestSlot) == false then
  1033. errors[5] = true
  1034. elseif ItemCount(chestList, chestSlot) == 0 then
  1035. errors[6] = true
  1036. else
  1037. Check.chest = true
  1038. end
  1039. else
  1040. Check.chest = true
  1041. MoveObjects(5, 1)
  1042. end
  1043. if Check.chest == false then
  1044. if Color() then
  1045. term.setBackgroundColor(colors.red)
  1046. end
  1047. printRight(lang.layout(settings.language, 16), objects[5])
  1048. else
  1049. if Color() then
  1050. term.setBackgroundColor(colors.lime)
  1051. end
  1052. printRight(lang.layout(settings.language, 17), objects[5])
  1053. end
  1054. term.setBackgroundColor(colors.black)
  1055.  
  1056. --Autofuel
  1057. if settings.Autofuel == true then
  1058. MoveObjects(6, 2)
  1059. printLeft(lang.layout(settings.language, 19), objects[6])
  1060. term.setBackgroundColor(colors.lime)
  1061. printRight(lang.layout(settings.language, 17), objects[6])
  1062. term.setBackgroundColor(colors.black)
  1063. if help[4] == false then
  1064. help[4] = turtle.getItemCount(AutofuelSlot)
  1065. end
  1066. else
  1067. MoveObjects(6, 1)
  1068. end
  1069.  
  1070. printLeft(string.rep("-", w), objects[7])
  1071.  
  1072. --Inventory
  1073. if Version < 1.64 then
  1074. for i = 1, #variables.slots do
  1075. if variables.slots[i] == "I" then
  1076. variables.slots[i] = "_"
  1077. end
  1078. end
  1079. for i = 1, settings.ignor do
  1080. variables.slots[i] = "I"
  1081. end
  1082. end
  1083. for k, v in ipairs(SlotCalculator("T", "empty")) do
  1084. variables.slots[v] = "_"
  1085. end
  1086. local stupid = SlotCalculator("_", "empty")
  1087. for k, v in ipairs(stupid) do
  1088. if k > #stupid-math.ceil(variables.TorchDemand/64) then
  1089. variables.slots[v] = "T"
  1090. end
  1091. end
  1092. notificationCenter()
  1093. printRight("|"..variables.slots[1].."|"..variables.slots[2].."|"..variables.slots[3].."|"..variables.slots[4].."|", objects[8])
  1094. printRight("|"..variables.slots[5].."|"..variables.slots[6].."|"..variables.slots[7].."|"..variables.slots[8].."|", objects[9])
  1095. printRight("|"..variables.slots[9].."|"..variables.slots[10].."|"..variables.slots[11].."|"..variables.slots[12].."|", objects[10])
  1096. printRight("|"..variables.slots[13].."|"..variables.slots[14].."|"..variables.slots[15].."|"..variables.slots[16].."|", objects[11])
  1097.  
  1098. if objects[11] < 12 then
  1099. printLeft(string.rep("-", w), 12)
  1100. end
  1101.  
  1102. --Buttons
  1103. if select == 1 then
  1104. printB({">"..lang.layout(settings.language, 20).."<", " "..lang.layout(settings.language, 10).." ", " "..lang.layout(settings.language, 21).." "}, objects[13])
  1105. elseif select == 2 then
  1106. printB({" "..lang.layout(settings.language, 20).." ", ">"..lang.layout(settings.language, 10).."<", " "..lang.layout(settings.language, 21).." "}, objects[13])
  1107. elseif select == 3 then
  1108. printB({" "..lang.layout(settings.language, 20).." ", " "..lang.layout(settings.language, 10).." ", ">"..lang.layout(settings.language, 21).."<"}, objects[13])
  1109. end
  1110.  
  1111. --Action
  1112. if fuelLevel < 3*variables.FuelDemand/settings.quantity then
  1113. local FuelAmount = math.ceil((3*variables.FuelDemand/settings.quantity-fuelLevel)/80)
  1114. for i = 1, #SlotCalculator("_", "minecraft:coal") do
  1115. turtle.select(SlotCalculator("_", "minecraft:coal")[i])
  1116. local output = refuel(FuelAmount, true)
  1117. if output == true then
  1118. errors[8] = false
  1119. Fuellevel = "risky"
  1120. else
  1121. FuelAmount = FuelAmount - output
  1122. end
  1123. end
  1124. end
  1125. end
  1126.  
  1127. function drawOptions(event, p1, p2, p3)
  1128. if menuVars["drawOptions"].focus == 100 then
  1129. calculateFuelDemand()
  1130. TorchCalculator()
  1131. if menuVars["drawOptions"].saved == true and select == 3 then
  1132. select = 2
  1133. end
  1134. end
  1135. if event == "mouse_scroll" then
  1136. if menuVars["drawOptions"].focus == 100 then
  1137. menuVars["drawOptions"].scroll = menuVars["drawOptions"].scroll - p1
  1138. 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
  1139. menuVars["drawOptions"].scroll2 = menuVars["drawOptions"].scroll2 - p1
  1140. end
  1141. elseif event == "mouse_click" and p1 == 1 and menuVars["drawOptions"].focus == 100 then
  1142. if p2 == w then
  1143. if p3 == 3 then
  1144. menuVars["drawOptions"].scroll = menuVars["drawOptions"].scroll + 1
  1145. elseif p3 == h then
  1146. menuVars["drawOptions"].scroll = menuVars["drawOptions"].scroll - 1
  1147. end
  1148. else
  1149. menuVars["drawOptions"].focus = p3
  1150. if menuVars["drawOptions"].focus > 15+menuVars["drawOptions"].shift+menuVars["drawOptions"].shift2 or menuVars["drawOptions"].focus > h-3 or menuVars["drawOptions"].focus < 3 then
  1151. menuVars["drawOptions"].focus = 100
  1152. end
  1153. end
  1154. elseif event == "key" then
  1155. if p1 == 28 and menuVars["drawOptions"].focus ~= 0 then
  1156. menuVars["drawOptions"].saved = false
  1157. menuVars["drawOptions"].focus = 100
  1158. elseif p1 == 208 and menuVars["drawOptions"].focus == 100 then
  1159. menuVars["drawOptions"].scroll = menuVars["drawOptions"].scroll - 1
  1160. elseif p1 == 200 and menuVars["drawOptions"].focus == 100 then
  1161. menuVars["drawOptions"].scroll = menuVars["drawOptions"].scroll + 1
  1162. else
  1163. if settings.torches == false then
  1164. if menuVars["drawOptions"].focus == 8+menuVars["drawOptions"].scroll then
  1165. if p1 == 203 and settings.mainTorches == false then
  1166. settings.mainTorches = true
  1167. elseif p1 == 205 and settings.mainTorches == true then
  1168. settings.mainTorches = false
  1169. end
  1170. end
  1171. end
  1172. menuVars["drawOptions"].shift2 = 0
  1173. if Version >= 1.64 then
  1174. if menuVars["drawOptions"].focus == 14+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1175. if p1 == 203 and settings.trash == false then
  1176. settings.trash = true
  1177. elseif p1 == 205 and settings.trash == true then
  1178. settings.trash = false
  1179. end
  1180. end
  1181. else
  1182. menuVars["drawOptions"].shift2 = menuVars["drawOptions"].shift2-1
  1183. end
  1184. if menuVars["drawOptions"].focus == 3+menuVars["drawOptions"].scroll then
  1185. if p1 == 203 and settings.language == "de" then
  1186. settings.language = "en"
  1187. elseif p1 == 205 and settings.language == "en" then
  1188. settings.language = "de"
  1189. end
  1190. elseif menuVars["drawOptions"].focus == 4+menuVars["drawOptions"].scroll then
  1191. if p1 == 203 and settings.tunnelspace == 4 then
  1192. settings.tunnelspace = 3
  1193. elseif p1 == 205 and settings.tunnelspace == 3 then
  1194. settings.tunnelspace = 4
  1195. end
  1196. elseif menuVars["drawOptions"].focus == 7+menuVars["drawOptions"].scroll then
  1197. if p1 == 203 and settings.chestSelect > 1 then
  1198. settings.chestSelect = settings.chestSelect - 1
  1199. elseif p1 == 205 and settings.chestSelect < #chest then
  1200. settings.chestSelect = settings.chestSelect + 1
  1201. end
  1202. for k, v in ipairs(chest) do
  1203. if k == settings.chestSelect then
  1204. v = true
  1205. else
  1206. v = false
  1207. end
  1208. end
  1209. elseif menuVars["drawOptions"].focus == 8+menuVars["drawOptions"].scroll then
  1210. if p1 == 203 and settings.torches == false then
  1211. settings.torches = true
  1212. elseif p1 == 205 and settings.torches == true then
  1213. settings.torches = false
  1214. end
  1215. elseif menuVars["drawOptions"].focus == 11+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1216. if p1 == 203 and settings.Autofuel == false then
  1217. settings.Autofuel = true
  1218. elseif p1 == 205 and settings.Autofuel == true then
  1219. settings.Autofuel = false
  1220. end
  1221. elseif menuVars["drawOptions"].focus == 12+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1222. if p1 == 203 and settings.floor == false then
  1223. settings.floor = true
  1224. elseif p1 == 205 and settings.floor == true then
  1225. settings.floor = false
  1226. end
  1227. elseif menuVars["drawOptions"].focus == 13+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1228. if p1 == 200 and menuVars["drawOptions"].scroll2 < 0 then
  1229. menuVars["drawOptions"].scroll2 = menuVars["drawOptions"].scroll2+1
  1230. elseif p1 == 208 and h < menuVars["drawOptions"].ypos then
  1231. menuVars["drawOptions"].scroll2 = menuVars["drawOptions"].scroll2-1
  1232. elseif Version >= 1.64 then
  1233. if p1 == 57 or p1 == 14 then
  1234. for i = 1, 16 do
  1235. local data = turtle.getItemDetail(i)
  1236. if data then
  1237. for k, v in ipairs(settings.ignor) do
  1238. if v == data.name then
  1239. table.remove(settings.ignor, k)
  1240. end
  1241. end
  1242. if p1 == 57 then
  1243. table.insert(settings.ignor, data.name)
  1244. end
  1245. end
  1246. end
  1247. end
  1248. end
  1249. elseif menuVars["drawOptions"].focus == 15+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1250. if p1 == 203 and settings.walls == false then
  1251. settings.walls = true
  1252. elseif p1 == 205 and settings.walls == true then
  1253. settings.walls = false
  1254. end
  1255. end
  1256. end
  1257. end
  1258. if menuVars["drawOptions"].scroll > 0 then
  1259. menuVars["drawOptions"].scroll = 0
  1260. elseif menuVars["drawOptions"].scroll < -(5+menuVars["drawOptions"].shift+menuVars["drawOptions"].shift2) then
  1261. menuVars["drawOptions"].scroll = -(5+menuVars["drawOptions"].shift+menuVars["drawOptions"].shift2)
  1262. end
  1263.  
  1264. if settings.torches == false then
  1265. if menuVars["drawOptions"].focus == 9+menuVars["drawOptions"].scroll then
  1266. printLeft(lang.layout(settings.language, 31), menuVars["drawOptions"].focus)
  1267. if settings.mainTorches == true then
  1268. printRight(">"..lang.layout(settings.language, 29).."< "..lang.layout(settings.language, 30).." ", menuVars["drawOptions"].focus)
  1269. else
  1270. printRight(lang.layout(settings.language, 29).." >"..lang.layout(settings.language, 30).."<", menuVars["drawOptions"].focus)
  1271. end
  1272. elseif menuVars["drawOptions"].focus == 10+menuVars["drawOptions"].scroll then
  1273. printLeft(lang.layout(settings.language, 32), menuVars["drawOptions"].focus)
  1274. term.setCursorPos(w-2, menuVars["drawOptions"].focus)
  1275. settings.lateralTorches = tonumber(read())
  1276. term.clear()
  1277. drawHeader()
  1278. return drawOptions("key", 28)
  1279. end
  1280. menuVars["drawOptions"].shift = 0
  1281. else
  1282. menuVars["drawOptions"].shift = -2
  1283. end
  1284. if Version >= 1.64 then
  1285. if menuVars["drawOptions"].focus == 14+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1286. printLeft(lang.layout(settings.language, 39), menuVars["drawOptions"].focus)
  1287. if settings.trash == true then
  1288. printRight(">"..lang.layout(settings.language, 29).."< "..lang.layout(settings.language, 30).." ", menuVars["drawOptions"].focus)
  1289. else
  1290. printRight(lang.layout(settings.language, 29).." >"..lang.layout(settings.language, 30).."<", menuVars["drawOptions"].focus)
  1291. end
  1292. end
  1293. end
  1294. if menuVars["drawOptions"].focus == 3+menuVars["drawOptions"].scroll then
  1295. printLeft(lang.layout(settings.language, 34), menuVars["drawOptions"].focus)
  1296. if settings.language == "en" then
  1297. printRight(">en< de ", menuVars["drawOptions"].focus)
  1298. else
  1299. printRight("en >de<", menuVars["drawOptions"].focus)
  1300. end
  1301. elseif menuVars["drawOptions"].focus == 4+menuVars["drawOptions"].scroll then
  1302. printLeft(lang.layout(settings.language, 22), menuVars["drawOptions"].focus)
  1303. if settings.tunnelspace == 3 then
  1304. printRight(">2< 3 ", menuVars["drawOptions"].focus)
  1305. else
  1306. printRight("2 >3<", menuVars["drawOptions"].focus)
  1307. end
  1308. elseif menuVars["drawOptions"].focus == 5+menuVars["drawOptions"].scroll then
  1309. printLeft(lang.layout(settings.language, 23), menuVars["drawOptions"].focus)
  1310. term.setCursorPos(w-2, menuVars["drawOptions"].focus)
  1311. settings.quantity = tonumber(read())
  1312. term.clear()
  1313. drawHeader()
  1314. return drawOptions("key", 28)
  1315. elseif menuVars["drawOptions"].focus == 6+menuVars["drawOptions"].scroll then
  1316. printLeft(lang.layout(settings.language, 24), menuVars["drawOptions"].focus)
  1317. term.setCursorPos(w-2, menuVars["drawOptions"].focus)
  1318. settings.length = tonumber(read())
  1319. term.clear()
  1320. drawHeader()
  1321. return drawOptions("key", 28)
  1322. elseif menuVars["drawOptions"].focus == 7+menuVars["drawOptions"].scroll then
  1323. printLeft(lang.layout(settings.language, 18), menuVars["drawOptions"].focus)
  1324. variables.slots[16] = "C"
  1325. if settings.chestSelect == 1 then
  1326. printRight(">"..lang.layout(settings.language, 25).."< "..lang.layout(settings.language, 26).." "..lang.layout(settings.language, 27).." ", menuVars["drawOptions"].focus)
  1327. elseif settings.chestSelect == 2 then
  1328. printRight(lang.layout(settings.language, 25).." >"..lang.layout(settings.language, 26).."< "..lang.layout(settings.language, 27).." ", menuVars["drawOptions"].focus)
  1329. else
  1330. printRight(lang.layout(settings.language, 25).." "..lang.layout(settings.language, 26).." >"..lang.layout(settings.language, 27).."<", menuVars["drawOptions"].focus)
  1331. if variables.slots[16] == "C" then
  1332. variables.slots[16] = "_"
  1333. end
  1334. end
  1335. elseif menuVars["drawOptions"].focus == 8+menuVars["drawOptions"].scroll then
  1336. printLeft(lang.layout(settings.language, 28), menuVars["drawOptions"].focus)
  1337. if settings.torches == true then
  1338. printRight(">"..lang.layout(settings.language, 29).."< "..lang.layout(settings.language, 30).." ", menuVars["drawOptions"].focus)
  1339. else
  1340. printRight(" "..lang.layout(settings.language, 29).." >"..lang.layout(settings.language, 30).."<", menuVars["drawOptions"].focus)
  1341. end
  1342. elseif menuVars["drawOptions"].focus == 11+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1343. printLeft(lang.layout(settings.language, 19), menuVars["drawOptions"].focus)
  1344. if settings.Autofuel == true then
  1345. printRight(">"..lang.layout(settings.language, 29).."< "..lang.layout(settings.language, 30).." ", menuVars["drawOptions"].focus)
  1346. else
  1347. printRight(lang.layout(settings.language, 29).." >"..lang.layout(settings.language, 30).."<", menuVars["drawOptions"].focus)
  1348. end
  1349. elseif menuVars["drawOptions"].focus == 12+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1350. printLeft(lang.layout(settings.language, 33), menuVars["drawOptions"].focus)
  1351. if settings.floor == true then
  1352. printRight(">"..lang.layout(settings.language, 29).."< "..lang.layout(settings.language, 30).." ", menuVars["drawOptions"].focus)
  1353. else
  1354. printRight(lang.layout(settings.language, 29).." >"..lang.layout(settings.language, 30).."<", menuVars["drawOptions"].focus)
  1355. end
  1356. elseif menuVars["drawOptions"].focus == 13+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1357. if Version >= 1.64 then
  1358. printLeft(lang.layout(settings.language, 36), 3)
  1359. local ypos = printWrapped(textutils.unserialize(string.gsub(textutils.serialize(settings.ignor), "minecraft:(%a+)", function(q) return q.."," end)), 1, 4, w)
  1360. menuVars["drawOptions"].ypos = printWrapped(Splitter(lang.layout(settings.language, 37, label)), 1, ypos+2+menuVars["drawOptions"].scroll2, w-1)
  1361. for i = 1, ypos+1 do
  1362. printLeft(string.rep(" ", w), i)
  1363. end
  1364. drawHeader()
  1365. printLeft(lang.layout(settings.language, 36), 3)
  1366. printWrapped(textutils.unserialize(string.gsub(textutils.serialize(settings.ignor), "minecraft:(%a+_*%a*)", function(q) return q.."," end)), 1, 4, w)
  1367. printLine(w, ypos+2, h, "^", "v")
  1368. else
  1369. printLeft(lang.layout(settings.language, 38), menuVars["drawOptions"].focus)
  1370. term.setCursorPos(w-2, menuVars["drawOptions"].focus)
  1371. settings.ignor = tonumber(read())
  1372. term.clear()
  1373. drawHeader()
  1374. return drawOptions("key", 28)
  1375. end
  1376. elseif menuVars["drawOptions"].focus == 15+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift then
  1377. printLeft(lang.layout(settings.language, 40), menuVars["drawOptions"].focus)
  1378. if settings.walls == true then
  1379. printRight(">"..lang.layout(settings.language, 29).."< "..lang.layout(settings.language, 30).." ", menuVars["drawOptions"].focus)
  1380. else
  1381. printRight(lang.layout(settings.language, 29).." >"..lang.layout(settings.language, 30).."<", menuVars["drawOptions"].focus)
  1382. end
  1383. elseif menuVars["drawOptions"].focus == 100 then
  1384. printLeft(lang.layout(settings.language, 34), 3+menuVars["drawOptions"].scroll)
  1385. printLeft(lang.layout(settings.language, 22), 4+menuVars["drawOptions"].scroll)
  1386. printLeft(lang.layout(settings.language, 23), 5+menuVars["drawOptions"].scroll)
  1387. printLeft(lang.layout(settings.language, 24), 6+menuVars["drawOptions"].scroll)
  1388. printLeft(lang.layout(settings.language, 18), 7+menuVars["drawOptions"].scroll)
  1389. printLeft(lang.layout(settings.language, 28), 8+menuVars["drawOptions"].scroll)
  1390. if settings.torches == false then
  1391. printLeft(lang.layout(settings.language, 31), 9+menuVars["drawOptions"].scroll)
  1392. printLeft(lang.layout(settings.language, 32), 10+menuVars["drawOptions"].scroll)
  1393. end
  1394. printLeft(lang.layout(settings.language, 19), 11+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift)
  1395. printLeft(lang.layout(settings.language, 33), 12+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift)
  1396. printLeft("#"..lang.layout(settings.language, 36), 13+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift)
  1397. printLeft(lang.layout(settings.language, 39), 14+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift)
  1398. printLeft(lang.layout(settings.language, 40), 15+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift)
  1399. printRight(settings.language, 3+menuVars["drawOptions"].scroll, 1)
  1400. printRight(tostring(settings.tunnelspace-1), 4+menuVars["drawOptions"].scroll, 1)
  1401. printRight(tostring(settings.quantity), 5+menuVars["drawOptions"].scroll, 1)
  1402. printRight(tostring(settings.length), 6+menuVars["drawOptions"].scroll, 1)
  1403. printRight(translate(chest[tonumber(settings.chestSelect)], "layout"), 7+menuVars["drawOptions"].scroll, 1)
  1404. printRight(translate(tostring(settings.torches), "layout"), 8+menuVars["drawOptions"].scroll, 1)
  1405. if settings.torches == false then
  1406. printRight(translate(tostring(settings.mainTorches), "layout"), 9+menuVars["drawOptions"].scroll, 1)
  1407. printRight(tostring(settings.lateralTorches), 10+menuVars["drawOptions"].scroll, 1)
  1408. end
  1409. printRight(translate(tostring(settings.Autofuel), "layout"), 11+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift, 1)
  1410. printRight(translate(tostring(settings.floor), "layout"), 12+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift, 1)
  1411. if Version >= 1.64 then
  1412. printRight(tostring(#settings.ignor-4), 13+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift, 1)
  1413. else
  1414. printRight(tostring(settings.ignor), 13+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift, 1)
  1415. end
  1416. printRight(translate(tostring(settings.trash), "layout"), 14+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift, 1)
  1417. printRight(translate(tostring(settings.walls), "layout"), 15+menuVars["drawOptions"].scroll+menuVars["drawOptions"].shift, 1)
  1418. printLeft(string.rep(" ", w-1), h)
  1419. printLeft(string.rep(" ", w-1), h-1)
  1420. printLeft(string.rep(" ", w-1), h-2)
  1421. printB({lang.layout(settings.language, 9), lang.layout(settings.language, 21), lang.layout(settings.language, 35)}, 12)
  1422. if select == 1 then
  1423. printB({string.rep("_", #lang.layout(settings.language, 9)), string.rep(" ", #lang.layout(settings.language, 21)), string.rep(" ", #lang.layout(settings.language, 35))}, 13)
  1424. elseif select == 2 then
  1425. printB({string.rep(" ", #lang.layout(settings.language, 9)), string.rep("_", #lang.layout(settings.language, 21)), string.rep(" ", #lang.layout(settings.language, 35))}, 13)
  1426. else
  1427. printB({string.rep(" ", #lang.layout(settings.language, 9)), string.rep(" ", #lang.layout(settings.language, 21)), string.rep("_", #lang.layout(settings.language, 35))}, 13)
  1428. end
  1429. printLine(w, 3, h-2, "^", "v")
  1430. drawHeader()
  1431. end
  1432. end
  1433.  
  1434. function drawResume(time)
  1435. term.setCursorPos(1, 3)
  1436. print("Program will resume in "..tostring(time).." seconds.\n")
  1437. print("Press Enter to stop resuming...")
  1438. end
  1439.  
  1440. menu = {
  1441. ["Update"] = {
  1442. options = {"News", "Home"},
  1443. orientation = "horizontal",
  1444. draw = drawUpdate
  1445. },
  1446. ["News"] = {
  1447. options = {"Home"},
  1448. orientation = "horizontal",
  1449. draw = drawNews
  1450. },
  1451. ["Home"] = {
  1452. options = {"Start", "Options", "Quit"},
  1453. orientation = "vertical",
  1454. draw = drawHome
  1455. },
  1456. ["Start"] = {
  1457. options = {"Go!", "Options", "Home"},
  1458. orientation = "horizontal",
  1459. draw = drawStart
  1460. },
  1461. ["Options"] = {
  1462. options = {"Start", "Home", "Save as default"},
  1463. orientation = "horizontal",
  1464. draw = drawOptions
  1465. },
  1466. ["Popup"] = {
  1467. options = {"Go!", "Start", "Quit"},
  1468. orientation = "horizontal",
  1469. draw = drawPopup
  1470. }
  1471. }
  1472.  
  1473. -----###-----sequences-----###-----
  1474.  
  1475. function Return()
  1476. face(1)
  1477. if #variables.cache == 0 then
  1478. return
  1479. elseif variables.cache[#variables.cache] == 5 then
  1480. insert('FreewayDown()')
  1481. elseif variables.cache[#variables.cache] == 6 then
  1482. insert('FreewayUp()')
  1483. else
  1484. insert('FreewayBack()')
  1485. insert('variables.direction = variables.cache[#variables.cache]')
  1486. end
  1487. insert('face(1)')
  1488. insert('table.remove(variables.cache, #variables.cache)')
  1489. end
  1490.  
  1491. function compare(method, slotNum)
  1492. turtle.select(slotNum)
  1493. if method == "down" then
  1494. return turtle.compareDown()
  1495. elseif method == "up" then
  1496. return turtle.compareUp()
  1497. elseif method == "front" then
  1498. return turtle.compare()
  1499. end
  1500. end
  1501.  
  1502. function CompareDown(walls)
  1503. if Version >= 1.64 then
  1504. local boolean, data = turtle.inspectDown()
  1505. if boolean then
  1506. for k, v in pairs(settings.ignor) do
  1507. if v == data.name then
  1508. return
  1509. end
  1510. end
  1511. else
  1512. return
  1513. end
  1514. elseif turtle.detectDown() then
  1515. for k, v in pairs(SlotCalculator("I")) do
  1516. if compare("down", k) == true then
  1517. return
  1518. end
  1519. end
  1520. else
  1521. return
  1522. end
  1523. insert('variables.searching = true')
  1524. insert('turtle.select(SlotCalculator("_", "empty")[1])')
  1525. insert('digDown()')
  1526. insert('FreewayDown()')
  1527. insert('table.insert(variables.cache, 6)')
  1528. insert('CompareAll("CompareUp()")')
  1529. end
  1530.  
  1531. function CompareUp(walls)
  1532. if Version >= 1.64 then
  1533. local boolean, data = turtle.inspectUp()
  1534. if boolean then
  1535. for k, v in pairs(settings.ignor) do
  1536. if v == data.name then
  1537. return (walls and placeWall("placeUp")) or nil
  1538. end
  1539. end
  1540. else
  1541. return (walls and placeWall("placeUp")) or nil
  1542. end
  1543. elseif turtle.detectUp() then
  1544. for k, v in pairs(SlotCalculator("I")) do
  1545. if compare("up", k) == true then
  1546. return
  1547. end
  1548. end
  1549. else
  1550. return (walls and placeWall("placeUp")) or nil
  1551. end
  1552. insert('variables.searching = true')
  1553. insert('turtle.select(SlotCalculator("_", "empty")[1])')
  1554. insert('digUp()')
  1555. insert('FreewayUp()')
  1556. insert('table.insert(variables.cache, 5)')
  1557. if walls == true then
  1558. insert('placeWall()')
  1559. end
  1560. insert('CompareAll("CompareDown()")')
  1561. end
  1562.  
  1563. function CompareRight(walls)
  1564. Compare(4, walls)
  1565. end
  1566.  
  1567. function CompareBack(walls)
  1568. Compare(3, walls)
  1569. end
  1570.  
  1571. function CompareLeft(walls)
  1572. Compare(2, walls)
  1573. end
  1574.  
  1575. function Compare(facing, walls)
  1576. if facing == nil then
  1577. facing = 1
  1578. elseif type(facing) == "boolean" then
  1579. walls = facing
  1580. facing = 1
  1581. end
  1582. face(facing)
  1583. if Version >= 1.64 then
  1584. local boolean, data = turtle.inspect()
  1585. if boolean then
  1586. for k, v in pairs(settings.ignor) do
  1587. if v == data.name then
  1588. return (walls and placeWall("placeUp")) or nil
  1589. end
  1590. end
  1591. else
  1592. return (walls and placeWall()) or nil
  1593. end
  1594. elseif turtle.detect() then
  1595. for k, v in pairs(SlotCalculator("I")) do
  1596. if compare("front", k) == true then
  1597. return
  1598. end
  1599. end
  1600. else
  1601. return (walls and placeWall()) or nil
  1602. end
  1603. insert('variables.searching = true')
  1604. insert('turtle.select(SlotCalculator("_", "empty")[1])')
  1605. insert('dig()')
  1606. insert('Freeway()')
  1607. insert('table.insert(variables.cache, variables.direction)')
  1608. if walls == true then
  1609. insert('placeWall("placeUp")')
  1610. end
  1611. insert('variables.direction = 1')
  1612. insert('CompareAll("CompareBack()")')
  1613. end
  1614.  
  1615. function CompareAll(...)
  1616. local exceptions = {...}
  1617. local walls
  1618. if type(exceptions[1]) == "boolean" then
  1619. walls = exceptions[1]
  1620. table.remove(exceptions, 1)
  1621. end
  1622. insert('Compare()')
  1623. insert('CompareLeft()')
  1624. insert('CompareBack()')
  1625. insert('CompareRight()')
  1626. insert('CompareUp()')
  1627. insert('CompareDown()')
  1628. insert('Return()')
  1629. local sub = 0
  1630. for j = 2, 8-sub do
  1631. for k, v in ipairs(exceptions) do
  1632. if v == todoList[j] then
  1633. table.remove(todoList, j)
  1634. table.remove(exceptions, k)
  1635. j = j - 1
  1636. sub = sub + 1
  1637. end
  1638. end
  1639. end
  1640. if walls == true then
  1641. for i = 2, 15 do
  1642. if todoList[i] == 'Return()' then
  1643. break
  1644. elseif string.find(todoList[i], 'placeWall(') == nil then
  1645. if string.find(todoList[i], 'Up') ~= nil then
  1646. table.insert(todoList, i+1, 'placeWall("placeUp")')
  1647. elseif string.find(todoList[i], 'Down') == nil then
  1648. table.insert(todoList, i+1, 'placeWall()')
  1649. end
  1650. end
  1651. end
  1652. end
  1653. end
  1654.  
  1655. function trash(keptCobble)
  1656. for k, v in ipairs(SlotCalculator("_")) do
  1657. local data = turtle.getItemDetail(v)
  1658. for k2, v2 in pairs(settings.ignor) do
  1659. if v2 == data.name then
  1660. if not keptCobble and v2 == "minecraft:cobblestone" then
  1661. keptCobble = true
  1662. else
  1663. turtle.select(v)
  1664. turtle.drop()
  1665. end
  1666. end
  1667. end
  1668. end
  1669. end
  1670.  
  1671. function Enderchest(keptCoal, keptCobble)
  1672. if (#SlotCalculator("_") >= #SlotCalculator("_", "empty")-1-math.ceil(settings.length/12) or keptCoal == true) and #SlotCalculator("C", "check") ~= 0 then
  1673. turtle.select(SlotCalculator("C", "check")[1])
  1674. if variables.level == 1 then
  1675. insert('FreewayDown()')
  1676. end
  1677. insert('FreewayBack()')
  1678. insert([[while not turtle.place() do
  1679. turtle.attack()
  1680. end]])
  1681. insert([[for k, v in ipairs(SlotCalculator("_")) do
  1682. if settings.Autofuel and not keptCoal and Version >= 1.64 and turtle.getItemDetail(v).name == "minecraft:coal" then
  1683. keptCoal = true
  1684. elseif not keptCobble and v == "minecraft:cobblestone" then
  1685. keptCobble = true
  1686. else
  1687. turtle.select(v)
  1688. while not turtle.drop() do
  1689. print(lang.status(settings.language, 3))
  1690. sleep(10)
  1691. end
  1692. end
  1693. end
  1694. turtle.select(SlotCalculator("C", "empty")[1])]])
  1695. insert('dig()')
  1696. insert('Freeway()')
  1697. insert([[turtle.select(SlotCalculator("_", "empty")[1])
  1698. print(lang.status(settings.language, 4))]])
  1699. end
  1700. end
  1701.  
  1702. function NormalChest(keptCoal, keptCobble)
  1703. local function goToOrigin()
  1704. insert('turn()')
  1705. insert([[if variables.level == 1 then
  1706. FreewayDown()
  1707. end
  1708. for Way_Back = 1, variables.CrosswayAmount*settings.tunnelspace do
  1709. Freeway()
  1710. end]])
  1711. insert('turn()')
  1712. end
  1713. local function dropOff()
  1714. print("sdsdsdsdsdsdsdsdsadistic")
  1715. insert([[for k, v in ipairs(SlotCalculator("_")) do
  1716. if settings.Autofuel and not keptCoal and Version >= 1.64 and turtle.getItemDetail(v).name == "minecraft:coal" then
  1717. keptCoal = true
  1718. elseif not keptCobble and v == "minecraft:cobblestone" then
  1719. keptCobble = true
  1720. else
  1721. turtle.select(v)
  1722. print("eff")
  1723. print(turtle.getItemCount())
  1724. print(lang.status(settings.language, 3))
  1725. while not turtle.dropDown() and turtle.getItemCount() ~= 0 do
  1726. print(lang.status(settings.language, 3))
  1727. sleep(10)
  1728. end
  1729. end
  1730. end]])
  1731. end
  1732. if variables.setup == true then
  1733. goToOrigin()
  1734. dropOff()
  1735. insert([[for Way_Back = 1, variables.CrosswayAmount*settings.tunnelspace do
  1736. Freeway()
  1737. end]])
  1738. insert('print(lang.status(settings.language, 4))')
  1739. elseif #SlotCalculator("C", "check") == 0 then
  1740. variables.setup = false
  1741. elseif #SlotCalculator("_") >= #SlotCalculator("_", "empty")-1-math.ceil(settings.length/12) then
  1742. goToOrigin()
  1743. insert('turtle.select(SlotCalculator("C", "check")[1])')
  1744. insert([[while not turtle.placeDown() do
  1745. digDown()
  1746. end]])
  1747. insert('variables.setup = true')
  1748. dropOff()
  1749. insert([[for Way_Back = 1, variables.CrosswayAmount*settings.tunnelspace do
  1750. Freeway()
  1751. end]])
  1752. insert('print(lang.status(settings.language, 4))')
  1753. end
  1754. end
  1755.  
  1756. function Fuel()
  1757. local FuelAmount = math.ceil(3*variables.FuelDemand/settings.quantity/80)
  1758. fuelLevel = turtle.getFuelLevel()
  1759. if fuelLevel < 3*variables.FuelDemand/settings.quantity then
  1760. while true do
  1761. while #SlotCalculator("_", "minecraft:coal") > 0 do
  1762. turtle.select(SlotCalculator("_", "minecraft:coal")[1])
  1763. local output = refuel(FuelAmount, true)
  1764. if output == true then
  1765. print(lang.status(settings.language, 5))
  1766. return
  1767. else
  1768. FuelAmount = FuelAmount - output
  1769. end
  1770. end
  1771. term.clear()
  1772. term.setCursorPos(1,1)
  1773. print(lang.status(settings.language, 6))
  1774. write(lang.status(settings.language, 7))
  1775. for k, v in ipairs(SlotCalculator("_", "empty")) do
  1776. if k == #SlotCalculator("_", "empty") then
  1777. print(v)
  1778. else
  1779. write(v..", ")
  1780. end
  1781. end
  1782. os.pullEvent()
  1783. end
  1784. end
  1785. end
  1786.  
  1787. function placeFloor()
  1788. if settings.floor == true and turtle.detectDown() == false and #SlotCalculator("_", "minecraft:cobblestone") ~= 0 then
  1789. turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])
  1790. turtle.placeDown()
  1791. end
  1792. end
  1793.  
  1794. function placeWall(param)
  1795. if param == true then
  1796. param = "place"
  1797. else
  1798. param = param or "place"
  1799. end
  1800. if #SlotCalculator("_", "minecraft:cobblestone") > 0 then
  1801. turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])
  1802. turtle[param]()
  1803. return true
  1804. end
  1805. return false
  1806. end
  1807.  
  1808. -----###-----Processing-----###-----
  1809. function TorchCalculator()
  1810. local Tspace
  1811. if settings.torches == true then
  1812. if (settings.tunnelspace == 4 and settings.length <= 8) or (settings.tunnelspace == 3 and settings.length <= 10) then
  1813. settings.lateralTorches = 1
  1814. else
  1815. settings.lateralTorches = math.floor((settings.length-math.floor(16/settings.tunnelspace))/12)+1
  1816. end
  1817. if (settings.tunnelspace == 4 and settings.length <= 3) or (settings.tunnelspace == 3 and settings.length <= 4) then
  1818. settings.mainTorches = true
  1819. settings.lateralTorches = 0
  1820. 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
  1821. settings.mainTorches = true
  1822. else
  1823. settings.mainTorches = false
  1824. end
  1825. end
  1826. if settings.lateralTorches >= 1 then
  1827. if settings.mainTorches == true then
  1828. Tspace = round((settings.length+(settings.tunnelspace-1)-settings.lateralTorches)/(settings.lateralTorches+0.5), "u")
  1829. else
  1830. Tspace = (settings.length+(settings.tunnelspace-1)-settings.lateralTorches)/settings.lateralTorches
  1831. end
  1832. if Tspace == 11 then
  1833. variables.maxSpace = true
  1834. else
  1835. variables.maxSpace = false
  1836. end
  1837. local done = false
  1838. while not done do
  1839. variables.torchPositions = {}
  1840. table.insert(variables.torchPositions, round(Tspace/2, "d")+1)
  1841. for i = 2, settings.lateralTorches do
  1842. table.insert(variables.torchPositions, round(Tspace+1+variables.torchPositions[i-1], "d"))
  1843. end
  1844. if variables.torchPositions[#variables.torchPositions] > settings.length then
  1845. Tspace = Tspace - 0.1
  1846. else
  1847. done = true
  1848. end
  1849. end
  1850. else
  1851. variables.maxSpace = false
  1852. variables.torchPositions = {}
  1853. end
  1854. variables.TorchDemand = 2*(settings.lateralTorches*settings.quantity)+1
  1855. if settings.mainTorches == true then
  1856. variables.TorchDemand = variables.TorchDemand + settings.quantity
  1857. end
  1858. for k, v in ipairs(SlotCalculator("T", "empty")) do
  1859. variables.slots[v] = "_"
  1860. end
  1861. local stupid = SlotCalculator("_", "empty")
  1862. for k, v in ipairs(stupid) do
  1863. if k > #stupid-math.ceil(variables.TorchDemand/64) then
  1864. variables.slots[v] = "T"
  1865. end
  1866. end
  1867. end
  1868.  
  1869. function calculateFuelDemand()
  1870. if settings.chestSelect == 1 then
  1871. variables.FuelDemand = ((settings.length*2+settings.tunnelspace)*3+3)*settings.quantity
  1872. elseif settings.chestSelect == 2 then
  1873. variables.FuelDemand = math.ceil(((settings.length*2+settings.tunnelspace)*3+2)*settings.quantity+settings.tunnelspace*(settings.quantity/2)^2)
  1874. else
  1875. variables.FuelDemand = ((settings.length*2+settings.tunnelspace)*3+2)*settings.quantity
  1876. end
  1877. if variables.maxSpace == true then
  1878. variables.FuelDemand = variables.FuelDemand + #variables.torchPositions
  1879. end
  1880. end
  1881.  
  1882.  
  1883. -----###-----Core functions-----###-----
  1884. function update()
  1885. if not fs.exists("database/"..programName.."/state") then
  1886. save("database/"..programName.."/state", "0")
  1887. end
  1888. file = fs.open("database/"..programName.."/state", "r")
  1889. local fileData = {}
  1890. local line = file.readLine()
  1891. repeat
  1892. table.insert(fileData, line)
  1893. line = file.readLine()
  1894. until line == nil
  1895. file.close()
  1896. updated = fileData[1]
  1897.  
  1898. if updated == "0" then
  1899. kill = true
  1900. term.clear()
  1901. print("loading...")
  1902. shell.run("pastebin get cR9vEiTc database/"..programName.."/lang")
  1903. term.clear()
  1904. local function installAsStartup()
  1905. if fs.exists("startup") then
  1906. os.loadAPI("startup")
  1907. if startup.name == "SupHa - Startup Handler by BrunoZockt" then
  1908. for k, v in ipairs(startup.getList()) do
  1909. if v == programName then
  1910. return
  1911. end
  1912. end
  1913. startup.set(programName)
  1914. else
  1915. os.unloadAPI("startup")
  1916. fs.move("startup", "old_startup")
  1917. shell.run("pastebin get 19VG8eD6 startup")
  1918. os.loadAPI("startup")
  1919. startup.set("old_startup", "standart")
  1920. startup.set(programName)
  1921. end
  1922. else
  1923. shell.run("pastebin get 19VG8eD6 startup")
  1924. os.loadAPI("startup")
  1925. startup.set(programName)
  1926. end
  1927. end
  1928. installAsStartup()
  1929. if programName ~= "OCM" then
  1930. fs.delete("database/OCM")
  1931. end
  1932. if shell.run("database/"..programName.."/updaterV2") == false then
  1933. fs.delete("database/"..programName.."/updater")
  1934. term.clear()
  1935. print("loading...")
  1936. shell.run("pastebin get rUMt9siN database/"..programName.."/updaterV2")
  1937. term.clear()
  1938. shell.run("database/"..programName.."/updaterV2")
  1939. end
  1940. end
  1941. end
  1942.  
  1943. function getVariables(path)
  1944. local extSettings = {}
  1945. if fs.exists("database/"..programName.."/"..path) then
  1946. file = fs.open("database/"..programName.."/"..path, "r")
  1947. local line = Splitter(file.readLine(), " = ")
  1948. repeat
  1949. if line[2] == "{" or line[2] == "{}" then
  1950. local str = line[2]
  1951. if line[2] == "{" then
  1952. repeat
  1953. local tline = file.readLine()
  1954. if tline ~= nil then
  1955. str = str..tline
  1956. end
  1957. until tline == "}"
  1958. end
  1959. extSettings[line[1]] = textutils.unserialize(str)
  1960. else
  1961. extSettings[line[1]] = line[2]
  1962. end
  1963. line = Splitter(file.readLine(), " = ")
  1964. until line == nil
  1965. file.close()
  1966. for k, v in pairs(extSettings) do
  1967. if type(extSettings[k]) ~= "table" then
  1968. if not tonumber(extSettings[k]) then
  1969. if extSettings[k] == "true" or extSettings[k] == "false" then
  1970. extSettings[k] = extSettings[k] == "true"
  1971. end
  1972. else
  1973. extSettings[k] = tonumber(extSettings[k])
  1974. end
  1975. end
  1976. if Splitter(path, "/")[#Splitter(path, "/")] == "settings" then
  1977. settings[k] = extSettings[k]
  1978. elseif Splitter(path, "/")[#Splitter(path, "/")] == "variables" then
  1979. variables[k] = extSettings[k]
  1980. end
  1981. end
  1982. end
  1983. if fs.exists("database/"..programName.."/updateCheckbox/V2.6") then
  1984. local file = fs.open("database/"..programName.."/updateCheckbox/V2.6", "r")
  1985. checkbox = file.readLine() == "true"
  1986. file.close()
  1987. end
  1988. if checkbox == true then
  1989. menustate = "Home"
  1990. else
  1991. menustate = "Update"
  1992. end
  1993. if settings.chestSelect < 3 and #SlotCalculator("C", "empty") == 0 then
  1994. variables.slots[16] = "C"
  1995. end
  1996. calculateFuelDemand()
  1997. TorchCalculator()
  1998. end
  1999.  
  2000. function getList(path)
  2001. local file = fs.open("database/"..programName.."/"..path, "r")
  2002. todoList = textutils.unserialize(Splitter(file.readLine(), " = ")[2]..file.readAll())
  2003. file.close()
  2004. end
  2005.  
  2006. function saveVars(path, content)
  2007. save("database/"..programName.."/"..path, content)
  2008. end
  2009.  
  2010. function compStep(n)
  2011. if n == nil then
  2012. n = 1
  2013. else
  2014. n = tonumber(n)
  2015. end
  2016. for i = 1, n do
  2017. insert('turtle.select(SlotCalculator("T", "empty")[1])')
  2018. insert('Freeway()')
  2019. if variables.level == 0 then
  2020. insert('CompareAll("Compare()", "CompareBack()", "CompareUp()")')
  2021. insert('placeFloor()')
  2022. insert('turtle.select(SlotCalculator("T", "empty")[1])')
  2023. insert('FreewayUp()')
  2024. insert('CompareAll("Compare()", "CompareBack()", "CompareDown()")')
  2025. elseif variables.level == 1 then
  2026. insert('CompareAll("Compare()", "CompareBack()", "CompareDown()")')
  2027. insert('turtle.select(SlotCalculator("T", "empty")[1])')
  2028. insert('FreewayDown()')
  2029. insert('CompareAll("Compare()", "CompareBack()", "CompareUp()")')
  2030. insert('placeFloor()')
  2031. end
  2032. end
  2033. end
  2034.  
  2035. function mainstep(n, first)
  2036. if n == nil then
  2037. n = 1
  2038. else
  2039. n = tonumber(n)
  2040. end
  2041. turtle.select(SlotCalculator("_", "empty")[1])
  2042. for i = 1, n do
  2043. insert('variables.searching = false')
  2044. insert('dig()')
  2045. insert('Freeway()')
  2046. insert([[if variables.level == 0 then
  2047. insert('placeFloor()')
  2048. insert('digUp()')
  2049. if ]]..tostring(first)..[[ and ]]..tostring(i)..[[ == 1 or (settings.walls == true and ]]..tostring(i)..[[ == 2 and settings.tunnelspace == 4) then
  2050. insert('CompareAll("Compare()", "CompareBack()", "CompareUp()")')
  2051. else
  2052. insert('CompareDown()')
  2053. end
  2054. insert('FreewayUp()')
  2055. if ]]..tostring(first)..[[ and ]]..tostring(i)..[[ == 1 or (settings.walls == true and ]]..tostring(i)..[[ == 2 and settings.tunnelspace == 4) then
  2056. insert('CompareAll("Compare()", "CompareBack()", "CompareDown()")')
  2057. else
  2058. insert('CompareUp()')
  2059. insert('placeWall("placeUp")')
  2060. end
  2061. elseif variables.level == 1 then
  2062. insert('digDown()')
  2063. if ]]..tostring(first)..[[ and ]]..tostring(i)..[[ == 1 or (settings.walls == true and ]]..tostring(i)..[[ == 2 and settings.tunnelspace == 4) then
  2064. insert('CompareAll("Compare()", "CompareBack()", "CompareDown()")')
  2065. else
  2066. insert('CompareUp()')
  2067. insert('placeWall("placeUp")')
  2068. end
  2069. if i == 2 and settings.mainTorches then
  2070. insert('variables.searching = false')
  2071. insert('dig(true)')
  2072. end
  2073. insert('FreewayDown()')
  2074. if ]]..tostring(first)..[[ and ]]..tostring(i)..[[ == 1 or (settings.walls == true and ]]..tostring(i)..[[ == 2 and settings.tunnelspace == 4) then
  2075. insert('CompareAll("Compare()", "CompareBack()", "CompareUp()")')
  2076. else
  2077. insert('CompareDown()')
  2078. end
  2079. insert('placeFloor()')
  2080. end]])
  2081. if settings.mainTorches == true then
  2082. if i == 2 and #SlotCalculator('T', 'check') ~= 0 then
  2083. insert([[turtle.select(SlotCalculator('T', 'check')[1])
  2084. if variables.level == 1 then
  2085. FreewayDown()
  2086. end]])
  2087. insert([[if not turtle.placeUp() then
  2088. insert('FreewayUp()')
  2089. insert('left()')
  2090. insert('turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])')
  2091. insert('dig()')
  2092. insert('turtle.place()')
  2093. insert('right()')
  2094. insert('FreewayDown()')
  2095. insert('turtle.select(SlotCalculator("T", "check")[1])')
  2096. insert('turtle.placeUp()')
  2097. end]])
  2098. insert([[for k, v in ipairs(SlotCalculator('T', 'empty')) do
  2099. variables.slots[v] = '_'
  2100. end
  2101. local stupid = SlotCalculator('_', 'empty')
  2102. for k, v in ipairs(stupid) do
  2103. if k > #stupid-math.ceil(variables.TorchDemand/64) then
  2104. variables.slots[v] = 'T'
  2105. end
  2106. end
  2107. variables.TorchDemand = variables.TorchDemand - 1]])
  2108. end
  2109. end
  2110. end
  2111. end
  2112.  
  2113. function stepAside(n)
  2114. if n == nil then
  2115. n = 1
  2116. else
  2117. n = tonumber(n)
  2118. end
  2119. for i = 1, n do
  2120. insert('variables.searching = false')
  2121. insert('dig()')
  2122. insert('Freeway()')
  2123. if variables.level == 1 then
  2124. insert('digDown()')
  2125. elseif variables.level == 0 then
  2126. insert('placeFloor()')
  2127. insert('digUp()')
  2128. end
  2129. end
  2130. end
  2131.  
  2132. function youJustGotLittUp(steps, func, left)
  2133. if left == nil then
  2134. left = false
  2135. end
  2136. for Steprepeat = 1, steps do
  2137. if func == stepAside then
  2138. insert('stepAside()')
  2139. end
  2140. for k, v in ipairs(variables.torchPositions) do
  2141. if ((func == stepAside and settings.length-v+1 == Steprepeat) or (func == compStep and v == Steprepeat)) and #SlotCalculator("T", "check") > 0 then
  2142. insert([[turtle.select(SlotCalculator("T", "check")[1])
  2143. if variables.maxSpace == true then
  2144. if settings.mainTorches == false and left == true then
  2145. if k%2 == #variables.torchPositions%2 then
  2146. if variables.level == 1 then
  2147. if variables.orientation[1] == "North" or variables.orientation[1] == "South" then
  2148. insert('dig()')
  2149. end
  2150. insert('FreewayDown()')
  2151. elseif variables.orientation[1] == "North" or variables.orientation[1] == "South" then
  2152. insert('FreewayUp()')
  2153. insert('dig()')
  2154. insert('FreewayDown()')
  2155. end
  2156. else
  2157. if variables.level == 0 then
  2158. insert('FreewayUp()')
  2159. end
  2160. end
  2161. else
  2162. if k%2 == #variables.torchPositions%2 then
  2163. if variables.level == 0 then
  2164. insert('FreewayUp()')
  2165. end
  2166. else
  2167. if variables.level == 1 then
  2168. if variables.orientation[1] == "North" or variables.orientation[1] == "South" then
  2169. insert('dig()')
  2170. end
  2171. insert('FreewayDown()')
  2172. elseif variables.orientation[1] == "North" or variables.orientation[1] == "South" then
  2173. insert('FreewayDown()')
  2174. insert('dig()')
  2175. insert('FreewayUp()')
  2176. end
  2177. end
  2178. end
  2179. elseif variables.orientation[1] == "North" or variables.orientation[1] == "South" then
  2180. if variables.level == 0 then
  2181. insert('FreewayUp()')
  2182. end
  2183. end]])
  2184. insert([[if variables.level == 1 then
  2185. turtle.placeDown()
  2186. elseif variables.level == 0 then
  2187. if not turtle.placeUp() then
  2188. insert('FreewayUp()')
  2189. insert('left()')
  2190. insert('turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])')
  2191. insert('dig()')
  2192. insert('turtle.place()')
  2193. insert('right()')
  2194. insert('FreewayDown()')
  2195. insert('turtle.select(SlotCalculator("T", "check")[1])')
  2196. insert('turtle.placeUp()')
  2197. end
  2198. end]])
  2199. insert([[for k, v in ipairs(SlotCalculator("T", "empty")) do
  2200. variables.slots[v] = "_"
  2201. end
  2202. local stupid = SlotCalculator("_", "empty")
  2203. for k, v in ipairs(stupid) do
  2204. if k > #stupid-math.ceil(variables.TorchDemand/64) then
  2205. variables.slots[v] = "T"
  2206. end
  2207. end]])
  2208. insert([[if func == compStep then
  2209. variables.TorchDemand = variables.TorchDemand - 1
  2210. end
  2211. turtle.select(SlotCalculator("_", "empty")[1])]])
  2212. end
  2213. end
  2214. if func == compStep then
  2215. if Steprepeat == settings.length then
  2216. insert('Freeway()')
  2217. else
  2218. insert('compStep()')
  2219. end
  2220. end
  2221. end
  2222. end
  2223.  
  2224. function tunnel(first)
  2225. if settings.Autofuel == true then
  2226. insert('Fuel()')
  2227. end
  2228. if settings.trash == true then
  2229. insert('trash()')
  2230. end
  2231. if settings.chestSelect == 1 then
  2232. insert('Enderchest()')
  2233. elseif settings.chestSelect == 2 then
  2234. insert('print("EXECUTE NORMAL CHEST")')
  2235. insert('NormalChest()')
  2236. end
  2237. insert("mainstep(settings.tunnelspace, "..tostring(first)..")")
  2238. insert("turtle.turnRight()")
  2239. insert('old_orientation = {}')
  2240. insert([[for k,v in ipairs(variables.orientation) do
  2241. old_orientation[k] = v
  2242. end]])
  2243. for i = 1, 4 do
  2244. insert('variables.orientation['..tostring(i)..'] = old_orientation[('..tostring(i)..'+2)%4+1]')
  2245. end
  2246. insert("youJustGotLittUp(settings.length, stepAside)")
  2247. insert([[if variables.level == 1 then
  2248. insert('CompareAll("CompareBack()", "CompareDown()")')
  2249. insert('FreewayDown()')
  2250. insert('CompareAll("CompareBack()", "CompareUp()")')
  2251. else
  2252. insert('CompareAll("CompareBack()", "CompareUp()")')
  2253. insert('FreewayUp()')
  2254. insert('CompareAll("CompareBack()", "CompareDown()")')
  2255. end]])
  2256. insert('face(3)')
  2257. insert('old_orientation = {}')
  2258. insert([[for k,v in ipairs(variables.orientation) do
  2259. old_orientation[k] = v
  2260. end]])
  2261. for i = 1, 4 do
  2262. insert('variables.orientation['..tostring(i)..'] = old_orientation[('..tostring(i)..'+1)%4+1]')
  2263. end
  2264. insert('variables.direction = 1')
  2265. insert("youJustGotLittUp(settings.length, compStep)")
  2266. insert("youJustGotLittUp(settings.length, stepAside, true)")
  2267. insert([[if variables.level == 1 then
  2268. insert('CompareAll("CompareBack()", "CompareDown()")')
  2269. insert('FreewayDown()')
  2270. insert('CompareAll("CompareBack()", "CompareUp()")')
  2271. else
  2272. insert('CompareAll("CompareBack()", "CompareUp()")')
  2273. insert('FreewayUp()')
  2274. insert('CompareAll("CompareBack()", "CompareDown()")')
  2275. end]])
  2276. insert('face(3)')
  2277. insert('old_orientation = {}')
  2278. insert([[for k,v in ipairs(variables.orientation) do
  2279. old_orientation[k] = v
  2280. end]])
  2281. for i = 1, 4 do
  2282. insert('variables.orientation['..tostring(i)..'] = old_orientation[('..tostring(i)..'+1)%4+1]')
  2283. end
  2284. insert('variables.direction = 1')
  2285. insert("youJustGotLittUp(settings.length, compStep, true)")
  2286. insert('turtle.turnLeft()')
  2287. insert('old_orientation = {}')
  2288. insert([[for k,v in ipairs(variables.orientation) do
  2289. old_orientation[k] = v
  2290. end]])
  2291. for i = 1, 4 do
  2292. insert('variables.orientation['..tostring(i)..'] = old_orientation[('..tostring(i)..')%4+1]')
  2293. end
  2294. end
  2295.  
  2296. function go()
  2297. saveVars("resume/settings", settings)
  2298. variables.startDay = os.day()
  2299. variables.startTime = os.time()
  2300. for Tunnelrepeat = 1, settings.quantity do
  2301. insert("tunnel("..tostring(Tunnelrepeat == 1)..")")
  2302. insert([[variables.CrosswayAmount = variables.CrosswayAmount + 1
  2303. print(lang.status(settings.language, 8, variables.CrosswayAmount, settings.quantity))]])
  2304. end
  2305. insert('print(lang.status(settings.language, 9))')
  2306. insert('turn()')
  2307. insert([[if variables.level == 1 then
  2308. FreewayDown()
  2309. end]])
  2310. for Way_Back = 1, settings.quantity*settings.tunnelspace do
  2311. insert('Freeway()')
  2312. end
  2313. if settings.trash == true then
  2314. insert('trash()')
  2315. end
  2316. if settings.chestSelect == 1 then
  2317. insert("Enderchest(true)")
  2318. elseif settings.chestSelect == 2 then
  2319. insert('print("EXECUTE NORMAL CHEST")')
  2320. insert("NormalChest(true, true)")
  2321. end
  2322. insert([[local endDay = os.day()
  2323. local endTime = os.time()
  2324. variables.stats["time"] = (endDay-variables.startDay)*24.000+(endTime-variables.startTime)]])
  2325. end
  2326.  
  2327. function Navigation()
  2328. table.insert(timer, os.startTimer(0.05))
  2329. while true do
  2330. local tempState = menustate
  2331. local event, p1, p2, p3 = os.pullEvent()
  2332. while (event == "timer" and p1 ~= timer[#timer]) or event == "key_up" do
  2333. event, p1, p2, p3 = os.pullEvent()
  2334. end
  2335. if menuVars["drawOptions"].focus == 100 then
  2336. basicInputHandler(menu[menustate].orientation, event, p1)
  2337. end
  2338. if menustate == "Quit" then
  2339. break
  2340. elseif menustate == "Save as default" then
  2341. saveVars("settings", settings)
  2342. menuVars["drawOptions"].saved = true
  2343. menustate = "Options"
  2344. elseif menustate == "Go!" then
  2345. menustate = "Popup"
  2346. local ready = true
  2347. for i = 1, #errors do
  2348. if errors[i] == true then
  2349. ready = false
  2350. end
  2351. end
  2352. if (Fuellevel ~= "low" and ready == true) or tempState == "Popup" then
  2353. return execute()
  2354. end
  2355. end
  2356. term.clear()
  2357. drawHeader()
  2358. if tempState == menustate then
  2359. menu[menustate].draw(event, p1, p2, p3)
  2360. else
  2361. menu[menustate].draw()
  2362. end
  2363. if tempState == "Update" then
  2364. save("database/"..programName.."/updateCheckbox/V2.6", checkbox)
  2365. end
  2366. table.insert(timer, os.startTimer(0.5))
  2367. end
  2368. end
  2369.  
  2370. function extractstats()
  2371. save("database/"..programName.."/variables.stats", variables.stats)
  2372. end
  2373.  
  2374. function close()
  2375. fs.delete("database/"..programName.."/resume")
  2376. term.clear()
  2377. term.setCursorPos(1,1)
  2378. if Color() then
  2379. term.setTextColor(colors.yellow)
  2380. print(os.version())
  2381. term.setTextColor(colors.white)
  2382. else
  2383. print(os.version())
  2384. end
  2385. term.setCursorPos(1, 2)
  2386. end
  2387.  
  2388. -----###-----Executive-----###------
  2389.  
  2390. local function compile(chunk) -- returns compiled chunk or nil and error message
  2391. if type(chunk) ~= "string" then
  2392. error("expected string, got ".. type(chunk), 2)
  2393. end
  2394.  
  2395. local function findChunkName(var)
  2396. for k,v in pairs(HOST_ENV) do
  2397. if v==var then
  2398. return k
  2399. end
  2400. end
  2401. return "Unknown chunk"
  2402. end
  2403.  
  2404. return load(chunk, findChunkName(chunk), "t", OUR_ENV)
  2405. end
  2406.  
  2407. function getOrientation(resume)
  2408. if resume then
  2409. for i = 1, 2-variables.level do
  2410. insert('FreewayUp()')
  2411. end
  2412. end
  2413. if #SlotCalculator("T", "check") ~= 0 then
  2414. insert('Freeway()')
  2415. if Version >= 1.64 then
  2416. insert('FreewayUp()')
  2417. for i = 1, 3 do
  2418. insert('right()')
  2419. insert('dig(true)')
  2420. end
  2421. insert('right()')
  2422. insert([[if turtle.detect() == false then
  2423. turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])
  2424. turtle.place()
  2425. end]])
  2426. insert('FreewayDown()')
  2427. insert('turtle.select(SlotCalculator("T", "check")[1])')
  2428. insert('turtle.placeUp()')
  2429.  
  2430. insert('torch = {"West", "East", "North", "South"}')
  2431. insert('_, data = turtle.inspectUp()')
  2432. insert('new_orientation = torch[data.metadata]')
  2433.  
  2434. insert('digUp()')
  2435. insert('FreewayBack()')
  2436. insert('_, data, torch = nil, nil, nil')
  2437. else
  2438. insert('Freeway()')
  2439. insert('digDown()')
  2440. insert('FreewayUp()')
  2441. for i = 1, 4 do
  2442. insert([[if turtle.detect() == false then
  2443. turtle.select(SlotCalculator("_", "minecraft:cobblestone")[1])
  2444. turtle.place()
  2445. end]])
  2446. insert('right()')
  2447. end
  2448. insert('FreewayDown()')
  2449. insert('turtle.select(SlotCalculator("T", "check")[1])')
  2450. insert('turtle.placeUp()')
  2451.  
  2452. insert('torch = {"West", "South", "East", "North"}')
  2453. for i = 1, 4 do
  2454. insert('Freeway()')
  2455. insert('digUp()')
  2456. insert('os.sleep(0.5)')
  2457. insert('FreewayBack()')
  2458. insert([[if turtle.detectUp() == false then
  2459. i = ]]..tostring(i)..[[
  2460. insert('turtle.select(SlotCalculator("T", "check")[1])')
  2461. insert('turtle.suckDown()')
  2462. insert('new_orientation = torch[i]')
  2463. insert('i = nil')
  2464. end]])
  2465. insert('turtle.turnLeft()')
  2466. end
  2467. insert('face(variables.direction)')
  2468. insert('FreewayBack()')
  2469. end
  2470. end
  2471. if resume then
  2472. for i = 1, 2-variables.level do
  2473. insert('FreewayDown()')
  2474. end
  2475. insert([[for k, v in pairs(cardinal) do
  2476. if v == new_orientation then
  2477. new_orientation = k
  2478. end
  2479. if v == variables.orientation[variables.direction] then
  2480. variables.orientation[variables.direction] = k
  2481. end
  2482. end]])
  2483. insert([[if new_orientation ~= variables.orientation[variables.direction] then
  2484. if math.abs(new_orientation-variables.orientation[variables.direction]) == 2 then
  2485. insert('turtle.turnLeft()')
  2486. insert('turtle.turnLeft()')
  2487. elseif (new_orientation-variables.orientation[variables.direction]+1)%4 == 0 then
  2488. insert('turtle.turnLeft()')
  2489. elseif (new_orientation-variables.orientation[variables.direction]-1)%4 == 0 then
  2490. insert('turtle.turnRight()')
  2491. end
  2492. end]])
  2493. insert('variables.orientation[variables.direction] = cardinal[variables.orientation[variables.direction]]')
  2494. else
  2495. insert([[for k, v in ipairs(cardinal) do
  2496. if new_orientation == v then
  2497. for i = 1, 4 do
  2498. table.insert(variables.orientation, cardinal[(k+i-2)%4+1])
  2499. end
  2500. end
  2501. end]])
  2502. end
  2503. end
  2504.  
  2505. function execute(resume)
  2506. if not resume then
  2507. todoList = {"go()"}
  2508. end
  2509. table.insert(todoList, 1, 'getOrientation('..tostring(resume)..')')
  2510. while #todoList > 0 do
  2511. compile(todoList[1])()
  2512. table.remove(todoList, 1)
  2513. variables.index = 2
  2514. save("database/"..programName.."/resume/todoList", todoList, true)
  2515. saveVars("resume/variables", variables)
  2516. end
  2517. end
  2518.  
  2519. function main()
  2520. if fs.exists("database/"..programName.."/resume") then
  2521. os.loadAPI("database/"..programName.."/lang")
  2522. local countdown = 10
  2523. local count = {}
  2524. term.clear()
  2525. drawResume(countdown)
  2526. table.insert(count, os.startTimer(1))
  2527. repeat
  2528. local event, p1 = os.pullEvent()
  2529. while (event == "timer" and p1 ~= count[#count]) do
  2530. event, p1 = os.pullEvent()
  2531. end
  2532. if event == "key" then
  2533. if p1 == 28 then
  2534. fs.delete("database/"..programName.."/resume")
  2535. return main()
  2536. end
  2537. elseif event == "timer" and p1 == count[#count] then
  2538. countdown = countdown - 1
  2539. end
  2540. term.clear()
  2541. drawResume(countdown)
  2542. table.insert(count, os.startTimer(1))
  2543. until countdown == 0
  2544. getVariables("resume/settings")
  2545. getVariables("resume/variables")
  2546. getList("resume/todoList")
  2547. execute(true)
  2548. else
  2549. --update()
  2550. if kill == true then
  2551. return
  2552. end
  2553. save("database/"..programName.."/state", "0")
  2554. os.loadAPI("database/"..programName.."/lang")
  2555. getVariables("settings")
  2556. Navigation()
  2557. end
  2558. --extractstats()
  2559. close()
  2560. end
  2561.  
  2562. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement