Advertisement
Jkerr

Advanced Ore Finder by Henness v3.1

Jun 13th, 2021
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.52 KB | None | 0 0
  1. -- Advanced Ore Finder by Henness
  2. -- Version 3.1 1/12/2014
  3.  
  4. -- Config
  5. local program = "Advanced Orefinder"
  6. local version = "v3.1"
  7. local author = "Henness"
  8. local tSave = {}
  9.  
  10. local ores_mined, tCordsInput, select, screenw, screenh, fuel_level, _sFile
  11.  
  12. screenw,screenh = term.getSize()
  13.  
  14. -- Functions
  15.  
  16. --[[
  17.     Most of the loc movement functions were written by Mikeemoo,
  18.     for his killer program. If you would like to see his program
  19.     you can download it from: http://pastebin.com/UCES36jD
  20. ]]
  21.  
  22. local loc = {}
  23. loc = {
  24.     paused = false,
  25.    
  26.     x = 0,
  27.     y = 0,
  28.     z = 0,
  29.     facing = 0,
  30.    
  31.     facingToAxis = {
  32.         [0] = { axis = 'z', unit = 1 },
  33.         [1] = { axis = 'x', unit = -1 },
  34.         [2] = { axis = 'z', unit = -1 },
  35.         [3] = { axis = 'x', unit = 1 }
  36.     },
  37.    
  38.     pause = function()
  39.         while loc.paused do
  40.             sleep(1)
  41.         end
  42.     end,
  43.    
  44.     getAxisForFacing = function()
  45.         return loc.facingToAxis[loc.facing]['axis'], loc.facingToAxis[loc.facing]['unit']
  46.     end,
  47.  
  48.     turnLeft = function()
  49.         loc.pause()
  50.         loc.facing = (loc.facing - 1) % 4
  51.         turtle.turnLeft()
  52.     end,
  53.  
  54.     turnRight = function()
  55.         loc.pause()
  56.         loc.facing = (loc.facing + 1) % 4
  57.         turtle.turnRight()
  58.     end,
  59.  
  60.     moveForward = function()
  61.         loc.pause()
  62.         if turtle.forward() then
  63.             local axis, unit = loc.getAxisForFacing()
  64.             loc[axis] = loc[axis] + unit
  65.             return true
  66.         end
  67.         return false
  68.     end,
  69.    
  70.     moveBack = function()
  71.         loc.pause()
  72.         if turtle.back() then
  73.             local axis, unit = loc.getAxisForFacing()
  74.             loc[axis] = loc[axis] - unit
  75.             return true
  76.         end
  77.         return false
  78.     end,
  79.  
  80.     face = function(faceto)
  81.         local dirdif = (faceto - loc.facing) % 4
  82.         if dirdif == 1 then
  83.             loc.turnRight()
  84.         elseif dirdif == 2 then
  85.             loc.turnRight()
  86.             loc.turnRight()
  87.         elseif dirdif == 3 then
  88.             loc.turnLeft()
  89.         end
  90.     end,
  91.  
  92.     movez = function(d)
  93.         if d < loc.z then loc.face(2) elseif d > loc.z then loc.face(0) end
  94.         return loc.moveForward()
  95.     end,
  96.  
  97.     movex = function(d)
  98.         if d < loc.x then loc.face(1) elseif d > loc.x then loc.face(3) end
  99.         return loc.moveForward()
  100.     end,
  101.  
  102.     movey = function(d)
  103.         if d < loc.y then
  104.             return loc.moveDown()
  105.         end
  106.         return loc.moveUp()
  107.     end,
  108.  
  109.     moveUp = function()
  110.         loc.pause()
  111.         if turtle.up() then
  112.             loc.y = loc.y + 1
  113.             return true
  114.         end
  115.         return false
  116.     end,
  117.  
  118.     moveDown = function()
  119.         loc.pause()
  120.         if turtle.down() then
  121.             loc.y = loc.y - 1
  122.             return true
  123.         end
  124.         return false
  125.     end,
  126.  
  127.     moveTo = function(x, y, z, facing)
  128.         if y > loc.y then
  129.             while loc.y < y do
  130.                 while not loc.moveUp() do
  131.                     if turtle.detectUp() then
  132.                         turtle.select(1)
  133.                         turtle.digUp()
  134.                     else
  135.                         turtle.attackUp()
  136.                     end
  137.                 end
  138.             end
  139.         end
  140.         while x ~= loc.x do
  141.             while not loc.movex(x) do
  142.                 if turtle.detect() then
  143.                     turtle.select(1)
  144.                     turtle.dig()
  145.                 else
  146.                     turtle.attack()
  147.                 end
  148.             end
  149.         end
  150.         while z ~= loc.z do
  151.             while not loc.movez(z) do
  152.                 if turtle.detect() then
  153.                     turtle.select(1)
  154.                     turtle.dig()
  155.                 else
  156.                     turtle.attack()
  157.                 end
  158.             end
  159.         end
  160.         if y < loc.y then
  161.             while loc.y > y do
  162.                 while not loc.moveDown() do
  163.                     if turtle.detectDown() then
  164.                         turtle.select(1)
  165.                         turtle.digDown()
  166.                     else
  167.                         turtle.attackDown()
  168.                     end
  169.                 end
  170.             end
  171.         end
  172.         loc.face(facing)
  173.         return true
  174.     end,
  175.    
  176.     moveToPos = function(pos)
  177.         return loc.moveTo(pos.x, pos.y, pos.z, pos.facing)
  178.     end,
  179.  
  180.     distanceTo = function(x, y, z)
  181.         return math.abs(x) - loc.x + math.abs(y) - loc.y + math.abs(z) - loc.z
  182.     end,
  183.  
  184.     distanceToPos = function(pos)
  185.         return loc.distanceTo(pos.x, pos.y, pos.z)
  186.     end
  187. }
  188.  
  189. -- Orefinder
  190. function saveTable(table,name)
  191.     local file = fs.open(name,"w")
  192.     file.write(textutils.serialize(table))
  193.     file.close()
  194. end
  195.  
  196. function loadTable(name)
  197.     local file = fs.open(name,"r")
  198.     local data = file.readAll()
  199.     file.close()
  200.     return textutils.unserialize(data)
  201. end
  202.  
  203. function moveDown(h)
  204.     while not loc.movey(h) do
  205.         if turtle.detectDown() then
  206.             turtle.digDown()
  207.             if turtle.detectDown() then
  208.                 return false
  209.             end
  210.         else
  211.             turtle.attackDown()
  212.         end
  213.     end
  214.     return true
  215. end
  216.  
  217. function compareForward(a, b)
  218.     loc.pause()
  219.     for i=a,b do
  220.         turtle.select(i)
  221.         if turtle.compare() then
  222.             return false
  223.         end            
  224.     end
  225.     return true
  226. end
  227.  
  228. function findDown(d)
  229.     if not d then d = loc.y end
  230.     local h = loc.y - d
  231.     while loc.y ~= h do
  232.         if not moveDown(h) then
  233.             break
  234.         end
  235.         for j=1,4 do
  236.             if compareForward(1, tSave.ignore) then
  237.                 if not space() then
  238.                     returnToChest()
  239.                 end
  240.                 turtle.select(1)
  241.                 turtle.dig()
  242.                 ores_mined = ores_mined + 1
  243.             end
  244.             loc.turnRight()
  245.         end
  246.     end
  247. end
  248.  
  249. function refuel(ammount)
  250.     if turtle.getFuelLevel() == "unlimited" then
  251.         return true
  252.     end
  253.     local needed = ammount or loc.distanceToPos(tSave.startPos) * 2 + 1
  254.     if turtle.getFuelLevel() < needed then
  255.         for n=tSave.ignore+1,16 do
  256.             loc.pause()
  257.             if turtle.getItemCount(n) > 0 then
  258.                 turtle.select(n)
  259.                 if turtle.refuel(1) then
  260.                     while turtle.getItemCount(n) > 0 and turtle.getFuelLevel() < needed do
  261.                         turtle.refuel(1)
  262.                     end
  263.                     if turtle.getFuelLevel() >= needed then
  264.                         turtle.select(1)
  265.                         return true
  266.                     end
  267.                 end
  268.             end
  269.         end
  270.         turtle.select(1)
  271.         return false
  272.     end
  273.     return true
  274. end
  275.  
  276. function unload()
  277.     for n=1,16 do
  278.         loc.pause()
  279.         if turtle.getItemCount(n) > 0 then
  280.             turtle.select(n)
  281.             if n <= tSave.ignore then
  282.                 if (not tSave.safemode  and n == 1) or n > 1 then
  283.                     turtle.drop(turtle.getItemCount(n) - 1)
  284.                 end
  285.             else
  286.                 turtle.drop()
  287.             end
  288.         end
  289.     end
  290.     turtle.select(1)
  291. end
  292.  
  293. function space()
  294.     for n=1,16 do
  295.         if turtle.getItemCount(n) == 0 then
  296.             return true
  297.         end
  298.     end
  299.     return false
  300. end
  301.  
  302. function returnToChest()
  303.     local returnPos = {x = loc.x, y = loc.y, z = loc.z, facing = loc.facing}
  304.     local fuelNeeded = loc.distanceToPos(tSave.startPos) * 2 + 1
  305.     loc.moveToPos(tSave.startPos)
  306.     loc.face((loc.facing + 2) % 4)
  307.     if not refuel(fuelNeeded) then
  308.         unload()
  309.         while not refuel(fuelNeeded) do
  310.             loc.pause()
  311.             sleep(1)
  312.         end
  313.     else
  314.         unload()   
  315.     end
  316.     loc.moveToPos(returnPos)
  317. end
  318.  
  319. function forward()
  320.     if not space() then
  321.         returnToChest()
  322.     end
  323.     while not loc.moveForward() do
  324.         if turtle.detect() then
  325.             turtle.select(1)
  326.             turtle.dig()
  327.         else
  328.             turtle.attack()
  329.         end
  330.     end
  331. end
  332.  
  333. function oreFinder()
  334.     loc.moveToPos(tSave.returnPos)
  335.     while tSave.w <= tSave.width do
  336.         while tSave.l <= tSave.length do
  337.             if not refuel() or not space() then
  338.                 returnToChest()
  339.             end
  340.             if math.fmod((loc.x + 4) - (loc.z - 1) * 2, 5) == 0 then
  341.                 tSave.returnPos = {x = loc.x, y = loc.y, z = loc.z, facing = loc.facing}
  342.                 saveTable( tSave, _sFile )
  343.                 findDown()
  344.                 loc.moveToPos(tSave.returnPos)
  345.                 if tSave.safemode then
  346.                     turtle.select(1)
  347.                     turtle.placeDown()
  348.                 end
  349.             end
  350.             turtle.select(1)
  351.             turtle.digUp()
  352.             if tSave.l ~= tSave.length then
  353.                 forward()
  354.             elseif tSave.l == tSave.length and tSave.w ~= tSave.width then
  355.                 if loc.facing == tSave.startPos.facing then
  356.                     loc.turnRight()
  357.                     forward()
  358.                     loc.turnRight()
  359.                 else
  360.                     loc.turnLeft()
  361.                     forward()
  362.                     loc.turnLeft()
  363.                 end
  364.             end
  365.             tSave.l = tSave.l + 1
  366.         end
  367.         tSave.w = tSave.w + 1
  368.         tSave.l = 1
  369.     end
  370.     loc.moveToPos(tSave.startPos)
  371.     returnToChest()
  372.     fs.delete(_sFile)
  373.     return true
  374. end
  375.  
  376. -- GUI
  377. function printNormal(str, xpos, ypos)
  378.     term.setCursorPos(xpos, ypos)
  379.     term.write (str)
  380. end
  381.  
  382. function printReverse(str, xpos, ypos)
  383.     term.setCursorPos(xpos - (#str-1), ypos)
  384.     term.write (str)
  385. end
  386.  
  387. function printLeft(str, ypos)
  388.     term.setCursorPos(1, ypos)
  389.     term.write(str)
  390. end
  391.  
  392. function printCentered(str, ypos)
  393.     term.setCursorPos(screenw/2 - #str/2 + 1, ypos)
  394.     term.write(str)
  395. end
  396.  
  397. function printRight(str, ypos)
  398.     term.setCursorPos(screenw - #str, ypos)
  399.     term.write(str)
  400. end
  401.  
  402. function readLines( sLines, _sReplaceChar )
  403.     term.setCursorBlink( true )
  404.     local w, h = term.getSize()
  405.     local nPos = 0
  406.     local nSelect = 1
  407.     local vSelect = 1
  408.     local function redraw( _sCustomReplaceChar )
  409.         local nScroll = 0
  410.         if sLines[nSelect].sx + nPos >= w then
  411.             nScroll = (sLines[nSelect].sx + nPos) - w
  412.         end
  413.         term.setCursorPos( sLines[nSelect].sx, sLines[nSelect].sy )
  414.         local sReplace = _sCustomReplaceChar or _sReplaceChar
  415.         if sReplace then
  416.             term.write( string.rep(sReplace, string.len(sLines[nSelect].text) - nScroll) )
  417.         else
  418.             term.write( string.sub( sLines[nSelect].text, nScroll + 1 ) )
  419.         end
  420.         term.setCursorPos( sLines[nSelect].sx + nPos - nScroll, sLines[nSelect].sy )
  421.     end
  422.     for nVar, tVar in ipairs(sLines) do
  423.         nSelect = nVar
  424.         redraw()
  425.         if tVar.text ~= "" then
  426.             vSelect = nVar
  427.         end
  428.     end
  429.     nSelect = vSelect
  430.     nPos = #sLines[nSelect].text
  431.     redraw()
  432.     while true do
  433.         local sEvent, param = os.pullEvent()
  434.         if sEvent == "char" then
  435.             sLines[nSelect].text = string.sub( sLines[nSelect].text, 1, nPos ) .. param .. string.sub( sLines[nSelect].text, nPos + 1 )
  436.             nPos = nPos + 1
  437.             redraw()
  438.         elseif sEvent == "key" then
  439.             if param == keys.enter then
  440.                 -- Enter
  441.                 if nSelect < #sLines then
  442.                     nSelect = nSelect + 1
  443.                     if sLines[nSelect].text == "" then
  444.                         nPos = 0
  445.                     else
  446.                         nPos = #sLines[nSelect].text
  447.                     end
  448.                     redraw()
  449.                 else
  450.                     break
  451.                 end
  452.             elseif param == keys.left then
  453.                 -- Left
  454.                 if nPos > 0 then
  455.                     nPos = nPos - 1
  456.                     redraw()
  457.                 end
  458.             elseif param == keys.right then
  459.                 -- Right               
  460.                 if nPos < string.len(sLines[nSelect].text) then
  461.                     nPos = nPos + 1
  462.                     redraw()
  463.                 end
  464.             elseif param == keys.up or param == keys.down then
  465.                 -- Up or down
  466.                 if param == keys.up then
  467.                     -- Up
  468.                     if nSelect > 1 then
  469.                         nSelect = nSelect - 1
  470.                         if sLines[nSelect].text == "" then
  471.                             nPos = 0
  472.                         else
  473.                             nPos = #sLines[nSelect].text
  474.                         end
  475.                         redraw()
  476.                     end
  477.                 else
  478.                     -- Down
  479.                     if nSelect < #sLines then
  480.                         nSelect = nSelect + 1
  481.                         if sLines[nSelect].text == "" then
  482.                             nPos = 0
  483.                         else
  484.                             nPos = #sLines[nSelect].text
  485.                         end
  486.                         redraw()
  487.                     else
  488.                         break
  489.                     end
  490.                 end
  491.                 redraw()
  492.             elseif param == keys.backspace then
  493.                 -- Backspace
  494.                 if nPos > 0 then
  495.                     redraw(" ");
  496.                     sLines[nSelect].text = string.sub( sLines[nSelect].text, 1, nPos - 1 ) .. string.sub( sLines[nSelect].text, nPos + 1 )
  497.                     nPos = nPos - 1                
  498.                     redraw()
  499.                 end
  500.             elseif param == keys.home then
  501.                 -- Home
  502.                 nPos = 0
  503.                 redraw()       
  504.             elseif param == keys.delete then
  505.                 if nPos < string.len(sLines[nSelect].text) then
  506.                     redraw(" ");
  507.                     sLines[nSelect].text = string.sub( sLines[nSelect].text, 1, nPos ) .. string.sub( sLines[nSelect].text, nPos + 2 )             
  508.                     redraw()
  509.                 end
  510.             elseif param == keys["end"] then
  511.                 -- End
  512.                 nPos = string.len(sLines[nSelect].text)
  513.                 redraw()
  514.             end
  515.         end
  516.     end
  517.     term.setCursorBlink( false )
  518.     return sLines
  519. end
  520.  
  521. local function findModem()
  522.   for _, v in pairs( rs.getSides() ) do
  523.         if peripheral.isPresent( v ) and peripheral.getType( v ) == "modem" then
  524.           return true, v
  525.         end
  526.   end
  527.   return false, nil
  528. end
  529.  
  530. local function locate()
  531.     local x,y,z,facing
  532.     local exist, side = findModem()
  533.     if exist then
  534.         rednet.open(side)
  535.         printCentered("Receiving coordinates from host...", 4)
  536.         x,y,z = gps.locate(3)
  537.         if x and y and z then
  538.             forward()
  539.             local tmpx,tmpy,tmpz = gps.locate(3)
  540.             if tmpx > x then
  541.                 facing = 3
  542.             elseif tmpx < x then
  543.                 facing = 1
  544.             elseif tmpz > z then
  545.                 facing = 0
  546.             elseif tmpz < z then
  547.                 facing = 2
  548.             end
  549.             printCentered("At:"..x.."/"..y.."/"..z.."/"..facing,3)
  550.             loc.moveBack()
  551.             return x,y,z,facing
  552.         else
  553.             printCentered("Unable to get GPS cords.  Please,", 3)
  554.             printCentered("enter the turtles cords manually.", 4)
  555.         end
  556.     else
  557.         printCentered("No wireless modem found, please", 3)
  558.         printCentered("enter the cords manualy.", 4)
  559.     end
  560.     printLeft("     x: ", 6)
  561.     printLeft("     y: ", 7)
  562.     printLeft("     z: ", 8)
  563.     printLeft("  face: ", 9)
  564.     while true do
  565.         readLines( tCordsInput )
  566.         x,y,z,facing = tonumber(tCordsInput[1].text),tonumber(tCordsInput[2].text),tonumber(tCordsInput[3].text),tonumber(tCordsInput[4].text)
  567.         if x ~= nil and y ~= nil and y > 0 and y < 256 and z ~= nil and facing ~= nil and facing < 4 and facing >= 0 then
  568.             return x,y,z,facing
  569.         end
  570.     end
  571. end
  572.  
  573. local function drawHeader()
  574.     printCentered(program, 1)
  575.     printLeft(string.rep("-", screenw), 2)
  576.     printLeft("["..version.."]"..string.rep("-", screenw-#author-#version-7).."[by "..author.."]", screenh)
  577. end
  578.  
  579. local function drawMainMenu()
  580.     term.clear()
  581.     drawHeader()
  582.     printLeft(string.rep("-", screenw), screenh-2)
  583.     if loc.paused then
  584.         if select == 1 then
  585.             printCentered("[RESUME]  REFUEL   SAVE   EXIT ", screenh-1)
  586.         elseif select == 2 then
  587.             printCentered(" RESUME  [REFUEL]  SAVE   EXIT ", screenh-1)
  588.         elseif select == 3 then
  589.             printCentered(" RESUME   REFUEL  [SAVE]  EXIT ", screenh-1)
  590.         elseif select == 4 then
  591.             printCentered(" RESUME   REFUEL   SAVE  [EXIT]", screenh-1)
  592.         end
  593.     else
  594.         printCentered("[PAUSE]", screenh-1)
  595.     end
  596. end
  597.  
  598. local function drawGPSMenu()
  599.     if select == 2 then
  600.         printCentered("[DONE]", screenh-1)
  601.     elseif select == 1 then
  602.         term.clear()
  603.         drawHeader()
  604.         printLeft(string.rep("-", screenw), screenh-2)
  605.         printCentered(" DONE ", screenh-1)
  606.         loc.x,loc.y,loc.z,loc.facing = locate()
  607.         select = 2
  608.         drawGPSMenu()
  609.     end
  610. end
  611.  
  612. local function drawRefuelMenu()
  613.     local refuelList = {
  614.         "+-------------------------------+",
  615.         "|    Are you sure you want to   |",
  616.         "|       refuel the turtle.      |",
  617.         "|                               |",
  618.         "|        YES          NO        |",
  619.         "+-------------------------------+"
  620.     }
  621.     for i=1,#refuelList do
  622.         if i == #refuelList-1 then
  623.             if select == 1 then
  624.                 printCentered("|       [YES]         NO        |", 3 + i)
  625.             elseif select == 2 then
  626.                 printCentered("|        YES         [NO]       |", 3 + i)
  627.             end
  628.         else
  629.             printCentered(refuelList[i], 3 + i)
  630.         end
  631.     end
  632. end
  633.  
  634. local function drawRefuel()
  635.     local refuelList = {
  636.         "+-------------------------------+",
  637.         "|      Turtle fuel level is     |",
  638.         "|                               |",
  639.         "|                               |",
  640.         "|              OK               |",
  641.         "+-------------------------------+"
  642.     }
  643.     for i=1,#refuelList do
  644.         if i == #refuelList-1 then
  645.             printCentered("|             [OK]              |", 3 + i)
  646.         elseif i == #refuelList-3 then
  647.             printCentered(refuelList[i], 3 + i)
  648.             printCentered(fuel_level, 3 + i)
  649.         else
  650.             printCentered(refuelList[i], 3 + i)
  651.         end
  652.     end
  653. end
  654.  
  655. local function drawSaveMenu()
  656.     local saveList = {
  657.         "+-------------------------------+",
  658.         "|    Would you like to save?    |",
  659.         "|                               |",
  660.         "|                               |",
  661.         "|        YES          NO        |",
  662.         "+-------------------------------+"
  663.     }
  664.     for i=1,#saveList do
  665.         if i == #saveList-1 then
  666.             if select == 1 then
  667.                 printCentered("|       [YES]         NO        |", 3 + i)
  668.             elseif select == 2 then
  669.                 printCentered("|        YES         [NO]       |", 3 + i)
  670.             end
  671.         else
  672.             printCentered(saveList[i], 3 + i)
  673.         end
  674.     end
  675. end
  676.  
  677. local function drawExitMenu()
  678.     local exitList = {
  679.         "+-------------------------------+",
  680.         "|    Would you like to save     |",
  681.         "|        before exiting?        |",
  682.         "|                               |",
  683.         "|        YES          NO        |",
  684.         "+-------------------------------+"
  685.     }
  686.     for i=1,#exitList do
  687.         if i == #exitList-1 then
  688.             if select == 1 then
  689.                 printCentered("|       [YES]         NO        |", 3 + i)
  690.             elseif select == 2 then
  691.                 printCentered("|        YES         [NO]       |", 3 + i)
  692.             end
  693.         else
  694.             printCentered(exitList[i], 3 + i)
  695.         end
  696.     end
  697. end
  698.  
  699. local function drawResultMenu()
  700.     local resultList = {
  701.         "+-------------------------------+",
  702.         "|                               |",
  703.         "|    Ores mined this session!   |",
  704.         "|                               |",
  705.         "|             [OK]              |",
  706.         "+-------------------------------+"
  707.     }
  708.     for i=1,#resultList do
  709.         if i == #resultList-1 then
  710.             printCentered("|             [OK]              |", 3 + i)
  711.         elseif i == #resultList-4 then
  712.             printCentered(resultList[i], 2 + i)
  713.             printCentered(ores_mined, 2 + i)
  714.         else
  715.             printCentered(resultList[i], 3 + i)
  716.         end
  717.     end
  718. end
  719.  
  720. local function runOreFinder(_sSave)
  721.     tSave = {}
  722.     tSave = loadTable(_sSave)
  723.     local menustate = "gpsmenu"
  724.     local function rungui()
  725.         local mopt = {
  726.             ["main"] = {
  727.                 options = {"toggle_pause", "refuelmenu", "savemenu", "exitmenu"},
  728.                 draw = drawMainMenu
  729.             },
  730.             ["gpsmenu"] = {
  731.                 options = {"locate", "exit"},
  732.                 draw = drawGPSMenu
  733.             },
  734.             ["refuelmenu"] = {
  735.                 options = {"refuel", "main"},
  736.                 draw = drawRefuelMenu
  737.             },
  738.             ["refuel"] = {
  739.                 options = {"main"},
  740.                 draw = drawRefuel
  741.             },
  742.             ["savemenu"] = {
  743.                 options = {"save", "main"},
  744.                 draw = drawSaveMenu
  745.             },
  746.             ["exitmenu"] = {
  747.                 options = {"save_exit", "exit"},
  748.                 draw = drawExitMenu
  749.             },
  750.             ["resultmenu"] = {
  751.                 options = {"exit"},
  752.                 draw = drawResultMenu
  753.             }
  754.         }
  755.         tCordsInput = {
  756.             {text = "", sx = 9, sy = 6},
  757.             {text = "", sx = 9, sy = 7},
  758.             {text = "", sx = 9, sy = 8},
  759.             {text = "", sx = 9, sy = 9}
  760.         }
  761.         select = 1
  762.         fuel_level = tostring(turtle.getFuelLevel())
  763.         ores_mined = 0
  764.         while true do
  765.             mopt[menustate].draw()
  766.             local sEvent, param = os.pullEvent()
  767.             if sEvent == "key" then
  768.                 if param == keys.up and select > 1 then
  769.                     select = select-1
  770.                 elseif param == keys.down and select < #mopt[menustate].options then
  771.                     if loc.paused then
  772.                         select = select+1
  773.                     end
  774.                 elseif param == keys.left and select > 1 then
  775.                     select = select-1
  776.                 elseif param == keys.right and select < #mopt[menustate].options then
  777.                     if loc.paused then
  778.                         select = select+1
  779.                     end
  780.                 elseif param == keys.enter then
  781.                     if mopt[menustate].options[select] == "save" or mopt[menustate].options[select] == "save_exit" then
  782.                         saveTable(tSave, _sSave)
  783.                         if mopt[menustate].options[select] == "save_exit" then
  784.                             break
  785.                         end
  786.                         menustate = "main"
  787.                     elseif mopt[menustate].options[select] == "exit" then
  788.                         break
  789.                     elseif mopt[menustate].options[select] == "toggle_pause" then
  790.                         if loc.paused then
  791.                             loc.paused = false
  792.                         else
  793.                             loc.paused = true
  794.                         end
  795.                     elseif mopt[menustate].options[select] == "refuel" then
  796.                         if turtle.getFuelLevel() ~= "unlimited" then
  797.                             for i=tSave.ignore+1,16 do
  798.                                 if turtle.getItemCount(i) > 0 then
  799.                                     turtle.select(i)
  800.                                     turtle.refuel(turtle.getItemCount(i))
  801.                                 end
  802.                             end
  803.                             turtle.select(1)
  804.                         end
  805.                         fuel_level = tostring(turtle.getFuelLevel())
  806.                         menustate = mopt[menustate].options[select]
  807.                         select = 1
  808.                     else
  809.                         menustate = mopt[menustate].options[select]
  810.                         select = 1
  811.                     end
  812.                 end
  813.             end
  814.         end
  815.     end
  816.     rungui()
  817.     menustate = "main"
  818.     if not tSave.startPos then
  819.         tSave.startPos = {x = loc.x, y = loc.y, z = loc.z, facing = loc.facing}
  820.         tSave.returnPos = {x = loc.x, y = loc.y, z = loc.z, facing = loc.facing}
  821.     end
  822.     saveTable(tSave, _sFile)
  823.     parallel.waitForAny(oreFinder, rungui)
  824.     if not fs.exists(_sFile) then
  825.         menustate = "resultmenu"
  826.         rungui()
  827.     end
  828. end
  829.  
  830. local tArgs = { ... }
  831. if turtle.getFuelLevel() > 0 or turtle.getFuelLevel() == "unlimited" then
  832.     if #tArgs == 1 then
  833.         _sFile = tostring(tArgs[1])
  834.         if fs.exists(_sFile) then
  835.             runOreFinder(_sFile)
  836.             term.setCursorPos(1,1)
  837.             term.clear()
  838.         end
  839.     else
  840.         error("Usage: advancedorefinder <save file>")
  841.     end
  842. else
  843.     error("Error, there must be fuel in the turtle!")
  844. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement