Advertisement
Guest User

mine

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