Advertisement
montana_1

Branch Minning

Nov 2nd, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 37.68 KB | None | 0 0
  1. --[[
  2.     Feel free to use any code or functions in the following paste under the condition
  3.     that credit is given where credit is due.
  4.     All code has been made by minecraft:montana_1
  5.     For comments or concerns, please email [email protected]
  6.    
  7.     Thanks!
  8. ]]--
  9.  
  10. --[[
  11.     Code to-do list:
  12.         *Auto chest deposit
  13.         *Auto torch placement for branches and better torch logic for tunnel
  14.         *Rednet flags
  15.         *Finish branch function
  16.             *torch placement
  17.             *more efficient logic
  18.         *Improve efficiency
  19.         *Various others
  20.     Newest Features:
  21.         *Main tunnel function
  22.         *Ore priorities
  23. ]]--
  24.  
  25. -- Function to split string values into tables --
  26. function split(inputstr, sep)
  27.     if(inputstr == nil or inputstr == "") then
  28.             return nil
  29.         end
  30.         if sep == nil then
  31.             sep = ","
  32.         end
  33.         local t={} ; i=1
  34.         for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  35.             t[i] = str
  36.             i = i + 1
  37.         end
  38.         return t
  39. end
  40.  
  41. -- Function to add elements to priorities list --
  42. function addList(name,mine,flag,drop,vein)
  43.     if(fs.exists("listed")) then
  44.         xlist = fs.open("listed","r")
  45.         local x = split(xlist.readLine())
  46.        
  47.         while(x[1] ~= nil) do
  48.             if(name == x[1]) then
  49.                 return false
  50.             end
  51.             s = xlist.readLine()
  52.             if(s ~= nil) then
  53.                 x = split(s)
  54.             else
  55.                 break
  56.             end
  57.         end
  58.        
  59.         xlist.close()
  60.         xlist = fs.open("listed","a")
  61.     else
  62.         xlist = fs.open("listed","w")
  63.     end
  64.     xlist.writeLine(name..","..mine..","..flag..","..drop..","..vein)
  65.     xlist.close()
  66.     return true
  67. end
  68.  
  69. -- Function to get priorities list in file format as a list --
  70. function lstToTable()
  71.     if(fs.exists("listed")) then
  72.         ifile = fs.open("listed","r")
  73.         xlist = {}
  74.         x = split(ifile.readLine())
  75.         while(x ~= nil and x ~= "") do
  76.             table.insert(xlist, x)
  77.             x = split(ifile.readLine())
  78.         end
  79.     else
  80.         --      name,mine,flag,drop,vein
  81.         xlist = {
  82.             {'iron_ore','1','0','0','1'},
  83.             {'coal_ore','1','0','0','1'},
  84.             {'gold_ore','1','0','0','1'},
  85.             {'lapis_ore','1','0','0','1'},
  86.             {'redstone_ore','1','0','0','1'},
  87.             {'lit_redstone_ore','1','0','0','1'},
  88.             {'diamond_ore','1','0','0','1'},
  89.             {'quartz_ore','1','0','0','1'},
  90.             {'emerald_ore','1','0','0','1'}
  91.             }
  92.         for k,v in pairs(xlist) do
  93.             addList(v[1],v[2],v[3],v[4],v[5])
  94.         end
  95.     end
  96.     return xlist
  97. end
  98.  
  99. -- Function to clear turtle inventory according to priorities list --
  100. function clrInv(xtable)
  101.     for i = 1, 16 do -- loop through the slots
  102.         turtle.select(i)
  103.         local x = turtle.getItemDetail(i)
  104.         if(x ~= nil) then
  105.             local istr = string.sub(x.name,string.find(x.name,":",0)+1)
  106.             for key,value in pairs(xtable) do
  107.                 if(istr == value[1] and value[4] == "1") then
  108.                     turtle.drop()
  109.                 end
  110.             end
  111.         end
  112.     end
  113.     turtle.select(1)
  114. end
  115.  
  116. -- Function to sort turtle inventory --
  117. function sortInv()
  118.     for i = 1, 16 do -- loop through the slots
  119.         turtle.select(i)
  120.         if(turtle.getItemDetail(i) ~= nil) then
  121.             for c = i, 16 do
  122.                 if(turtle.getItemDetail(c) ~= nil) then
  123.                     if(turtle.compareTo(c)) then
  124.                         turtle.select(c)
  125.                         turtle.transferTo(i)
  126.                         turtle.select(i)
  127.                     end
  128.                 end
  129.             end
  130.         end
  131.     end
  132.     turtle.select(1)
  133. end
  134.  
  135. -- Function to check for turtle inventory space --
  136. function invSpace()
  137.     for i = 1, 16 do
  138.         turtle.select(i)
  139.         local x = turtle.getItemDetail(i)
  140.         if(x == nil or turtle.compare()) then
  141.             turtle.select(1)
  142.             return true
  143.         end
  144.     end
  145.     turtle.select(1)
  146.     return false
  147. end
  148.  
  149. -- Function to check for sufficient turtle fuel --
  150. function sufficientFuel(vector1,vector2,fuel,remainder)
  151.    
  152.     local distance = math.abs(vector1.x - vector2.x) + math.abs(vector1.y - vector2.y) + math.abs(vector1.z - vector2.z)
  153.     if(fuel <= distance + remainder) then
  154.         return false
  155.     else
  156.         return true
  157.     end
  158. end
  159.  
  160. -- Function to consume turtle fuel --
  161. function consumeFuel(maxFuel) -- Optionally add more fuel types and prioritise fuel types
  162.     local refuel = false
  163.     for i = 1, 16 do -- loop through the slots
  164.         turtle.select(i) -- change to the slot
  165.         local x = turtle.getItemDetail(i)
  166.         if(x ~= nil) then
  167.             local istr = string.sub(x.name,string.find(x.name,":",0)+1)
  168.             if(istr == "planks" or istr == "stick" or istr == "log") then
  169.                 turtle.refuel()
  170.                 refuel = true
  171.             end
  172.             if(turtle.getFuelLevel() < maxFuel and istr == "coal") then
  173.                 turtle.refuel(1)
  174.                 refuel = true
  175.             end
  176.         end
  177.     end
  178.     turtle.select(1)
  179.     --print(turtle.getFuelLevel())
  180.     return refuel
  181. end
  182.  
  183. -- Function to place torch --
  184. function placeTorch(direction) -- Optionally add functionality to place torch when no torch can be placed
  185.     local torch = false
  186.     for i = 1, 16 do -- loop through the slots
  187.         turtle.select(i) -- change to the slot
  188.         local x = turtle.getItemDetail(i)
  189.         if(x ~= nil) then
  190.             local istr = string.sub(x.name,string.find(x.name,":",0)+1)
  191.             if(istr == "torch") then
  192.                 if(direction == "up") then
  193.                     if(turtle.placeUp()) then
  194.                         torch = true
  195.                         turtle.select(1)
  196.                     end
  197.                 elseif(direction == "down")then
  198.                     if(turtle.placeDown()) then
  199.                         torch = true
  200.                         turtle.select(1)
  201.                     end
  202.                 else
  203.                     if(turtle.place()) then
  204.                         torch = true
  205.                         turtle.select(1)
  206.                     end
  207.                 end
  208.             end
  209.         end
  210.     end
  211.     turtle.select(1)
  212.     return torch
  213. end
  214.  
  215. -- Function to get turtle heading --
  216. function getHeading()
  217.     if(turtle.getFuelLevel() < 2) then
  218.         if(not consumeFuel(400)) then
  219.             error("Insufficient fuel")
  220.         end
  221.     end
  222.     local start = vector.new(gps.locate())
  223.     while(turtle.detect()) do
  224.         turtle.dig()
  225.     end
  226.     turtle.forward()
  227.     local current = vector.new(gps.locate())
  228.     turtle.back()
  229.     if(start.z - current.z > 0) then
  230.         heading = 'N'
  231.     elseif (start.z - current.z < 0) then
  232.         heading = 'S'
  233.     end
  234.     if(start.x - current.x > 0) then
  235.         heading = 'W'
  236.     elseif (start.x - current.x < 0) then
  237.         heading = 'E'
  238.     end
  239.         return heading
  240. end
  241.  
  242. -- Function to set turtle heading --
  243. function setHeading(heading,newHeading)
  244.      if(heading ~= 'N' and heading ~= 'n' and heading ~= 'E' and heading ~= 'e' and heading ~= 'S' and heading ~= 's' and heading ~= 'W' and heading ~= 'w') then
  245.         if(turtle.getFuelLevel() < 2) then
  246.             error("Insufficient fuel")
  247.         end
  248.                 local start = vector.new(gps.locate())
  249.                 while(turtle.detect()) do
  250.                         turtle.dig()
  251.                 end
  252.                 turtle.forward()
  253.                 local current = vector.new(gps.locate())
  254.                 turtle.back()
  255.                 if(start.z - current.z > 0) then
  256.                         heading = 'N'
  257.                 elseif (start.z - current.z < 0) then
  258.                         heading = 'S'
  259.                 end
  260.                 if(start.x - current.x > 0) then
  261.                         heading = 'W'
  262.                 elseif (start.x - current.x < 0) then
  263.                         heading = 'E'
  264.                 end
  265.         end
  266.  
  267.     if(heading ~= newHeading) then
  268.         if(newHeading == 'N' or newHeading == 'n') then
  269.             if(heading == 'S' or heading == 's') then
  270.                 turtle.turnLeft()
  271.                 turtle.turnLeft()
  272.             end
  273.             if(heading == 'E' or heading == 'e') then
  274.                 turtle.turnLeft()
  275.             end
  276.             if(heading == 'W' or heading == 'w') then
  277.                 turtle.turnRight()
  278.             end
  279.         end
  280.         if(newHeading == 'E' or newHeading == 'e') then
  281.             if(heading == 'S' or heading == 's') then
  282.                 turtle.turnLeft()
  283.             end
  284.             if(heading == 'N' or heading == 'n') then
  285.                 turtle.turnRight()
  286.             end
  287.             if(heading == 'W' or heading == 'w') then
  288.                 turtle.turnRight()
  289.                 turtle.turnRight()
  290.             end
  291.         end
  292.         if(newHeading == 'S' or newHeading == 's') then
  293.             if(heading == 'N' or heading == 'n') then
  294.                 turtle.turnLeft()
  295.                 turtle.turnLeft()
  296.             end
  297.             if(heading == 'E' or heading == 'e') then
  298.                 turtle.turnRight()
  299.             end
  300.             if(heading == 'W' or heading == 'w') then
  301.                 turtle.turnLeft()
  302.             end
  303.         end
  304.         if(newHeading == 'W' or newHeading == 'w') then
  305.             if(heading == 'S' or heading == 's') then
  306.                 turtle.turnRight()
  307.             end
  308.             if(heading == 'E' or heading == 'e') then
  309.                 turtle.turnLeft()
  310.                 turtle.turnLeft()
  311.             end
  312.             if(heading == 'N' or heading == 'n') then
  313.                 turtle.turnLeft()
  314.             end
  315.         end
  316.     end
  317. end
  318.  
  319. -- Function to go to a specific location --
  320. function goToLocation(location,heading)
  321.     if(heading ~= 'N' and heading ~= 'n' and heading ~= 'E' and heading ~= 'e' and heading ~= 'S' and heading ~= 's' and heading ~= 'W' and heading ~= 'w') then
  322.         heading = getHeading()
  323.     end
  324.    
  325.     local current = vector.new(gps.locate())
  326.     if(location.x ~= current.x or location.y ~= current.y or location.z ~= current.z) then
  327.         if(turtle.getFuelLevel() < 2) then
  328.             error("Insufficient fuel")
  329.         end
  330.     end
  331.     while(location.y ~= current.y) do
  332.         if(location.y > current.y) then
  333.             while(turtle.detectUp()) do
  334.                 turtle.digUp()
  335.             end
  336.             turtle.up()
  337.         else
  338.             while(turtle.detectDown()) do
  339.                 turtle.digDown()
  340.             end
  341.             turtle.down()
  342.         end
  343.         current = vector.new(gps.locate())
  344.     end
  345.    
  346.     while(location.z ~= current.z) do
  347.         if(location.z > current.z) then
  348.             setHeading(heading,'S')
  349.             heading = 'S'
  350.         elseif(location.z < current.z) then
  351.             setHeading(heading,'N')
  352.             heading = 'N'
  353.         end
  354.         while(turtle.detect()) do
  355.             turtle.dig()
  356.         end
  357.         turtle.forward()
  358.         current = vector.new(gps.locate())
  359.     end
  360.  
  361.     while(location.x ~= current.x) do
  362.         if(location.x > current.x) then
  363.             setHeading(heading,'E')
  364.             heading = 'E'
  365.         elseif(location.x < current.x) then
  366.             setHeading(heading,'W')
  367.             heading = 'W'
  368.         end
  369.         while(turtle.detect()) do
  370.             turtle.dig()
  371.         end
  372.         turtle.forward()
  373.         current = vector.new(gps.locate())
  374.     end
  375.     return heading
  376. end
  377.  
  378. -- Function to decide whether to mine whole ore vein based on priorities list --
  379. function shouldMineWhole(istr,xlist) -- must add functionality for flagging ores
  380.     for key,value in pairs(xlist) do
  381.         if(istr == value[1] and value[5] == "1") then
  382.             return true
  383.         end
  384.     end
  385.     return false
  386. end
  387.  
  388. -- Function to mine entire ore pocket --
  389. function mineVein(start,moves,back,xtable) -- This function needs work on flagging ore, also could be significantly more efficient
  390.     --Establish current GPS location--
  391.     local current = vector.new(gps.locate())
  392.     --Check for sufficient fuel, if not, try to refuel, if refuel fails, function return false and
  393.     --recursion tree will collapse with turtle returning to where it started--
  394.     if(not sufficientFuel(start,current,turtle.getFuelLevel(),5 + moves)) then
  395.         if(not consumeFuel(400)) then
  396.             return -2
  397.         end
  398.     end
  399.     --Check for inventory space, if no inventory space, try to create some. if no space can be created,
  400.     --function return false and recursion tree will collapse, with turtle returning to where it started.
  401.     if(not invSpace()) then
  402.         sortInv()
  403.         clrInv(xtable)
  404.         if(not invSpace()) then
  405.             return -1
  406.         end
  407.     end
  408.    
  409.     --Check above turtle for ores--
  410.     local success,data = turtle.inspect()
  411.     if(success) then
  412.         local istr = string.sub(data.name,string.find(data.name,":",0)+1)
  413.         --print(istr)
  414.         if(shouldMineWhole(istr,xtable)) then
  415.             turtle.dig()
  416.             turtle.forward()
  417.             mineVein(start,moves+1,false,xtable)
  418.             turtle.back()
  419.         end
  420.     end
  421.     if(moves == 0) then
  422.         if(current.y == start.y + 1) then
  423.             local success,data = turtle.inspectUp()
  424.             if(success) then
  425.                 local istr = string.sub(data.name,string.find(data.name,":",0)+1)
  426.                 --print(istr)
  427.                 if(shouldMineWhole(istr,xtable)) then
  428.                     turtle.digUp()
  429.                     turtle.up()
  430.                     mineVein(start,moves+1,true,xtable)
  431.                     turtle.down()
  432.                 end
  433.             end
  434.         end
  435.         if(current.y == start.y) then
  436.             local success,data = turtle.inspectDown()
  437.             if(success) then
  438.                 local istr = string.sub(data.name,string.find(data.name,":",0)+1)
  439.                 --print(istr)
  440.                 if(shouldMineWhole(istr,xtable)) then
  441.                     turtle.digDown()
  442.                     turtle.down()
  443.                     mineVein(start,moves+1,true,xtable)
  444.                     turtle.up()
  445.                 end
  446.             end
  447.         end
  448.     end
  449.    
  450.     --will ensure turtle does not check sides on start.
  451.     if(moves < 1) then
  452.         return 1
  453.     end
  454.     turtle.turnLeft()
  455.     local success,data = turtle.inspect()
  456.     if(success) then
  457.         local istr = string.sub(data.name,string.find(data.name,":",0)+1)
  458.         --print(istr)
  459.         if(shouldMineWhole(istr,xtable)) then
  460.             turtle.dig()
  461.             turtle.forward()
  462.             mineVein(start,moves+1,false,xtable)
  463.             turtle.back()
  464.         end
  465.     end
  466.     if(back) then
  467.         turtle.turnLeft()
  468.         local success,data = turtle.inspect()
  469.         if(success) then
  470.             local istr = string.sub(data.name,string.find(data.name,":",0)+1)
  471.             --print(istr)
  472.             if(shouldMineWhole(istr,xtable)) then
  473.                 turtle.dig()
  474.                 turtle.forward()
  475.                 mineVein(start,moves+1,false,xtable)
  476.                 turtle.back()
  477.             end
  478.         end
  479.         turtle.turnLeft()
  480.         local success,data = turtle.inspect()
  481.         if(success) then
  482.             local istr = string.sub(data.name,string.find(data.name,":",0)+1)
  483.             --print(istr)
  484.             if(shouldMineWhole(istr,xtable)) then
  485.                 turtle.dig()
  486.                 turtle.forward()
  487.                 mineVein(start,moves+1,false,xtable)
  488.                 turtle.back()
  489.             end
  490.         end
  491.         turtle.turnLeft()
  492.         local success,data = turtle.inspectUp()
  493.         if(success) then
  494.             local istr = string.sub(data.name,string.find(data.name,":",0)+1)
  495.             --print(istr)
  496.             if(shouldMineWhole(istr,xtable)) then
  497.                 turtle.digUp()
  498.                 turtle.up()
  499.                 mineVein(start,moves+1,true,xtable)
  500.                 turtle.down()
  501.             end
  502.         end
  503.         local success,data = turtle.inspectDown()
  504.         if(success) then
  505.             local istr = string.sub(data.name,string.find(data.name,":",0)+1)
  506.             --print(istr)
  507.             if(shouldMineWhole(istr,xtable)) then
  508.                 turtle.digDown()
  509.                 turtle.down()
  510.                 mineVein(start,moves+1,true,xtable)
  511.                 turtle.up()
  512.             end
  513.         end
  514.     else
  515.         turtle.turnRight()
  516.         turtle.turnRight()
  517.         local success,data = turtle.inspect()
  518.         if(success) then
  519.             local istr = string.sub(data.name,string.find(data.name,":",0)+1)
  520.             --print(istr)
  521.             if(shouldMineWhole(istr,xtable)) then
  522.                 turtle.dig()
  523.                 turtle.forward()
  524.                 mineVein(start,moves+1,false,xtable)
  525.                 turtle.back()
  526.             end
  527.         end
  528.         turtle.turnLeft()
  529.         local success,data = turtle.inspectUp()
  530.         if(success) then
  531.             local istr = string.sub(data.name,string.find(data.name,":",0)+1)
  532.             --print(istr)
  533.             if(shouldMineWhole(istr,xtable)) then
  534.                 turtle.digUp()
  535.                 turtle.up()
  536.                 mineVein(start,moves+1,true,xtable)
  537.                 turtle.down()
  538.             end
  539.         end
  540.         local success,data = turtle.inspectDown()
  541.         if(success) then
  542.             local istr = string.sub(data.name,string.find(data.name,":",0)+1)
  543.             --print(istr)
  544.             if(shouldMineWhole(istr,xtable)) then
  545.                 turtle.digDown()
  546.                 turtle.down()
  547.                 mineVein(start,moves+1,true,xtable)
  548.                 turtle.up()
  549.             end
  550.         end
  551.     end
  552.     return 1
  553. end
  554.  
  555. -- Function to mine branch --
  556. function mineBranch(branchStart,branchHeading,currentHeading,branchLimit,fuelRemainder,plist,torchLength) -- Still needs optimization and functions to replace repeated blocks
  557.     -- Search for GPS signal --
  558.     local current = vector.new(gps.locate())
  559.     if(current.x == nil or current.y == nil or current.z == nil) then
  560.         -- GPS signal could not be established --
  561.         error("Could not establish GPS signal, please ensure GPS servers are running and try again")
  562.     end
  563.     -- GPS signal established --
  564.     if(not sufficientFuel(current,branchStart,turtle.getFuelLevel(),fuelRemainder + 5)) then
  565.         if(not consumeFuel(4000)) then
  566.             error("Insufficient fuel!")
  567.         end
  568.     end
  569.     if(currentHeading ~= 'N' and currentHeading ~= 'n' and currentHeading ~= 'E' and currentHeading ~= 'e' and currentHeading ~= 'S' and currentHeading ~= 's' and currentHeading ~= 'W' and currentHeading ~= 'w') then
  570.         currentHeading = getHeading()
  571.     end
  572.    
  573.     --print("Heading: ", currentHeading)
  574.    
  575.     if(branchStart.y ~= current.y) then
  576.         -- If y level is not the same --
  577.         currentHeading = goToLocation(vector.new(current.x,branchStart.y,current.z), currentHeading)
  578.         current = vector.new(gps.locate())
  579.     end
  580.     -- Ensure z level is the same as starting y level --
  581.     if(branchHeading == 'N' or branchHeading == 'n' or branchHeading == 'S' or branchHeading == 's') then
  582.         if(branchStart.z ~= current.z) then
  583.             -- If z level is not the same --
  584.             currentHeading = goToLocation(vector.new(branchStart.x,current.y,current.z), currentHeading)
  585.             current = vector.new(gps.locate())
  586.         end
  587.     end
  588.     -- Ensure x level is the same as starting y level --
  589.     if(branchHeading == 'E' or branchHeading == 'e' or branchHeading == 'W' or branchHeading == 'w') then
  590.         if(branchStart.x ~= current.x) then
  591.             -- If x level is not the same --
  592.             currentHeading = goToLocation(vector.new(current.x,current.y,branchStart.z), currentHeading)
  593.             current = vector.new(gps.locate())
  594.         end
  595.     end
  596.     setHeading(currentHeading,branchHeading)
  597.     currentHeading = branchHeading
  598.     --[[
  599.         Done
  600.         0   : Not done, still mining
  601.         1   : Is done, mining was successful
  602.         -1  : Inventory full
  603.         -2  : Insufficient fuel
  604.     ]]--
  605.     done = 0
  606.     while(done == 0) do
  607.         current = vector.new(gps.locate())
  608.         if(current.x == nil or current.y == nil or current.z == nil) then
  609.             -- GPS signal could not be established --
  610.             error("Could not establish GPS signal, please ensure GPS servers are running and try again")
  611.         else
  612.             -- Ensure distance from branchStart is less than branchLimit --
  613.             -- Along the North/South line --
  614.             if(branchHeading == 'N' or branchHeading == 'n' or branchHeading == 'S' or branchHeading == 's')then
  615.                 -- Check if distance from branchStart is within branchLimit --
  616.                 if(math.abs(branchStart.z - current.z)>=branchLimit) then
  617.                     -- Distance from branchStart is not within branchLimit --
  618.                     currentHeading = goToLocation(vector.new(branchStart.x,branchStart.y,current.z),currentHeading)
  619.                     currentHeading = goToLocation(vector.new(branchStart.x,branchStart.y,branchStart.z),currentHeading)
  620.                     done = 1
  621.                 else
  622.                     -- Distance from branchStart is within branchLimit --
  623.                     -- Check for sufficient fuel --
  624.                     if(sufficientFuel(current,branchStart,turtle.getFuelLevel(),fuelRemainder + 5)) then
  625.                         if(invSpace()) then
  626.                             if(current.y == branchStart.y) then
  627.                                 turtle.turnLeft()
  628.                                 mineVein(branchStart,0,false,plist)
  629.                                 turtle.turnRight()
  630.                                 turtle.turnRight()
  631.                                 mineVein(branchStart,0,false,plist)
  632.                                 turtle.turnLeft()
  633.                                 while(turtle.detect()) do
  634.                                     turtle.dig()
  635.                                 end
  636.                                 turtle.forward()
  637.                                 turtle.turnLeft()
  638.                                 mineVein(branchStart,0,false,plist)
  639.                                 turtle.turnRight()
  640.                                 turtle.turnRight()
  641.                                 mineVein(branchStart,0,false,plist)
  642.                                 turtle.turnLeft()
  643.                                 while(turtle.detectUp()) do
  644.                                     turtle.digUp()
  645.                                 end
  646.                                 turtle.up()
  647.                             elseif(current.y - 1 == branchStart.y) then
  648.                                 turtle.turnLeft()
  649.                                 mineVein(branchStart,0,false,plist)
  650.                                 turtle.turnRight()
  651.                                 turtle.turnRight()
  652.                                 mineVein(branchStart,0,false,plist)
  653.                                 turtle.turnLeft()
  654.                                 while(turtle.detect()) do
  655.                                     turtle.dig()
  656.                                 end
  657.                                 turtle.forward()
  658.                                 turtle.turnLeft()
  659.                                 mineVein(branchStart,0,false,plist)
  660.                                 turtle.turnRight()
  661.                                 turtle.turnRight()
  662.                                 mineVein(branchStart,0,false,plist)
  663.                                 turtle.turnLeft()
  664.                                 while(turtle.detectDown()) do
  665.                                     turtle.digDown()
  666.                                 end
  667.                                 turtle.down()
  668.                             else
  669.                                 currentHeading = goToLocation(vector.new(current.x,branchStart.y,current.z),currentHeading)
  670.                             end
  671.                         else
  672.                             sortInv()
  673.                             clrInv(plist)
  674.                             if(not invSpace()) then
  675.                                 currentHeading = goToLocation(vector.new(branchStart.x,branchStart.y,current.z),currentHeading)
  676.                                 currentHeading = goToLocation(vector.new(branchStart.x,branchStart.y,branchStart.z),currentHeading)
  677.                                 done = -1
  678.                             end
  679.                         end
  680.                     else
  681.                         if(not consumeFuel(4000)) then
  682.                             currentHeading = goToLocation(vector.new(branchStart.x,branchStart.y,current.z),currentHeading)
  683.                             currentHeading = goToLocation(vector.new(branchStart.x,branchStart.y,branchStart.z),currentHeading)
  684.                             done = -2
  685.                         end
  686.                     end
  687.                 end
  688.             -- Along the East/West line --
  689.             elseif(branchHeading == 'E' or branchHeading == 'e' or branchHeading == 'W' or branchHeading == 'w') then
  690.                 -- Check if distance from branchStart is within branchLimit --
  691.                 if(math.abs(branchStart.x - current.x)>=branchLimit) then
  692.                     -- Distance from branchStart is not within branchLimit --
  693.                     currentHeading = goToLocation(vector.new(current.x,branchStart.y,branchStart.z),currentHeading)
  694.                     currentHeading = goToLocation(vector.new(branchStart.x,branchStart.y,branchStart.z),currentHeading)
  695.                     done = 1
  696.                 else
  697.                     -- Distance from branchStart is within branchLimit --
  698.                     -- Check for sufficient fuel --
  699.                     if(sufficientFuel(current,branchStart,turtle.getFuelLevel(),fuelRemainder + 5)) then
  700.                         if(invSpace()) then
  701.                             if(current.y == branchStart.y) then
  702.                                 turtle.turnLeft()
  703.                                 mineVein(branchStart,0,false,plist)
  704.                                 turtle.turnRight()
  705.                                 turtle.turnRight()
  706.                                 mineVein(branchStart,0,false,plist)
  707.                                 turtle.turnLeft()
  708.                                 while(turtle.detect()) do
  709.                                     turtle.dig()
  710.                                 end
  711.                                 turtle.forward()
  712.                                 turtle.turnLeft()
  713.                                 mineVein(branchStart,0,false,plist)
  714.                                 turtle.turnRight()
  715.                                 turtle.turnRight()
  716.                                 mineVein(branchStart,0,false,plist)
  717.                                 turtle.turnLeft()
  718.                                 while(turtle.detectUp()) do
  719.                                     turtle.digUp()
  720.                                 end
  721.                                 turtle.up()
  722.                             elseif(current.y - 1 == branchStart.y) then
  723.                                 turtle.turnLeft()
  724.                                 mineVein(branchStart,0,false,plist)
  725.                                 turtle.turnRight()
  726.                                 turtle.turnRight()
  727.                                 mineVein(branchStart,0,false,plist)
  728.                                 turtle.turnLeft()
  729.                                 while(turtle.detect()) do
  730.                                     turtle.dig()
  731.                                 end
  732.                                 turtle.forward()
  733.                                 turtle.turnLeft()
  734.                                 mineVein(branchStart,0,false,plist)
  735.                                 turtle.turnRight()
  736.                                 turtle.turnRight()
  737.                                 mineVein(branchStart,0,false,plist)
  738.                                 turtle.turnLeft()
  739.                                 while(turtle.detectDown()) do
  740.                                     turtle.digDown()
  741.                                 end
  742.                                 turtle.down()
  743.                             else
  744.                                 currentHeading = goToLocation(vector.new(current.x,branchStart.y,current.z),currentHeading)
  745.                             end
  746.                         else
  747.                             sortInv()
  748.                             clrInv(plist)
  749.                             if(not invSpace()) then
  750.                                 currentHeading = goToLocation(vector.new(current.x,branchStart.y,branchStart.z),currentHeading)
  751.                                 currentHeading = goToLocation(vector.new(branchStart.x,branchStart.y,branchStart.z),currentHeading)
  752.                                 done = -1
  753.                             end
  754.                         end
  755.                     else
  756.                         if(not consumeFuel(4000)) then
  757.                             currentHeading = goToLocation(vector.new(current.x,branchStart.y,branchStart.z),currentHeading)
  758.                             currentHeading = goToLocation(vector.new(branchStart.x,branchStart.y,branchStart.z),currentHeading)
  759.                             done = -2
  760.                         end
  761.                     end
  762.                 end
  763.             end
  764.         end
  765.     end
  766.     return done
  767. end
  768.  
  769. -- Function to mine tunnel --
  770. function mTunnel(tunnelStart, tunnelHeading, currentHeading, tunnelLength, fuelRemainder, plist, torchDistance, branchSpacing, branchLimit,branchTorchLength)
  771.     -- Search for GPS signal --
  772.     local current = vector.new(gps.locate())
  773.     if(current.x == nil or current.y == nil or current.z == nil) then
  774.         -- GPS signal could not be established --
  775.         error("Could not establish GPS signal, please ensure GPS servers are running and try again")
  776.     end
  777.     -- GPS signal established --
  778.     if(not sufficientFuel(current,tunnelStart,turtle.getFuelLevel(),fuelRemainder+10)) then
  779.         if(not consumeFuel(4000)) then
  780.             error("Insufficient fuel!")
  781.         end
  782.     end
  783.     if(currentHeading ~= 'N' and currentHeading ~= 'n' and currentHeading ~= 'E' and currentHeading ~= 'e' and currentHeading ~= 'S' and currentHeading ~= 's' and currentHeading ~= 'W' and currentHeading ~= 'w') then
  784.         currentHeading = getHeading()
  785.     end
  786.    
  787.     print("Heading: ", currentHeading)
  788.    
  789.     -- Ensure y level is the same as starting y level --
  790.     if(tunnelStart.y ~= current.y) then
  791.         -- If y level is not the same --
  792.         currentHeading = goToLocation(vector.new(current.x,tunnelStart.y,current.z), currentHeading)
  793.         current = vector.new(gps.locate())
  794.     end
  795.     -- Ensure z level is the same as starting z level if on N/S axis --
  796.     if(tunnelHeading == 'N' or tunnelHeading == 'n' or tunnelHeading == 'S' or tunnelHeading == 's') then
  797.         if(tunnelStart.z ~= current.z) then
  798.             -- If z level is not the same --
  799.             currentHeading = goToLocation(vector.new(tunnelStart.x,current.y,current.z), currentHeading)
  800.             setHeading(currentHeading,tunnelHeading)
  801.             currentHeading = tunnelHeading
  802.             turtle.back()
  803.             current = vector.new(gps.locate())
  804.         end
  805.     end
  806.     -- Ensure x level is the same as starting x level if on E/W axis --
  807.     if(tunnelHeading == 'E' or tunnelHeading == 'e' or tunnelHeading == 'W' or tunnelHeading == 'w') then
  808.         if(tunnelStart.x ~= current.x) then
  809.             -- If x level is not the same --
  810.             currentHeading = goToLocation(vector.new(current.x,current.y,tunnelStart.z), currentHeading)
  811.             setHeading(currentHeading,tunnelHeading)
  812.             currentHeading = tunnelHeading
  813.             turtle.back()
  814.             current = vector.new(gps.locate())
  815.         end
  816.     end
  817.     if(currentHeading ~= tunnelHeading) then
  818.         setHeading(currentHeading,tunnelHeading)
  819.         currentHeading = tunnelHeading
  820.     end
  821.     --[[
  822.         Done
  823.         0   : Not done, still mining
  824.         1   : Is done, mining was successful
  825.         -1  : Inventory full
  826.         -2  : Insufficient fuel
  827.     ]]--
  828.     done = 0
  829.     while(done == 0) do
  830.         current = vector.new(gps.locate())
  831.         if(current.x == nil or current.y == nil or current.z == nil) then
  832.             -- GPS signal could not be established --
  833.             error("Could not establish GPS signal, please ensure GPS servers are running and try again")
  834.         else
  835.             -- Ensure distance from tunnelStart is less than tunnelLength --
  836.             -- Along the North/South line --
  837.             if(tunnelHeading == 'N' or tunnelHeading == 'n' or tunnelHeading == 'S' or tunnelHeading == 's')then
  838.                 -- Check if distance from tunnelStart is within tunnelLength --
  839.                 if(math.abs(tunnelStart.z - current.z)>=tunnelLength) then
  840.                     -- Distance from tunnelStart is not within tunnelLength --
  841.                     currentHeading = goToLocation(vector.new(tunnelStart.x,tunnelStart.y,current.z),currentHeading)
  842.                     currentHeading = goToLocation(vector.new(tunnelStart.x,tunnelStart.y,tunnelStart.z),currentHeading)
  843.                     done = 1
  844.                 else
  845.                     -- Distance from tunnelStart is within tunnelLength --
  846.                     -- Check for sufficient fuel --
  847.                     if(sufficientFuel(current,tunnelStart,turtle.getFuelLevel(),fuelRemainder + 10)) then
  848.                         if(invSpace()) then
  849.                             term.clear()
  850.                             term.setCursorPos(1,1)
  851.                             print((tunnelStart.z - current.z)%branchSpacing)
  852.                             while(turtle.detect()) do
  853.                                 turtle.dig()
  854.                             end
  855.                             turtle.forward()
  856.                             while(turtle.detectUp()) do
  857.                                 turtle.digUp()
  858.                             end
  859.                             turtle.turnLeft()
  860.                             while(turtle.detect()) do
  861.                                 turtle.dig()
  862.                             end
  863.                             turtle.forward()
  864.                             if(tunnelHeading == 'N' or tunnelHeading == 'n') then
  865.                                 if((tunnelStart.z - current.z)%branchSpacing == branchSpacing - 1 and done == 0) then
  866.                                     done = mineBranch(vector.new(gps.locate()),"w","w",branchLimit,fuelRemainder+5,plist,branchTorchLength)
  867.                                     if(done == 1) then
  868.                                         done = 0
  869.                                     end
  870.                                     turtle.turnLeft()
  871.                                     turtle.turnLeft()
  872.                                 end
  873.                             else
  874.                                 if((tunnelStart.z - current.z)%branchSpacing == branchSpacing - 1 and done == 0) then
  875.                                     done = mineBranch(vector.new(gps.locate()),"e","e",branchLimit,fuelRemainder+5,plist,branchTorchLength)
  876.                                     if(done == 1) then
  877.                                         done = 0
  878.                                     end
  879.                                     turtle.turnLeft()
  880.                                     turtle.turnLeft()
  881.                                 end
  882.                             end
  883.                             while(turtle.detectUp()) do
  884.                                 turtle.digUp()
  885.                             end
  886.                             turtle.up()
  887.                             while(turtle.detectUp()) do
  888.                                 turtle.digUp()
  889.                             end
  890.                             turtle.up()
  891.                             turtle.turnLeft()
  892.                             turtle.turnLeft()
  893.                             while(turtle.detect()) do
  894.                                 turtle.dig()
  895.                             end
  896.                             turtle.forward()
  897.                             if((tunnelStart.z - current.z)%torchDistance - 1 == 0 and math.abs(tunnelStart.z - current.z) >= torchDistance - 1) then
  898.                                 turtle.turnLeft()
  899.                                 turtle.turnLeft()
  900.                                 placeTorch()
  901.                                 turtle.turnLeft()
  902.                                 turtle.turnLeft()
  903.                             end
  904.                             while(turtle.detect()) do
  905.                                 turtle.dig()
  906.                             end
  907.                             turtle.forward()
  908.                             while(turtle.detectDown()) do
  909.                                 turtle.digDown()
  910.                             end
  911.                             turtle.down()
  912.                             if((tunnelStart.z - current.z)%torchDistance - 1 == 0 and math.abs(tunnelStart.z - current.z) >= torchDistance - 1) then
  913.                                 placeTorch("up")
  914.                             end
  915.                             while(turtle.detectDown()) do
  916.                                 turtle.digDown()
  917.                             end
  918.                             turtle.down()
  919.                             if(tunnelHeading == 'S' or tunnelHeading == 's') then
  920.                                 if((tunnelStart.z - current.z)%branchSpacing == branchSpacing - 1 and done == 0) then
  921.                                     done = mineBranch(vector.new(gps.locate()),"w","w",branchLimit,fuelRemainder+5,plist,branchTorchLength)
  922.                                     if(done == 1) then
  923.                                         done = 0
  924.                                     end
  925.                                     turtle.turnLeft()
  926.                                     turtle.turnLeft()
  927.                                 end
  928.                             else
  929.                                 if((tunnelStart.z - current.z)%branchSpacing == branchSpacing - 1 and done == 0) then
  930.                                     done = mineBranch(vector.new(gps.locate()),"e","e",branchLimit,fuelRemainder+5,plist,branchTorchLength)
  931.                                     if(done == 1) then
  932.                                         done = 0
  933.                                     end
  934.                                     turtle.turnLeft()
  935.                                     turtle.turnLeft()
  936.                                 end
  937.                             end
  938.                             turtle.back()
  939.                             turtle.turnLeft()
  940.                         else
  941.                             sortInv()
  942.                             clrInv(plist)
  943.                             if(not invSpace()) then
  944.                                 currentHeading = goToLocation(vector.new(tunnelStart.x,tunnelStart.y,current.z),currentHeading)
  945.                                 currentHeading = goToLocation(vector.new(tunnelStart.x,tunnelStart.y,tunnelStart.z),currentHeading)
  946.                                 done = -1
  947.                             end
  948.                         end
  949.                     else
  950.                         if(not consumeFuel(4000)) then
  951.                             currentHeading = goToLocation(vector.new(tunnelStart.x,tunnelStart.y,current.z),currentHeading)
  952.                             currentHeading = goToLocation(vector.new(tunnelStart.x,tunnelStart.y,tunnelStart.z),currentHeading)
  953.                             done = -2
  954.                         end
  955.                     end
  956.                 end
  957.             -- Along the East/West line --
  958.             elseif(tunnelHeading == 'E' or tunnelHeading == 'e' or tunnelHeading == 'W' or tunnelHeading == 'w') then
  959.                 -- Check if distance from tunnelStart is within tunnelLength --
  960.                 if(math.abs(tunnelStart.x - current.x)>=tunnelLength) then
  961.                     -- Distance from tunnelStart is not within tunnelLength --
  962.                     currentHeading = goToLocation(vector.new(current.x,tunnelStart.y,tunnelStart.z),currentHeading)
  963.                     currentHeading = goToLocation(vector.new(tunnelStart.x,tunnelStart.y,tunnelStart.z),currentHeading)
  964.                     done = 1
  965.                 else
  966.                     -- Distance from tunnelStart is within tunnelLength --
  967.                     -- Check for sufficient fuel --
  968.                     if(sufficientFuel(current,tunnelStart,turtle.getFuelLevel(),fuelRemainder + 10)) then
  969.                         if(invSpace()) then
  970.                             while(turtle.detect()) do
  971.                                 turtle.dig()
  972.                             end
  973.                             turtle.forward()
  974.                             while(turtle.detectUp()) do
  975.                                 turtle.digUp()
  976.                             end
  977.                             turtle.turnLeft()
  978.                             while(turtle.detect()) do
  979.                                 turtle.dig()
  980.                             end
  981.                             turtle.forward()
  982.                             if(tunnelHeading == 'E' or tunnelHeading == 'e') then
  983.                                 if((tunnelStart.x - current.x)%branchSpacing == branchSpacing - 1 and done == 0) then
  984.                                     done = mineBranch(vector.new(gps.locate()),"n","n",branchLimit,fuelRemainder+5,plist,branchTorchLength)
  985.                                     if(done == 1) then
  986.                                         done = 0
  987.                                     end
  988.                                     turtle.turnLeft()
  989.                                     turtle.turnLeft()
  990.                                 end
  991.                             else
  992.                                 if((tunnelStart.x - current.x)%branchSpacing == branchSpacing - 1 and done == 0) then
  993.                                     done = mineBranch(vector.new(gps.locate()),"s","s",branchLimit,fuelRemainder+5,plist,branchTorchLength)
  994.                                     if(done == 1) then
  995.                                         done = 0
  996.                                     end
  997.                                     turtle.turnLeft()
  998.                                     turtle.turnLeft()
  999.                                 end
  1000.                             end
  1001.                             while(turtle.detectUp()) do
  1002.                                 turtle.digUp()
  1003.                             end
  1004.                             turtle.up()
  1005.                             while(turtle.detectUp()) do
  1006.                                 turtle.digUp()
  1007.                             end
  1008.                             turtle.up()
  1009.                             turtle.turnLeft()
  1010.                             turtle.turnLeft()
  1011.                             while(turtle.detect()) do
  1012.                                 turtle.dig()
  1013.                             end
  1014.                             turtle.forward()
  1015.                             if((tunnelStart.x - current.x)%torchDistance - 1 == 0 and math.abs(tunnelStart.x - current.x) >= torchDistance - 1) then
  1016.                                 turtle.turnLeft()
  1017.                                 turtle.turnLeft()
  1018.                                 placeTorch()
  1019.                                 turtle.turnLeft()
  1020.                                 turtle.turnLeft()
  1021.                             end
  1022.                             while(turtle.detect()) do
  1023.                                 turtle.dig()
  1024.                             end
  1025.                             turtle.forward()
  1026.                             while(turtle.detectDown()) do
  1027.                                 turtle.digDown()
  1028.                             end
  1029.                             turtle.down()
  1030.                             if((tunnelStart.x - current.x)%torchDistance - 1 == 0 and math.abs(tunnelStart.x - current.x) >= torchDistance - 1) then
  1031.                                 placeTorch("up")
  1032.                             end
  1033.                             while(turtle.detectDown()) do
  1034.                                 turtle.digDown()
  1035.                             end
  1036.                             turtle.down()
  1037.                             if(tunnelHeading == 'W' or tunnelHeading == 'w') then
  1038.                                 if((tunnelStart.x - current.x)%branchSpacing == branchSpacing - 1 and done == 0) then
  1039.                                     done = mineBranch(vector.new(gps.locate()),"n","n",branchLimit,fuelRemainder+5,plist,branchTorchLength)
  1040.                                     if(done == 1) then
  1041.                                         done = 0
  1042.                                     end
  1043.                                     turtle.turnLeft()
  1044.                                     turtle.turnLeft()
  1045.                                 end
  1046.                             else
  1047.                                 if((tunnelStart.x - current.x)%branchSpacing == branchSpacing - 1 and done == 0) then
  1048.                                     done = mineBranch(vector.new(gps.locate()),"s","s",branchLimit,fuelRemainder+5,plist,branchTorchLength)
  1049.                                     if(done == 1) then
  1050.                                         done = 0
  1051.                                     end
  1052.                                     turtle.turnLeft()
  1053.                                     turtle.turnLeft()
  1054.                                 end
  1055.                             end
  1056.                             turtle.back()
  1057.                             turtle.turnLeft()
  1058.                         else
  1059.                             sortInv()
  1060.                             clrInv(plist)
  1061.                             if(not invSpace()) then
  1062.                                 currentHeading = goToLocation(vector.new(current.x,tunnelStart.y,tunnelStart.z),currentHeading)
  1063.                                 currentHeading = goToLocation(vector.new(tunnelStart.x,tunnelStart.y,tunnelStart.z),currentHeading)
  1064.                                 done = -1
  1065.                             end
  1066.                         end
  1067.                     else
  1068.                         if(not consumeFuel(4000)) then
  1069.                             currentHeading = goToLocation(vector.new(current.x,tunnelStart.y,tunnelStart.z),currentHeading)
  1070.                             currentHeading = goToLocation(vector.new(tunnelStart.x,tunnelStart.y,tunnelStart.z),currentHeading)
  1071.                             done = -2
  1072.                         end
  1073.                     end
  1074.                 end
  1075.             end
  1076.         end
  1077.     end
  1078.     return done
  1079. end
  1080.  
  1081. --[[
  1082. d = {['split']=split,['addList']=addlist,['lstToTable']=lstToTable,['clrInv']=clrInv,['sortInv']=sortInv,['invSpace']=invSpace,['sufficientFuel']=sufficientFuel,['consumeFuel']=consumeFuel,['getHeading']=getHeading,['setHeading']=setHeading,['goToLocation']=goToLocation,['shouldMineWhole']=shouldMineWhole,['mineVein']=mineVein}
  1083.  
  1084. for key,value in pairs(d) do
  1085.     print(key)
  1086. end
  1087. print("function to test? ")
  1088. local x = read()
  1089.  
  1090. if(x == 'split') then
  1091.     print("Enter a string to split")
  1092.     local istr = read()
  1093.     print("Enter a delimiter")
  1094.     local lim = read()
  1095.     for k,v in split(istr,lim) do
  1096.         write(v," ")
  1097.     end
  1098. elseif(x == 'addList') then
  1099.     print("Enter name: ")
  1100.     local name = read()
  1101.     print("Enter mine: ")
  1102.     local mine = read()
  1103.     print("Enter flag: ")
  1104.     local flag = read()
  1105.     print("Enter drop: ")
  1106.     local drop = read()
  1107.     print("Enter vein: ")
  1108.     local vein = read()
  1109.    
  1110.     print(addList(name,mine,flag,drop,vein))
  1111. elseif(x == 'lstToTable') then
  1112.     print(lstToTable())
  1113. elseif(x == 'clrInv') then
  1114.     clrInv(lstToTable())
  1115. elseif(x == 'sortInv') then
  1116.     sortInv()
  1117. elseif(x == 'invSpace')then
  1118.     print(invSpace())
  1119. elseif(x == 'sufficientFuel') then
  1120.     print("Remainder: ")
  1121.     x = read()
  1122.     if(fs.exists("GPS_DATA")) then
  1123.         gpsData = fs.open("GPS_DATA","r")
  1124.         start = vector.new(tonumber(gpsData.readLine()),tonumber(gpsData.readLine()),tonumber(gpsData.readLine()))
  1125.     else
  1126.         print("No gps data")
  1127.     end
  1128.     local current = vector.new(gps.locate())
  1129.     print(sufficientFuel(current,start,turtle.getFuelLevel(),x))
  1130. elseif(x == 'consumeFuel') then
  1131.     print("Max fuel: ")
  1132.     maxFuel = tonumber(read())
  1133.     print(consumeFuel(maxFuel))
  1134. elseif(x == 'getHeading') then
  1135.     print(getHeading())
  1136. elseif(x == 'setHeading') then
  1137.     print("Current heading: ")
  1138.     heading = read()
  1139.     print("New heading: ")
  1140.     newHeading = read()
  1141.     setHeading(heading,newHeading)
  1142. elseif(x == 'goToLocation') then
  1143.     print("X: ")
  1144.     x = tonumber(read())
  1145.     print("Y: ")
  1146.     y = tonumber(read())
  1147.     print("Z: ")
  1148.     z = tonumber(read())
  1149.     print("Heading: ")
  1150.     heading = read()
  1151.     location = vector.new(x,y,z)
  1152.     print(goToLocation(location,heading))
  1153. elseif(x == 'shouldMineWhole') then
  1154.     x = read()
  1155.     print(shouldMineWhole(x,lstToTable()))
  1156. elseif(x == 'mineVein') then
  1157.     if(fs.exists("GPS_DATA")) then
  1158.         gpsData = fs.open("GPS_DATA","r")
  1159.         start = vector.new(tonumber(gpsData.readLine()),tonumber(gpsData.readLine()),tonumber(gpsData.readLine()))
  1160.     else
  1161.         print("No gps data")
  1162.     end
  1163.     mineVein(start,0,false,lstToTable())
  1164. end
  1165. ]]--
  1166.  
  1167. print("Enter length: ")
  1168. c = tonumber(read())
  1169.  
  1170. if(fs.exists("GPS_DATA")) then
  1171.     gpsData = fs.open("GPS_DATA","r")
  1172.     local start = vector.new(tonumber(gpsData.readLine()),tonumber(gpsData.readLine()),tonumber(gpsData.readLine()))
  1173.     sHeading = gpsData.readLine()
  1174.     if(start.x == nil or start.y == nil or start.z == nil) then
  1175.         -- GPS_DATA Invalid --
  1176.         term.clear()
  1177.         term.setCursorPos(1,1)
  1178.         error("Invalid GPS information")
  1179.     else
  1180.         -- GPS_DATA Valid --
  1181.         term.clear()
  1182.         term.setCursorPos(1,1)
  1183.         print("GPS_DATA exists, start: (",start.x,",",start.y,",",start.z,")")
  1184.         print("Heading: ", sHeading)
  1185.         -- Search for GPS signal --
  1186.         local current = vector.new(gps.locate())
  1187.         if(current.x == nil or current.y == nil or current.z == nil) then
  1188.             -- GPS signal could not be established --
  1189.             error("Could not establish GPS signal, please ensure GPS servers are running and try again")
  1190.         else
  1191.             -- GPS signal established --
  1192.             print("GPS locate, current: (",current.x,",",current.y,",",current.z,")")
  1193.             plist = lstToTable()
  1194.             lst = {4,10,plist,0}
  1195.             print(mTunnel(start,sHeading,"",c,10,lstToTable(),4,4,4,0))
  1196.         end
  1197.     end
  1198. else
  1199.     -- GPS_DATA not found --
  1200.     term.clear()
  1201.     term.setCursorPos(1,1)
  1202.     error("File 'GPS_DATA' does not exist, please run program to initiate mining")
  1203. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement