Advertisement
Guest User

mine

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