Advertisement
Thanateros

Untitled

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