longlostbro

OCM

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