Advertisement
Guest User

Untitled

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