ebrobertson

Mining Toolkit

May 26th, 2023 (edited)
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 24.13 KB | Gaming | 0 0
  1. ---@diagnostic disable: unused-function
  2. --[[----------------------------------------
  3. Turtle Mining Script
  4. Author: Evan Robertson
  5. Created: 2023-05-25
  6. Last updated: 2023-05-25
  7. ToDo:
  8. - List of shovel/pickaxe blocks
  9. - Create a looping sort of system so the turtle isnt
  10. just mining in a straight line forever
  11. - Add a "place chest" at end of loop system and
  12. empty any non-fuel source items into chest
  13. - After each loop, turn right, dig three blocks (2 high),
  14. and then start new loop.
  15. - Switch out the "while" loop for a doLoop function
  16. that creates the loop system
  17. - Create the place chest/empty contents function
  18. - Check for bedrock, if found, move up
  19. ------------------------------------------]]
  20.  
  21. --[[----------------------------------------
  22. Variables
  23. ------------------------------------------]]
  24. local inventory          = {}
  25. local success            = true
  26. local isBlock            = false
  27. local blockType          = ""
  28. local fuelLevel          = 0
  29. local steps              = 0
  30. local pickaxeBlocks      = ""
  31. local shovelBlocks       = ""
  32. local ableToMove         = true
  33. local posY               = 0
  34. local buildingMaterial   = {"minecraft:cobblestone"}
  35. local noBreakList        = {"minecraft:torch","tconstruct:stone_torch"} -- list of blocks not to break
  36. local posHome            = 0 -- The starting position of the turtle
  37. local stepsToDestination = 0
  38. local miningPattern      = ""
  39. local margin             = 10 --should have about 10 fuel when we return home
  40. local torchPerSteps      = 10 --The number of steps taken before placing a torch
  41. local stepsTillToch      = 10
  42. local facing             = "forward" -- the direction the turtle started
  43. local noFuelList         = {"minecraft:torch"} -- list of items to exclude from using as fuel
  44. local globalDebug        = false -- when true, waits for user input
  45.  
  46. --[[----------------------------------------
  47. Functions
  48. ------------------------------------------]]
  49.  
  50.  
  51. --[[
  52.    setDirection
  53.    uses the current facing direction and returns the
  54.    new direction after a turn  
  55. ]]
  56. local function setDirection(turnDirection)
  57.    if turnDirection == "right" then
  58.       if facing == "forward" then
  59.          facing = "right"
  60.       end  
  61.       if facing == "right" then
  62.          facing = "backwards"
  63.       end  
  64.       if facing == "backwards" then
  65.          facing = "left"
  66.       end  
  67.       if facing == "left" then
  68.          facing = "forward"
  69.       end  
  70.    end -- end if right
  71.    if turnDirection == "left" then
  72.       if facing == "forward" then
  73.          facing = "left"
  74.       end  
  75.       if facing == "right" then
  76.          facing = "forwards"
  77.       end  
  78.       if facing == "backwards" then
  79.          facing = "right"
  80.       end  
  81.       if facing == "left" then
  82.          facing = "backwards"
  83.       end  
  84.    end -- end if left  
  85. end -- end function setDirection
  86.  
  87. --[[ Check all inventory slots for a fuel source and refuel --]]
  88. local function refuelTurtle()
  89.    local refuelSuccess
  90.    local slotInfo
  91.    --[[ Default to false ]]
  92.    refuelSuccess = false
  93.    for i = 1, 16 do
  94.       turtle.select(i)
  95.       slotInfo = turtle.getItemDetail()
  96.       if type(slotInfo) == "table" then
  97.          for key, value in pairs(noFuelList) do
  98.             if slotInfo.name ~= value then
  99.                refuelSuccess = turtle.refuel()
  100.                if refuelSuccess then
  101.                   break
  102.                end  
  103.             end
  104.          end
  105.       end      
  106.    end --[[ end for loop --]]
  107.    if refuelSuccess then
  108.       print("Refuel success, Fuel level: ", turtle.getFuelLevel())
  109.    else
  110.       print("Refuel failed")
  111.    end
  112.    return refuelSuccess
  113. end --[[ end function refuleTurtle --]]
  114.  
  115. --[[
  116.    findBuildingMaterial
  117.    Checks all inventory slots for applicable building blocks
  118.    returns if block was found and the slot its in
  119. ]]
  120. local function findBuildingMaterial()
  121.    local functionSuccess = false
  122.    local success = true
  123.    local slotNum = 0
  124.    local slotInfo = {}
  125.    local startIndex = 0
  126.    local endIndex = 0
  127.    local errReason = ""
  128.    for i = 1, 16 do
  129.       -- select each slot
  130.       success = turtle.select(i)
  131.  
  132.       -- if select was good
  133.       if success then
  134.          slotInfo = turtle.getItemDetail()
  135.          -- make sure it returns a table, else nothing there
  136.          if type(slotInfo) == "table" then
  137.             -- check the item's name for acceptable building materials like cobblestone
  138.             for key, value in pairs(buildingMaterial) do
  139.                if slotInfo.name == value then
  140.                   print("Applicable building material found")
  141.                   slotNum = i
  142.                   functionSuccess = true
  143.                   break
  144.                end -- end compare to list of materials
  145.             end -- end for loop            
  146.          end -- end if slot not empty
  147.       end -- end if select succeeds
  148.  
  149.    end -- end for loop
  150.  
  151.    return functionSuccess, slotNum
  152.  
  153. end -- end function findBuildingMaterial
  154.  
  155. --[[
  156.    faceLeft
  157.    Makes the turtle face left
  158. ]]
  159. local function faceLeft()
  160.    if facing == "foward" then
  161.       turtle.turnLeft()
  162.       setDirection("left")  
  163.    elseif facing == "right" then
  164.       turtle.turnLeft()
  165.       setDirection("left")  
  166.       turtle.turnLeft()
  167.       setDirection("left")  
  168.    elseif facing == "backwards" then
  169.       turtle.turnRight()
  170.       setDirection("right")  
  171.    end  
  172. end -- end function faceLeft
  173.  
  174. --[[
  175.    faceRight
  176.    Makes the turtle face right
  177. ]]
  178. local function faceRight()
  179.    if facing == "backwards" then
  180.       turtle.turnLeft()
  181.       setDirection("left")  
  182.    elseif facing == "left" then
  183.       turtle.turnLeft()
  184.       setDirection("left")  
  185.       turtle.turnLeft()
  186.       setDirection("left")  
  187.    elseif facing == "forwards" then
  188.       turtle.turnRight()
  189.       setDirection("right")  
  190.    end  
  191. end -- end function faceRight
  192.  
  193. --[[
  194.    faceBackwards
  195.    Makes the turtle face backwards
  196. ]]
  197. local function faceBackwards()
  198.    if facing == "foward" then
  199.       turtle.turnLeft()
  200.       setDirection("left")
  201.       turtle.turnLeft()
  202.       setDirection("left")  
  203.    elseif facing == "right" then
  204.       turtle.turnRight()
  205.       setDirection("right")  
  206.       turtle.turnLeft()
  207.       setDirection("left")  
  208.    elseif facing == "left" then
  209.       turtle.turnLeft()
  210.       setDirection("left")  
  211.    end  
  212. end -- end function faceBackwards
  213.  
  214. --[[
  215.    faceForwards
  216.    Makes the turtle face forwards
  217. ]]
  218. local function faceForwards()
  219.    if facing == "backwards" then
  220.       turtle.turnLeft()
  221.       setDirection("left")
  222.       turtle.turnLeft()
  223.       setDirection("left")  
  224.    elseif facing == "left" then
  225.       turtle.turnRight()
  226.       setDirection("right")  
  227.       turtle.turnLeft()
  228.       setDirection("left")  
  229.    elseif facing == "right" then
  230.       turtle.turnLeft()
  231.       setDirection("left")  
  232.    end  
  233. end -- end function faceForwards
  234.  
  235. --[[
  236.    placeTorch
  237.    checks for and places a torch
  238. ]]
  239. local function placeTorch()
  240.    local slotInfo = {}
  241.    for i = 1, 16 do
  242.       -- select each slot
  243.       turtle.select(i)
  244.       slotInfo = turtle.getItemDetail()
  245.       if type(slotInfo) == "table" then
  246.          if slotInfo.name == "minecraft:torch" then
  247.             print("Torch found, placing above")            
  248.                turtle.select(i)
  249.                turtle.placeUp()
  250.          end -- end if torch found in item slot
  251.       end -- end if type is table
  252.    end -- end for loop
  253.  
  254. end -- end function placeTorch
  255.  
  256. --[[
  257.    buildForward
  258.    Accepts an inventory slot (1-16) and places the block in that slot forward
  259.    returns true if placeDown was successful
  260. ]]
  261. local function buildForward(slotNum)
  262.    local success = true
  263.    local errReason = true
  264.    local functionSuccess = true
  265.  
  266.    -- select the inventory slot of the parameter slotNum
  267.    success = turtle.select(slotNum)
  268.    if success then
  269.       -- Attempt to place the block
  270.       success, errReason = turtle.place()
  271.       if not success then
  272.          print("Place forward failed, reason: ", errReason)
  273.          functionSuccess = false
  274.       else
  275.          print("Place forward success!")
  276.          functionSuccess = true
  277.       end -- end if placeDown failed
  278.    else
  279.       print("Could not select slot. Bad slot number? ", slotNum)  
  280.       functionSuccess = false
  281.    end -- if success was good
  282.    return functionSuccess
  283. end -- end function buildForward
  284.  
  285. --[[
  286.    buildDown
  287.    Accepts an inventory slot (1-16) and places the block in that slot down
  288.    returns true if placeDown was successful
  289. ]]
  290. local function buildDown(slotNum)
  291.    local success = true
  292.    local errReason = true
  293.    local functionSuccess = true
  294.  
  295.    -- select the inventory slot of the parameter slotNum
  296.    success = turtle.select(slotNum)
  297.    if success then
  298.       -- Attempt to place the block
  299.       success, errReason = turtle.placeDown()
  300.       if not success then
  301.          print("Place down failed, reason: ", errReason)
  302.          functionSuccess = false
  303.       else
  304.          print("Place down success!")
  305.          functionSuccess = true
  306.       end -- end if placeDown failed
  307.    else
  308.       print("Could not select slot. Bad slot number? ", slotNum)  
  309.       functionSuccess = false
  310.    end -- if success was good
  311.    return functionSuccess
  312. end -- end function buildDown
  313.  
  314. --[[ inspect the block in front of the turtle --]]
  315. --[[ returns false when there is air in front --]]
  316. --[[ will be used in more depth later,        --]]
  317. --[[ like comparing against a list of blocks  --]]
  318. local function checkFrontFacingBlock()
  319.    local inspectSuccess
  320.    local block
  321.    inspectSuccess, block = turtle.inspect()
  322.    return inspectSuccess, block
  323. end --[[ end function checkFrontFacingBlock --]]
  324.  
  325. local function checkTopFacingBlock()
  326.    local inspectSuccess
  327.    local block
  328.    inspectSuccess, block = turtle.inspectUp()
  329.    return inspectSuccess, block
  330. end --[[ end function checkFrontFacingBlock --]]
  331.  
  332. local function checkBottomFacingBlock()
  333.    local inspectSuccess
  334.    local block
  335.    inspectSuccess, block = turtle.inspectDown()
  336.    return inspectSuccess, block
  337. end --[[ end function checkFrontFacingBlock --]]
  338.  
  339. --[[ Functions to move, dig, refuel, etc ]]
  340.  
  341. --[[
  342.    digUntilEmpty
  343.    Digs in front of the turtle until no block is left
  344.    Ideal for clearing falling sand/gravel
  345.    Retruns false when no block is detected
  346. ]]
  347. local function digUntilEmpty(direction)
  348.    local blockDetected = true
  349.    local block
  350.    local blockFound
  351.    local skip = false
  352.    while blockDetected do
  353.       if direction == "up" then
  354.          blockDetected = turtle.detectUp()
  355.          blockFound, block = turtle.inspectUp()
  356.          for key, value in pairs(noBreakList) do
  357.             if block.name == value then
  358.                break
  359.             end
  360.          end
  361.          turtle.digUp()
  362.       elseif direction == "down" then
  363.          blockDetected = turtle.detectDown()
  364.          turtle.digDown()
  365.       else
  366.          blockDetected = turtle.detect()
  367.          turtle.dig()
  368.       end -- end if direction
  369.      
  370.    end -- end while loop
  371.    return blockDetected
  372.  end -- end function digUntilEmpty
  373. --[[
  374.    moveForward
  375.    Checks the block in front, if solid digs and moves forward
  376.    if air, just moves forward
  377.    returns true if dig and/or move succeeded
  378. ]]
  379. local function moveForward(positionY)
  380.    local isBlock = false
  381.    local block = ""
  382.    local success = true
  383.    local refuelSuccess = false
  384.    local functionSuccess = true
  385.    local slotNum = 0
  386.    
  387.    -- IF the Y position is 0, meaning on the floor, check for gaps
  388.    if positionY == 0 then
  389.       -- Start by checking block below. If non-solid, use material
  390.       -- to fill it in to create a solid walking surface
  391.       isBlock, block = checkBottomFacingBlock()
  392.  
  393.       -- if not solid
  394.       if not isBlock then
  395.          success, slotNum = findBuildingMaterial()
  396.          if success then
  397.             success = buildDown(slotNum)
  398.             if not success then
  399.                print("Could not build below turtle. Watch your step!")
  400.             end -- end if build down failed
  401.          else
  402.             print("No applicable building material found. Watch your step!")
  403.          end -- end if no building mats found      
  404.       end -- end if not solid block
  405.    end -- end if position Y is 0
  406.  
  407.    digUntilEmpty("forward")
  408.  
  409.    print("Moving forward")
  410.    success = turtle.forward()
  411.    if not success then
  412.       refuelSuccess = refuelTurtle()
  413.       if not refuelSuccess then
  414.          functionSuccess = false
  415.       else
  416.          print("Refuel successful, moving again")
  417.          --[[ Will always be true since refuel was good ]]
  418.          success = turtle.forward()
  419.          if not success then
  420.             print("Move failed, retrying once")
  421.             success = turtle.forward()
  422.             if not success then
  423.                functionSuccess = false
  424.             end
  425.          end
  426.       end -- end if refuel fails
  427.    end -- end if move failed    
  428.    
  429.    -- return success, true if dug and/or moved,
  430.    -- false if any action and refueling failed
  431.    if functionSuccess then
  432.       -- clear block above
  433.       digUntilEmpty("up")  
  434.       steps = steps +1
  435.       -- decrement number of steps required till placing a torch
  436.       stepsTillToch = stepsTillToch - 1
  437.       print("steps till torch:", stepsTillToch)
  438.       if stepsTillToch == 0 then        
  439.          print("placing torch!")
  440.          placeTorch()
  441.          -- reset the numberof steps still torch place
  442.          stepsTillToch = torchPerSteps
  443.       end
  444.    end
  445.  
  446.    if globalDebug then
  447.       print("")
  448.       print("Hit enter to continue")
  449.       read()
  450.    end -- end if debug is on
  451.    return functionSuccess
  452.  
  453. end -- end function moveForward
  454.  
  455. --[[
  456.    moveUpward
  457.    Checks the block above, if solid digs and moves up
  458.    if air, just moves up
  459.    returns true if dig and/or move succeeded
  460. ]]
  461. local function moveUpward()
  462.    local isBlock = false
  463.    local block = ""
  464.    local success = true
  465.    local refuelSuccess = false
  466.    local functionSuccess = true
  467.  
  468.    digUntilEmpty("up")  
  469.  
  470.    print("Moving upward")
  471.    success = turtle.up()
  472.    if not success then
  473.       refuelSuccess = refuelTurtle()
  474.       if not refuelSuccess then
  475.          functionSuccess = false
  476.       else
  477.          print("Refuel successful, moving again")
  478.          --[[ Will always be true since refuel was good ]]
  479.          success = turtle.up()
  480.       end -- end if refuel fails
  481.    end -- end if move failed
  482.  
  483.    -- return success, true if dug and/or moved,
  484.    -- false if any action and refueling failed
  485.    return functionSuccess
  486.  
  487. end -- end function moveUpward
  488.  
  489. --[[
  490.    moveDownward
  491.    Checks the block below, if solid digs and moves down
  492.    if air, just moves down
  493.    returns true if dig and/or move succeeded
  494. ]]
  495. local function moveDownward()
  496.    local isBlock = false
  497.    local block = ""
  498.    local success = true
  499.    local refuelSuccess = false
  500.    local functionSuccess = true
  501.  
  502.    -- Check if block is solid, and return what kind
  503.    isBlock, block = checkBottomFacingBlock()
  504.  
  505.    -- if solid
  506.    if isBlock then
  507.  
  508.       -- dig
  509.       print("Solid block below, digging and moving")
  510.       success = turtle.digDown('right')
  511.  
  512.       if not success then
  513.          print("Dig failed, attempting refuel")
  514.          refuelSuccess = refuelTurtle()
  515.          if not refuelSuccess then  
  516.             functionSuccess = false
  517.          else
  518.             print("Refuel successful, digging again")
  519.             --[[ Will always be true since refuel was good ]]
  520.             success = turtle.digDown('right')
  521.          end -- end if refuel fails
  522.       end -- end if dig fails
  523.  
  524.       -- if dig succeeds, move up
  525.       if success then
  526.          
  527.          print("Dig Successfull, moving Down")
  528.  
  529.          success = turtle.down()
  530.          if not success then
  531.             print("Move failed, attempting refuel")
  532.             refuelSuccess = refuelTurtle()
  533.             if not refuelSuccess then
  534.                functionSuccess = false
  535.             else
  536.                print("Refuel successful, moving again")
  537.                --[[ Will always be true since refuel was good ]]
  538.                success = turtle.down()
  539.             end -- end if refuel fails
  540.          end -- end if move fails
  541.  
  542.       end -- end if dig succeeds
  543.  
  544.    -- else if block is not solid/air  
  545.    else
  546.  
  547.       print("Non-solid block, just moving")
  548.       success = turtle.down()
  549.       if not success then
  550.          refuelSuccess = refuelTurtle()
  551.          if not refuelSuccess then
  552.             functionSuccess = false
  553.          else
  554.             print("Refuel successful, moving again")
  555.             --[[ Will always be true since refuel was good ]]
  556.             success = turtle.down()
  557.          end -- end if refuel fails
  558.       end -- end if move failed
  559.  
  560.    end -- end if block is solid
  561.    
  562.    -- return success, true if dug and/or moved,
  563.    -- false if any action and refueling failed
  564.    return functionSuccess
  565.  
  566. end -- end function moveDownward
  567.  
  568. --[[
  569.    requiredFuel
  570.    Accepts a destination like "home" and the current steps travelled
  571.    returns the fuel level required to travel there
  572.    Note - 1 fuel count equals 1 block, and each movement is tracked in steps
  573. ]]
  574. local function requiredFuel(destination, stepsMoved)
  575.  
  576.    local difference = stepsMoved - destination
  577.    return difference
  578.  
  579. end -- end function requiredFuel
  580.  
  581. --[[
  582.    goToDestination
  583.    Accepts a destination and mining pattern
  584.    Then executes the required steps to go to that destination
  585.    returns true if it made it to it's destination
  586. ]]
  587. local function goToDestination(destination, turns, goingTowardsHome)
  588.    -- if pattern is strip mining
  589.    if miningPattern == "1" then
  590.       -- Turn the turtle backwards
  591.       print("Turning turtle around")
  592.       if facing == "foward" then
  593.          turtle.turnRight()
  594.          setDirection("right")
  595.          turtle.turnRight()
  596.          setDirection("right")  
  597.       elseif facing == "left" then
  598.          turtle.turnLeft()
  599.          setDirection("left")  
  600.       elseif facing == "right" then
  601.          turtle.turnRight()
  602.          setDirection("right")  
  603.       end
  604.      
  605.       -- Make sure we're on the floor
  606.       if posY == 1 then
  607.          moveDownward()
  608.       end
  609.       -- Then exectue moveForward for the number of steps taken
  610.       for i=1,steps do                    
  611.          moveForward(posY)
  612.          -- Each moveForward increments the steps by 1 so
  613.          -- counteract that with -2
  614.          steps = steps - 2        
  615.       end -- end for loop
  616.       -- Then we handle however many turns were made
  617.       turtle.turnRight()
  618.       setDirection("right")
  619.       for i=1,turns do
  620.          print("Accounting for number of shafts made")
  621.          moveForward(posY)
  622.          turns = turns - 2        
  623.       end
  624.       print("Turning turtle back around")
  625.       turtle.turnRight()
  626.       setDirection("right")
  627.       print("Turtle is now facing: ", facing)
  628.    end -- end if pattern 1
  629.  
  630.    -- if steps == 0 then we retraced all our steps and made it
  631.    return steps == 0
  632.  
  633. end -- end function goToDestination
  634.  
  635. --[[
  636.    checkDistanceToHome
  637.    returns the distance required to make it home
  638.    If distance is equal to fuel level, go home
  639. ]]
  640. local function checkDistanceToHome(turns, goingTowardsHome)
  641.    local wentHome = false
  642.    stepsToDestination = requiredFuel(posHome, steps)  
  643.    print("Steps to destination:", stepsToDestination)  
  644.    print("Fuel level:", turtle.getFuelLevel())
  645.    if stepsToDestination > turtle.getFuelLevel() - margin then
  646.       print("Steps > fuel, checking for fuel")
  647.       -- First attempt to refuel
  648.       success = refuelTurtle()
  649.       -- if can't refuel, return home
  650.       if not success then
  651.          print("Returning home")
  652.          success = goToDestination(posHome, turns, goingTowardsHome)
  653.          if success then
  654.             print("Returned home")
  655.             wentHome = true
  656.          end
  657.       end
  658.    end
  659.    -- return whether or not the turtle went home
  660.    return wentHome
  661. end -- end function checkDistanceToHome
  662.  
  663. --[[
  664.    getMiningPattern
  665.    Requests input from the user
  666.    returns the selected pattern
  667. ]]
  668. local function getMiningPattern()
  669.    local awaitInput = true
  670.    local input = ""
  671.    local patterns = "1,"
  672.  
  673.    while awaitInput do
  674.  
  675.       print("Select the desired mining pattern")
  676.       print("1. Strip Mining")
  677.       print("Type help for more info")
  678.       input = read()
  679.       -- Check if the accepted answer is one of the available patterns
  680.       if string.find("help", input) then
  681.          print("Enter the selection for more info on it, or enter anything else to return.")
  682.          input = read()
  683.          if string.find("1", input) then
  684.             print("Strip Mines:")
  685.             print("A two block tall shaft that goes in the direction the turtle is facing")
  686.             print("Hit enter to continue")
  687.             read()
  688.             print("A desired depth is input")
  689.             print("When the turtle reaches the desired depth, turns right, moves a block over, and mines another shaft back.")
  690.             print("Hit enter to continue")
  691.             read()
  692.          end -- end help for strip mine
  693.       else
  694.          if string.find(patterns, input) then
  695.             awaitInput = false
  696.             break
  697.          else
  698.             print("Not an option, try again")
  699.          end -- end check for correct pattern
  700.       end -- end print help
  701.  
  702.    end -- end while loop
  703.  
  704.    return input
  705.  
  706. end -- end function getMiningPattern
  707.  
  708. local function stripMinePattern()
  709.    local input
  710.    local lengthOfMine
  711.    local inputGood = false
  712.    local turns = 0
  713.  
  714.    -- When the turtle is going towards "home" track steps differently
  715.    local goingTowardsHome = false
  716.  
  717.    while not inputGood do
  718.       print("How many blocks forward should the turtle mine?")
  719.       input = read()
  720.       lengthOfMine = tonumber(input)
  721.       if type(lengthOfMine) ~= "number" then
  722.          print("Please enter a number")
  723.       else
  724.          inputGood = true
  725.       end -- end if input not number
  726.    end -- end while
  727.  
  728.    print("Beginning strip mine")
  729.    while ableToMove do
  730.      
  731.       digUntilEmpty("up")
  732.            
  733.       success = moveForward(posY)
  734.       if not success then
  735.          print("Could not move forward")
  736.          ableToMove = false
  737.          break      
  738.       end -- end if move failed
  739.  
  740.       -- when going towards home, negate the moveForward
  741.       -- step increment, and subtract one as well, as we're
  742.       -- going towards "home"
  743.       if goingTowardsHome then
  744.          steps = steps - 2
  745.       end -- end if going towards home
  746.  
  747.       success = checkDistanceToHome(turns, goingTowardsHome)
  748.       if success then
  749.          print("Went home! Exiting mining loop.")
  750.          ableToMove = false
  751.          break
  752.       end
  753.      
  754.       -- If it reaches the desired depth, turn and make another shaft
  755.       if steps >= lengthOfMine then
  756.          turtle.turnRight()
  757.          setDirection("right")
  758.          success = moveForward(posY)
  759.          digUntilEmpty("up")
  760.          -- negate the step increment
  761.          steps = steps - 1
  762.          -- increment turns
  763.          if success then
  764.             turns = turns + 1
  765.          end -- end if move was successful
  766.          turtle.turnRight()
  767.          setDirection("right")
  768.          goingTowardsHome = true
  769.       elseif steps == 0 then
  770.          turtle.turnLeft()
  771.          setDirection("left")
  772.          success = moveForward(posY)
  773.          digUntilEmpty("up")
  774.          -- negate the step increment
  775.          steps = steps - 1
  776.          -- increment turns
  777.          if success then
  778.             turns = turns + 1
  779.          end -- end if move was successful
  780.          turtle.turnLeft()
  781.          setDirection("left")
  782.          goingTowardsHome = false
  783.       end
  784.  
  785.    end --[[ end while turtle foward loop --]]
  786. end -- end function stripMinePattern
  787.  
  788. --[[----------------------------------------
  789. Startup jobs
  790. ------------------------------------------]]
  791. print("Initializing Mining Toolkit V0.1")
  792.  
  793. --[[ check for fuel --]]
  794. fuelLevel = turtle.getFuelLevel()
  795. if fuelLevel == 0 then
  796.    success = refuelTurtle()
  797. end
  798.  
  799. if success then
  800.    fuelLevel = turtle.getFuelLevel()
  801. end
  802.  
  803. if fuelLevel == 0 then
  804.    print("Not enough fuel")
  805.    ableToMove = false
  806. else
  807.    -- Reset selected inventory to slot 1
  808.    turtle.select(1)
  809.    miningPattern = getMiningPattern()
  810.    if miningPattern == "1" then
  811.       stripMinePattern()
  812.    end
  813. end
Add Comment
Please, Sign In to add comment