Advertisement
criz

ORE COLLECTING MINER V2.7.1 - Modified

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