Deery50

BranchMine

Mar 9th, 2014
3,447
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.09 KB | None | 0 0
  1. -- Remember to put a chest directly behind the turtle at it's current location.
  2. -- It will deliver it's resources to this chest when full
  3.  
  4. -- Y Level to Branch-mine at
  5. local BranchMineLevel = 5
  6.  
  7. -- How many blocks on the ignore list
  8. -- that you put in the first number of slots
  9. local IgnoreSlots = 4
  10.  
  11. -- Set this to true if it is ok for the turtle to mine strait down to the y level for the Branch mine
  12. local MineDown = true
  13. local TunnelLength = 1000
  14.  
  15. -- Set this to false if you don't have a working GPS system
  16. local UseGPS = true
  17. --ALL THIS MUST BE FILLED IN IF YOU DON"T USE GPS
  18. local StartX = 0
  19. local StartY = 0
  20. local StartZ = 0
  21. -- EX: "SOUTH", "NORTH", "EAST", "WEST"
  22. local ForwardFacingDirection = ""
  23. --END NO GPS FILL INFORMATION
  24.  
  25.  
  26.  
  27. --DO NOT TOUCH ANYTHING BELOW THIS LINE
  28. local mov = {}
  29. local rot = {}
  30. local dig = {}
  31. local PositionInBranchMine = 0
  32. local RotatePosition = "FORWARD"
  33.  
  34. local InsertedIntoLeftWall = false
  35. local InsertedIntoRightWall = false
  36. local InsertionAmount = 0
  37.  
  38. local XX, YY, ZZ = 0;
  39. local PrimaryAxis = ""
  40. local SecondaryAxis = ""
  41.  
  42. local function Refuel()
  43.     currentFuelRequired = 10 + ((PositionInBranchMine/TunnelLength)*20)
  44.     if turtle.getFuelLevel() < currentFuelRequired then
  45.         turtle.select(16)
  46.         return turtle.refuel(currentFuelRequired)
  47.     else
  48.         return true
  49.     end
  50. end
  51.  
  52.  
  53. local function readLines(sPath)
  54.   local file = fs.open(sPath, "r") -- open the file
  55.   if file then -- check if it's open
  56.     local tLines = {} -- table to store the lines
  57.     local sLine = file.readLine() -- read a line from the file
  58.     while sLine do -- while there's a line in the file
  59.           table.insert(tLines, sLine) -- add it to the table
  60.           sLine = file.readLine() -- get the next line
  61.     end
  62.     file.close() -- close the file
  63.     return tLines -- return the table with the lines
  64.   end
  65.   return nil -- there was an error opening the file, return nil to let the user know
  66. end
  67.  
  68. local function writeLines(sPath, tLines)
  69.   local file = fs.open(sPath, "w") -- open the file
  70.   if file then -- check if the file is open
  71.     for _, sLine in ipairs(tLines) do -- for each line in the table
  72.           file.writeLine(sLine) -- write the line
  73.     end
  74.     file.close() -- close the file
  75.   end
  76. end
  77.  
  78. function filereadline(filename, line)
  79.   local tLines = readLines(filename) -- read the lines from the file (using the previous functions)
  80.   if not tLines then -- if there was an error
  81.     return nil -- return nil/error
  82.   end
  83.   return tLines[line] -- return the line
  84. end
  85.  
  86. function filewriteline(filename, line, text)
  87.   local tLines = readLines(filename) -- read the lines from the file (using the previous functions)
  88.   if tLines then -- if there was no error
  89.     tLines[line] = text -- set the line
  90.     writeLines(filename, tLines) -- write the lines back to the file (using the previous functions)
  91.   end
  92. end
  93.  
  94. local function incrementCoordinates(incX,incY,incZ)
  95. XX = XX + incX
  96. YY = YY + incY
  97. ZZ = ZZ + incZ
  98. filewriteline("BranchMineData", 7, XX)
  99. filewriteline("BranchMineData", 8, YY)
  100. filewriteline("BranchMineData", 9, ZZ)
  101. end
  102.  
  103. --directionInteger 0 = forward, 1 = left, 2 = backward, 3 = right, 4 = up, 5 = down
  104. local function updateCoordinates(directionInteger)
  105.     --Displace the direction by the current Rotation
  106.     if directionInteger <= 3 then
  107.         if directionInteger == 0 then
  108.             if string.match(RotatePosition,"LEFT") then
  109.                 directionInteger = 1
  110.             elseif string.match(RotatePosition,"BACKWARD") then
  111.                 directionInteger = 2
  112.             elseif string.match(RotatePosition,"RIGHT") then
  113.                 directionInteger = 3
  114.             end
  115.         elseif directionInteger == 2 then
  116.             if string.match(RotatePosition,"LEFT") then
  117.                 directionInteger = 3
  118.             elseif string.match(RotatePosition,"BACKWARD") then
  119.                 directionInteger = 0
  120.             elseif string.match(RotatePosition,"RIGHT") then
  121.                 directionInteger = 1
  122.             end
  123.         end
  124.     end
  125.  
  126.     local incrementPrimary = true
  127.     local incrementBy = 0
  128.     local incrementX = 0
  129.     local incrementY = 0
  130.     local incrementZ = 0
  131.     --if we are moving forward
  132.     if directionInteger == 0 then
  133.         incrementPrimary = true
  134.         incrementBy = 1
  135.     --if we are moving left
  136.     elseif directionInteger == 1 then
  137.         incrementPrimary = false
  138.         incrementBy = 1
  139.     --if we are moving backward
  140.     elseif directionInteger == 2 then
  141.         incrementPrimary = true
  142.         incrementBy = -1
  143.     --if we are moving right
  144.     elseif directionInteger == 3 then
  145.         incrementPrimary =false
  146.         incrementBy = -1
  147.     elseif directionInteger == 4 then
  148.         incrementY = 1
  149.     elseif directionInteger == 5 then
  150.         incrementY = -1
  151.     end
  152.  
  153.     if incrementPrimary then
  154.         if PrimaryAxis == "X" then
  155.             incrementX = incrementBy
  156.         elseif PrimaryAxis == "-X" then
  157.             incrementX = -1 * incrementBy
  158.         elseif PrimaryAxis == "Z" then
  159.             incrementZ = incrementBy
  160.         elseif PrimaryAxis == "-Z" then
  161.             incrementZ = -1 * incrementBy
  162.         end
  163.     else
  164.         if SecondaryAxis == "X" then
  165.             incrementX = incrementBy
  166.         elseif SecondaryAxis == "-X" then
  167.             incrementX = -1 * incrementBy
  168.         elseif SecondaryAxis == "Z" then
  169.             incrementZ = incrementBy
  170.         elseif SecondaryAxis == "-Z" then
  171.             incrementZ = -1 * incrementBy
  172.         end
  173.     end
  174.     incrementCoordinates(incrementX,incrementY,incrementZ)
  175. end
  176.  
  177. mov.forward = function(times)
  178.     local boolean v = false
  179.     for i=1,times do
  180.         if turtle.detect() == false then
  181.             while not turtle.forward() do
  182.                 Refuel()
  183.                 sleep(1)
  184.             end
  185.             updateCoordinates(0)
  186.             v = true
  187.         else
  188.             v = false
  189.             return v
  190.         end
  191.     end
  192.     return v
  193. end
  194.  
  195. mov.back = function(times)
  196.     local boolean v = false
  197.     for i=1,times do
  198.         while not turtle.back() do
  199.             Refuel()
  200.             sleep(1)
  201.         end
  202.         updateCoordinates(2)
  203.         v = true
  204.     end
  205.     return v
  206. end
  207.  
  208. mov.up = function(times)
  209.     local boolean v = false
  210.     for i=1,times do
  211.         if turtle.detectUp() == false then
  212.             while not turtle.up() do
  213.                 Refuel()
  214.                 sleep(1)
  215.             end
  216.             updateCoordinates(4)
  217.             v = true
  218.         else
  219.             v = false
  220.             return v
  221.         end
  222.     end
  223.     return v
  224. end
  225.  
  226. mov.down = function(times)
  227.     local boolean v = false
  228.     for i=1,times do
  229.         if turtle.detectDown() == false then
  230.             while not turtle.down() do
  231.                 Refuel()
  232.                 sleep(1)
  233.             end
  234.             updateCoordinates(5)
  235.             v = true
  236.         else
  237.             v = false
  238.             return v
  239.         end
  240.     end
  241.     return v
  242. end
  243.  
  244. mov.place = function()
  245.     while not turtle.place() do
  246.           sleep(1)
  247.     end
  248.     return true
  249. end
  250.  
  251. rot.right = function()
  252.     while not turtle.turnRight() do
  253.             sleep(1)
  254.     end
  255.    
  256.     if RotatePosition == "FORWARD" then
  257.         RotatePosition = "RIGHT"
  258.     elseif RotatePosition == "RIGHT" then
  259.         RotatePosition = "BACKWARD"
  260.     elseif RotatePosition == "BACKWARD" then
  261.         RotatePosition = "LEFT"
  262.     elseif RotatePosition == "LEFT" then
  263.         RotatePosition = "FORWARD"
  264.     end
  265.     filewriteline("BranchMineData", 5, RotatePosition)
  266.     return true
  267. end
  268.  
  269. rot.left = function()
  270.     while not turtle.turnLeft() do
  271.             sleep(1)
  272.     end
  273.    
  274.     if RotatePosition == "FORWARD" then
  275.         RotatePosition = "LEFT"
  276.     elseif RotatePosition == "LEFT" then
  277.         RotatePosition = "BACKWARD"
  278.     elseif RotatePosition == "BACKWARD" then
  279.         RotatePosition = "RIGHT"
  280.     elseif RotatePosition == "RIGHT" then
  281.         RotatePosition = "FORWARD"
  282.     end
  283.     filewriteline("BranchMineData", 5, RotatePosition)
  284.     return true
  285. end
  286.  
  287. -- RotateTo is a number where 0 = Forward, 1 = Left, 2 = Backward, and 3 = Right
  288. local function look(RotateTo)
  289.     --This rids one odd occurance
  290.     if RotatePosition == "RIGHT" and RotateTo == 0 then
  291.         rot.left()
  292.         return
  293.     end
  294.     --
  295.  
  296.     rotateNumber = 0
  297.     if RotatePosition == "LEFT" then
  298.         rotateNumber = 1
  299.     elseif RotatePosition == "BACKWARD" then
  300.         rotateNumber = 2
  301.     elseif RotatePosition == "RIGHT" then
  302.         rotateNumber = 3
  303.     end
  304.  
  305.     rotateRight = rotateNumber - RotateTo
  306.     if rotateRight >= 0 then
  307.             for i = 1,rotateRight do
  308.                 rot.right()
  309.             end
  310.     else
  311.             for i = 1,math.abs(rotateRight) do
  312.                 rot.left()
  313.             end
  314.     end
  315.  
  316. end
  317.  
  318. dig.forward = function()
  319.     if turtle.detect() then
  320.         while not turtle.dig() do
  321.                 sleep(1)
  322.         end
  323.         return true
  324.     else
  325.         print("No Block to mine forward")
  326.         return false
  327.     end
  328. end
  329.  
  330. dig.up = function()
  331.     if turtle.detectUp() then
  332.         while not turtle.digUp() do
  333.                 sleep(1)
  334.         end
  335.         return true
  336.     else
  337.         print("No Block to mine up")
  338.         return false
  339.     end
  340. end
  341.  
  342. dig.down = function()
  343.     if turtle.detectDown() then
  344.         while not turtle.digDown() do
  345.                 sleep(1)
  346.         end
  347.         return true
  348.     else
  349.         print("No Block to mine down")
  350.         return false
  351.     end
  352. end
  353.  
  354. local function DigMoveForward()
  355.     if mov.forward(1) == false then
  356.         dig.forward()
  357.         sleep(0.5)
  358.         DigMoveForward()
  359.     end
  360. end
  361.  
  362. local function DigMoveUp()
  363.     if mov.up(1) == false then
  364.         dig.up()
  365.         sleep(0.5)
  366.         DigMoveUp()
  367.     end
  368. end
  369.  
  370. local function DigMoveDown()
  371.     if mov.down(1) == false then
  372.         dig.down()
  373.         sleep(0.5)
  374.         DigMoveDown()
  375.     end
  376. end
  377.  
  378. -- Begin BranchMining Code
  379. if UseGPS then
  380.     if rednet.open("right") == nil then
  381.         print("You had GPS Enabled but there is not a modem on this turtle")
  382.         return
  383.     end
  384. end
  385. -- Mine to BranchMining level
  386. local function MineToMine()
  387.     local x, y, z = 0
  388. if UseGPS then
  389.     x, y, z = gps.locate(5)
  390. else
  391.     x = XX
  392.     y = YY
  393.     z = ZZ
  394. end
  395. if MineDown then
  396.     x = tonumber(x)
  397.     y = tonumber(y)
  398.     z = tonumber(z)
  399.     if y > BranchMineLevel then
  400.         MineCount = y - BranchMineLevel
  401.         for i = 1,MineCount do
  402.             if mov.down(1) then
  403. --              Print("Coords: ",x," ",y - i," ",z)
  404.             else
  405.                 dig.down()
  406.                 mov.down(1)
  407. --              Print("Coords: ",x," ",y - i," ",z)
  408.             end
  409.         end
  410.     elseif y < BranchMineLevel then
  411.         MineCount = BranchMineLevel - y
  412.         for i = 1,MineCount do
  413.             if mov.up(1) then
  414. --              Print("Coords: ",x," ",y - i," ",z)
  415.             else
  416.                 dig.up()
  417.                 mov.up(1)
  418. --              Print("Coords: ",x," ",y - i," ",z)
  419.             end
  420.         end
  421.     end
  422. end
  423.     for i = 1,tonumber(PositionInBranchMine) do
  424.         DigMoveForward()
  425.     end
  426. end
  427.  
  428. local function DepositChest()
  429.     print("Depositing the Load...")
  430.     for i = IgnoreSlots + 1,15 do
  431.         turtle.select(i)
  432.         turtle.drop()
  433.     end
  434. end
  435.  
  436. local function GetCoalChest()
  437.     look(1) -- look left
  438.     turtle.select(15)
  439.     if turtle.suck() == false then
  440.         rot.right()
  441.         return false
  442.     else
  443.         if turtle.compareTo(16) then
  444.             turtle.transferTo(16)
  445.             turtle.drop()
  446.             rot.right()
  447.             return true
  448.         else
  449.             turtle.drop()
  450.             rot.right()
  451.             return false
  452.         end
  453.     end
  454. end
  455.  
  456. local function ReturnBack()
  457.     local xC, yC, zC  = 0
  458. if UseGPS then
  459.     xC, yC, zC = gps.locate(5)
  460. else
  461.     xC = XX
  462.     yC = YY
  463.     zC = ZZ
  464. end
  465. look(2) -- look backward
  466. Distance = 0
  467. xC = tonumber(xC)
  468. yC = tonumber(yC)
  469. zC = tonumber(zC)
  470. StartX = tonumber(StartX)
  471. StartY = tonumber(StartY)
  472. StartZ = tonumber(StartZ)
  473. if xC < StartX then
  474.     Distance = StartX - xC
  475. elseif xC > StartX then
  476.     Distance = xC - StartX
  477. elseif zC < StartZ then
  478.     Distance = StartZ - zC
  479. elseif zC > StartZ then
  480.     Distance = zC - StartZ
  481. end
  482.  
  483. for i = 1,Distance do
  484.     if mov.forward(1) == false then
  485.         dig.forward()
  486.         mov.forward(1)
  487.     end
  488. end
  489. look(0) -- look forward
  490. filewriteline("BranchMineData", 5, RotatePosition)
  491. if UseGPS then
  492.     xC, yC, zC = gps.locate(5)
  493. else
  494.     xC = XX
  495.     yC = YY
  496.     zC = ZZ
  497. end
  498. xC = tonumber(xC)
  499. yC = tonumber(yC)
  500. zC = tonumber(zC)
  501. StartX = tonumber(StartX)
  502. StartY = tonumber(StartY)
  503. StartZ = tonumber(StartZ)
  504.     if StartY > yC then
  505.         mov.up(StartY - yC)
  506.     elseif StartY < yC then
  507.         mov.down(yC - StartY)
  508.     end
  509.    
  510.     DepositChest()
  511.     if GetCoalChest() == false then
  512.         if Refuel() == false then
  513.             print("***Out of fuel***")
  514.             print("***NO FUEL IN CHEST, PROGRAM HALT***")
  515.             return
  516.         else
  517.             print("Returning to Mine")
  518.             MineToMine()
  519.             StartMining()
  520.         end
  521.     else
  522.         print("Returning to Mine")
  523.         MineToMine()
  524.         StartMining()
  525.     end
  526. end
  527.  
  528. local function Finish()
  529.     local xC, yC, zC = 0
  530. if UseGPS then
  531.     xC, yC, zC = gps.locate(5)
  532. else
  533.     xC = XX
  534.     yC = YY
  535.     zC = ZZ
  536. end
  537. look(2) -- look Backward
  538. RotatePosition = "BACKWARD"
  539. filewriteline("BranchMineData", 5, RotatePosition)
  540. Distance = 0
  541. if xC < StartX then
  542.     Distance = StartX - xC
  543. elseif xC > StartX then
  544.     Distance = xC - StartX
  545. elseif zC < StartZ then
  546.     Distance = StartZ - zC
  547. elseif zC > StartZ then
  548.     Distance = zC - StartZ
  549. end
  550.  
  551. for i = 1,Distance do
  552.     if mov.forward(1) == false then
  553.         dig.forward()
  554.         mov.forward(1)
  555.     end
  556. end
  557. look(0) -- look Forward
  558. RotatePosition = "FORWARD"
  559. filewriteline("BranchMineData", 5, RotatePosition)
  560. if UseGPS then
  561.     xC, yC, zC = gps.locate(5)
  562. else
  563.     xC = XX
  564.     yC = YY
  565.     zC = ZZ
  566. end
  567.  
  568.     if StartY > yC then
  569.         mov.up(StartY - yC)
  570.     elseif StartY < yC then
  571.         mov.down(yC - StartY)
  572.     end
  573.    
  574.     DepositChest()
  575.     print("Finished!")
  576. end
  577.  
  578. local function checkDown()
  579.     TimesChecked = 0
  580.     for i = 1,tonumber(IgnoreSlots) do
  581.         turtle.select(i)
  582.         if turtle.compareDown() == false then
  583.             TimesChecked = TimesChecked + 1
  584.             if TimesChecked == IgnoreSlots then
  585.                 dig.down()
  586.             end
  587.         else
  588.             return
  589.         end
  590.     end
  591. end
  592.  
  593. local function checkUp()
  594.     TimesChecked = 0
  595.     for i = 1,tonumber(IgnoreSlots) do
  596.         turtle.select(i)
  597.         if turtle.compareUp() == false then
  598.             TimesChecked = TimesChecked + 1
  599.             if TimesChecked == IgnoreSlots then
  600.                 dig.up()
  601.             end
  602.         else
  603.             return
  604.         end
  605.     end
  606. end
  607.  
  608. local function checkFront(leftWall,shouldCheckUp)
  609.     TimesChecked = 0
  610.     for i = 1,tonumber(IgnoreSlots) do
  611.         turtle.select(i)
  612.         if turtle.detect() and turtle.compare() == false then
  613.             TimesChecked = TimesChecked + 1
  614.             if TimesChecked == IgnoreSlots then
  615.                 DigMoveForward()
  616.                 InsertionAmount = InsertionAmount + 1
  617.                 InsertedIntoLeftWall = leftWall
  618.                 if leftWall == false then
  619.                     InsertedIntoRightWall = true
  620.                 else
  621.                     InsertedIntoRightWall = false
  622.                 end
  623.                 filewriteline("BranchMineData", 10, InsertedIntoLeftWall)
  624.                 filewriteline("BranchMineData", 11, InsertedIntoRightWall)
  625.                 filewriteline("BranchMineData", 12, InsertionAmount)
  626.                 filewriteline("BranchMineData", 13, shouldCheckUp)
  627.                 if shouldCheckUp then
  628.                     checkUp()
  629.                 else
  630.                     checkDown()
  631.                 end
  632.                 return checkFront(leftWall, shouldCheckUp)
  633.             end
  634.         else
  635.             if InsertedIntoLeftWall then
  636.                 look(3) --look right
  637.                 for i = 1,tonumber(InsertionAmount) do
  638.                     DigMoveForward()
  639.                 end
  640.                 InsertedIntoRightWall = false
  641.                 InsertedIntoLeftWall = false
  642.                 InsertionAmount = 0
  643.             elseif InsertedIntoRightWall then
  644.                 look(1) --look left
  645.                 for i = 1,tonumber(InsertionAmount) do
  646.                     DigMoveForward()
  647.                 end
  648.                 InsertedIntoRightWall = false
  649.                 InsertedIntoLeftWall = false
  650.                 InsertionAmount = 0
  651.             else
  652.                 filewriteline("BranchMineData", 10, InsertedIntoLeftWall)
  653.                 filewriteline("BranchMineData", 11, InsertedIntoRightWall)
  654.                 filewriteline("BranchMineData", 12, InsertionAmount)
  655.                 return false
  656.             end
  657.                 filewriteline("BranchMineData", 10, InsertedIntoLeftWall)
  658.                 filewriteline("BranchMineData", 11, InsertedIntoRightWall)
  659.                 filewriteline("BranchMineData", 12, InsertionAmount)
  660.             return true
  661.         end
  662.     end
  663. end
  664.  
  665. local function checkOresLEVEL1()
  666.     look(1) --look left
  667.     checkFront(true, false)
  668.     look(3) --look Right
  669.     checkFront(false, false)
  670.     look(0) --look forward
  671.     checkDown()
  672. end
  673.  
  674. local function checkOresLEVEL2()
  675.     look(1) --look left
  676.     checkFront(true, true)
  677.     look(3) --look Right
  678.     checkFront(false, true)
  679.     look(0) --look forward
  680.     checkUp()
  681. end
  682.  
  683. local function InventoryFull()
  684.     SlotsFull = 0
  685.     for i=1,16 do
  686.         if turtle.getItemCount(i) > 0 then
  687.             SlotsFull = SlotsFull + 1
  688.         end
  689.     end
  690.    
  691.     if SlotsFull == 16 then
  692.         return true;
  693.     else
  694.         return false;
  695.     end
  696. end
  697.  
  698. function StartMining()
  699.  
  700. level2 = false
  701. BlocksTillEnd = TunnelLength - PositionInBranchMine
  702.  
  703.     for i = 1,tonumber(BlocksTillEnd) do
  704.             if Refuel() == false then
  705.                 print("***Out of fuel***")
  706.                 ReturnBack()
  707.                 return
  708.             end
  709.            
  710.             if InventoryFull() then
  711.                 print("***Inventory Full***")
  712.                 ReturnBack()
  713.                 return
  714.             end
  715.             DigMoveForward()
  716.    
  717.         if level2 == false then
  718.             checkOresLEVEL1()
  719.            
  720.             DigMoveUp()
  721.            
  722.             checkOresLEVEL2()
  723.            
  724.             level2 = true
  725.             PositionInBranchMine = PositionInBranchMine + 1
  726.             filewriteline("BranchMineData", 4, PositionInBranchMine)
  727.             print("Position in BranchMine:",PositionInBranchMine)
  728.         else
  729.             checkOresLEVEL2()
  730.            
  731.             DigMoveDown()
  732.            
  733.             checkOresLEVEL1()
  734.            
  735.             level2 = false
  736.             PositionInBranchMine = PositionInBranchMine + 1
  737.             filewriteline("BranchMineData", 4, PositionInBranchMine)
  738.             print("Position in BranchMine:",PositionInBranchMine)
  739.         end
  740.     end
  741.     Finish()
  742. end
  743.  
  744.  
  745. -- Create or read data file
  746. if fs.exists("BranchMineData") then
  747.     readLines("BranchMineData")
  748.     StartX = tonumber(filereadline("BranchMineData", 1))
  749.     StartY = tonumber(filereadline("BranchMineData", 2))
  750.     StartZ = tonumber(filereadline("BranchMineData", 3))
  751.     PositionInBranchMine = tonumber(filereadline("BranchMineData", 4))
  752.     RotatePosition = filereadline("BranchMineData", 5)
  753.     print("Read Saved data. Start Position: "..StartX.." "..StartY.." "..StartZ..".")
  754.     print("With a mine position of: "..PositionInBranchMine.." .")
  755.     print("RotatePosition: "..RotatePosition..".")
  756.  
  757.     if UseGPS == false then
  758.         ForwardFacingDirection = filereadline("BranchMineData", 6)
  759.         XX = filereadline("BranchMineData", 7)
  760.         YY = filereadline("BranchMineData", 8)
  761.         ZZ = filereadline("BranchMineData", 9)
  762.         if ForwardFacingDirection == "SOUTH" then
  763.             PrimaryAxis = "Z"
  764.             SecondaryAxis = "X"
  765.         elseif ForwardFacingDirection == "NORTH" then
  766.             PrimaryAxis = "-Z"
  767.             SecondaryAxis = "-X"
  768.         elseif ForwardFacingDirection == "EAST" then
  769.             PrimaryAxis = "X"
  770.             SecondaryAxis = "-Z"
  771.         elseif ForwardFacingDirection == "WEST" then
  772.             PrimaryAxis = "-X"
  773.             SecondaryAxis = "Z"
  774.         end
  775.         print("ForwardFacingDirection: "..ForwardFacingDirection..",")
  776.     end
  777.  
  778.     InsertedIntoLeftWall = filereadline("BranchMineData", 10)
  779.     InsertedIntoRightWall = filereadline("BranchMineData", 11)
  780.     InsertionAmount = filereadline("BranchMineData", 12)
  781.     local shouldCheckUp = filereadline("BranchMineData", 13)
  782.     if string.match(InsertedIntoLeftWall, "true") or string.match(InsertedIntoRightWall, "true")  then
  783.         if turtle.detect() == false then
  784.             DigMoveForward()
  785.             InsertionAmount = InsertionAmount + 1
  786.             if string.match(shouldCheckUp,"true") then
  787.                 shouldCheckUp = true
  788.                 checkUp()
  789.             else
  790.                 shouldCheckUp = false
  791.                 checkDown()
  792.             end
  793.             checkFront(InsertedIntoLeftWall,shouldCheckUp)
  794.         else
  795.             if string.match(shouldCheckUp,"true") then
  796.                 shouldCheckUp = true
  797.                 checkUp()
  798.             else
  799.                 shouldCheckUp = false
  800.                 checkDown()
  801.             end
  802.             checkFront(InsertedIntoLeftWall,shouldCheckUp)
  803.         end
  804.     end
  805.     sleep(1)
  806.     ReturnBack()
  807. else
  808.     local x, y, z = 0
  809.     if UseGPS then
  810.         x, y, z = gps.locate(5)
  811.     else
  812.         x = StartX
  813.         y = StartY
  814.         z = StartZ
  815.     end
  816.  
  817.     if x == nil then
  818.         print("Could not obtain a GPS Connection.")
  819.         print("Please make sure you have a working GPS system.")
  820.         return
  821.     else
  822.         print("Current Coords: ",x," ",y," ",z)
  823.         StartX = x
  824.         StartY = y
  825.         StartZ = z
  826.     end
  827.     local tLines = {}
  828.     tLines[1] = StartX
  829.     tLines[2] = StartY
  830.     tLines[3] = StartZ
  831.     tLines[4] = PositionInBranchMine
  832.     tLines[5] = RotatePosition
  833.     if UseGPS == false then
  834.         if string.match(ForwardFacingDirection, "SOUTH") or string.match(ForwardFacingDirection, "NORTH") or string.match(ForwardFacingDirection, "EAST") or string.match(ForwardFacingDirection, "WEST") then
  835.         tLines[6] = ForwardFacingDirection
  836.         XX = x
  837.         YY = y
  838.         ZZ = z
  839.         tLines[7] = XX
  840.         tLines[8] = YY
  841.         tLines[9] = ZZ
  842.         if ForwardFacingDirection == "SOUTH" then
  843.             PrimaryAxis = "Z"
  844.             SecondaryAxis = "X"
  845.         elseif ForwardFacingDirection == "NORTH" then
  846.             PrimaryAxis = "-Z"
  847.             SecondaryAxis = "-X"
  848.         elseif ForwardFacingDirection == "EAST" then
  849.             PrimaryAxis = "X"
  850.             SecondaryAxis = "-Z"
  851.         elseif ForwardFacingDirection == "WEST" then
  852.             PrimaryAxis = "-X"
  853.             SecondaryAxis = "Z"
  854.         end
  855.         else
  856.             print("ForwardFacingDirection not correctly formatted.")
  857.             return
  858.         end
  859.     else
  860.         tLines[6] = 0
  861.         tLines[7] = 0
  862.         tLines[8] = 0
  863.         tLines[9] = 0
  864.     end
  865.     tLines[10] = InsertedIntoLeftWall
  866.     tLines[11] = InsertedIntoRightWall
  867.     tLines[12] = InsertionAmount
  868.     tLines[13] = false
  869.     writeLines("BranchMineData", tLines)
  870.    
  871.     -- Check fuel
  872. local FuelCount = turtle.getItemCount(16)
  873.     if FuelCount == 0 then
  874.         print("please put fuel in the last slot of the Turtle.")
  875.         return
  876.     else
  877.         if FuelCount < 10 then
  878.             print("Please put at least 10 of the fuel you are using in the Turtle.")
  879.             return
  880.         end
  881.     end
  882.     Refuel()
  883.     MineToMine()
  884.     StartMining()
  885. end
Advertisement
Comments
  • BalintX2
    1 year
    # text 0.10 KB | 0 0
    1. Somehow... this tries to mine bedrock in new versions of CC Tweaked.. Maybe add bedrock to blacklist
Add Comment
Please, Sign In to add comment