karelvysinka

COLLECTING MINER V2.5.1 by BrunoZockt

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