Advertisement
Guest User

Untitled

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