Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Turtle Mining Script Mk2
- Author: Evan Robertson
- Created: 2023-05-26
- Updated: 2023-06-05
- Todo -
- - Make item find and place more efficient - any time we're looping through
- the turtle's inventory, use the inventory table instead.
- - Ideally a better way to indicate if a previously empty slot has a new item in it
- - more mining patterns, custom patterns.
- ]]
- --[[
- Define Globals
- Only to be set using get/setter functions
- ]]
- local pattern -- the mining pattern selected
- local steps -- number of steps taken/blocks moved
- local reserve -- amount of fuel to have leftover
- local distanceToMine -- the distance to mine set by player
- local mostRecentNilIndex -- the most recent index that was nil during checkInventory
- --[[
- Set Globals
- ]]
- pattern = ""
- steps = 0
- reserve = 10
- distanceToMine = 1
- mostRecentNilIndex = 1
- --[[
- Lists
- These are hardcoded lists used for validation
- Example - comparing the inspected block to a list of blocks
- ]]
- local noFuelList = {
- "minecraft:torch",
- "tconstruct:stone_torch"
- }
- local buildMaterialList = {
- "minecraft:cobblestone",
- "minecraft:dirt"
- }
- local noDropList = {
- "minecraft:torch",
- "tconstruct:stone_torch",
- "minecraft:coal"
- }
- local noBreakList = {
- "minecraft:chest",
- "ironchest:iron_chest"
- }
- -- Used to track contents of turtle inventory
- local inventory = {}
- --[[
- moveCursorDown
- A simple function to move the cursor down one line and to the start of the line when writing to screen
- ]]
- local function moveCursorDown(line)
- term.setCursorPos(1,line)
- line = line + 1
- return line
- end -- end moveCursorDown
- --[[
- displayLogs
- displays a sort of menu with stats and info about the run
- ]]
- local function displayLogs(rows,steps,depth,height,posY,portionOfLoop, goingForward)
- local line = 1
- term.clear()
- line = moveCursorDown(line)
- term.write(" ___________")
- line = moveCursorDown(line)
- term.write("| |")
- line = moveCursorDown(line)
- term.write("|Loop ")
- term.write(portionOfLoop)
- if portionOfLoop == "start" then
- term.write(" |")
- else
- term.write(" |")
- end
- line = moveCursorDown(line)
- term.write("|Rows: ")
- term.write(rows)
- term.write("|")
- line = moveCursorDown(line)
- term.write("|Steps: ")
- term.write(steps)
- term.write("|")
- line = moveCursorDown(line)
- term.write("|Depth: ")
- term.write(depth)
- term.write("|")
- line = moveCursorDown(line)
- term.write("|Height: ")
- term.write(height)
- term.write("|")
- line = moveCursorDown(line)
- term.write("|Pos Y: ")
- term.write(posY)
- term.write("|")
- line = moveCursorDown(line)
- term.write("|Direction:")
- if goingForward then
- term.write("f|")
- else
- term.write("b|")
- end
- line = moveCursorDown(line)
- term.write("|___________|")
- line = moveCursorDown(line)
- end -- end displayLogs
- --[[
- setDistanceToMine
- sets the distance the turtle should mine
- ]]
- local function setDistanceToMine(distance)
- distanceToMine = distance
- end -- end setDistanceToMine
- --[[
- getDistanceToMine
- gets the distance the turtle should mine
- ]]
- local function getDistanceToMine()
- return distanceToMine
- end -- end setDistanceToMine
- --[[
- setMostRecentNilIndex
- sets the last indexed inventory slot that was empty/nile
- ]]
- local function setMostRecentNilIndex(newIndex)
- mostRecentNilIndex = newIndex
- end -- end setMostRecentNilIndex
- --[[
- getMostRecentNilIndex
- gets the last indexed inventory slot that was empty/nile
- ]]
- local function getMostRecentNilIndex()
- return mostRecentNilIndex
- end -- end getMostRecentNilIndex
- --[[
- displayMenu
- Displays a list of menu options
- ]]
- local function displayMenu()
- term.clear()
- print("Mining Toolkit Mk2")
- print("")
- print("Please choose an option:")
- print("")
- print("1. Strip mining")
- print("2. Custom Height strip mining")
- print("")
- print("Type help to view a help menu or exit to quit")
- end -- end displayMenu
- --[[
- displayHelpMenu
- Displays a list of help menu options
- ]]
- local function displayHelpMenu()
- term.clear()
- print("Mining Toolkit Mk2 Help Screen")
- print("")
- print("Please choose an option to view help on:")
- print("")
- print("1. Strip mining")
- print("2. Custom Height strip mining")
- print("")
- print("Enter exit to return to main menu")
- end -- end displayHelpMenu
- --[[
- displayPatternHelp
- Displays a help message for the given pattern
- input - a string representing a valid patern
- ]]
- local function displayPatternHelp(pattern)
- if type(pattern) ~= "string" then
- print("Must enter a valid selection")
- return
- else
- if pattern == "1" then
- term.clear()
- print("Strip Mine Program:")
- print("Mines a 1x2 (wxh) tunnel for the length specified")
- print("")
- print("Tip: Include some torches, fuel, and cobblestone in the turtle's inventory so it can fill gaps and light up the mine as it goes.")
- print("")
- print("Press Enter to return")
- read()
- elseif pattern == "2" then
- term.clear()
- print("Tall strip Mine Program:")
- print("Mines a 1xn (wxh) tunnel for the length specified, where n is a user specified height")
- print("")
- print("Tip: Include some torches, fuel, and cobblestone in the turtle's inventory so it can fill gaps and light up the mine as it goes.")
- print("")
- print("Press Enter to return")
- read()
- end
- end
- end -- end displayPatternHelp
- --[[
- setSteps
- sets the number of steps taken/blocks moved
- input - the number of steps to increment by (1 by default)
- returns the total number of steps moved
- ]]
- local function setSteps(incrementBy)
- if type(incrementBy) == nil then
- steps = steps + 1
- else
- steps = steps + incrementBy
- end
- return steps
- end -- end setSteps
- --[[
- setPattern
- input - string, pattern to set
- sets the global pattern to be used for mining
- ]]
- local function setPattern(newPattern)
- if type(newPattern) ~= "string" then
- print("A valid pattern must be provided (string) not,", type(newPattern))
- elseif newPattern == "stripMine" then
- pattern = newPattern
- else
- print("Not a valid pattern.")
- end
- end -- end setPattern
- --[[
- findItem
- input - string, item to find
- returns the inventory slot the item is in or nil if not found
- ]]
- local function findItem(itemName)
- local item = {}
- if type(itemName) ~= "string" then
- print("A valid item name must be provided (string) not", type(itemName))
- else
- for i=1,16 do
- turtle.select(i)
- item = turtle.getItemDetail()
- if type(item) == "table" then
- if item.name == itemName then
- turtle.select(1)
- return i
- end
- end
- end
- -- item not found
- print("Item not found: ", itemName)
- turtle.select(1)
- return nil
- end
- end -- end findItem
- --[[
- placeItem
- input - inventory slot containing item to place, direction to place
- returns true if place was successful and the reason if it failed
- ]]
- local function placeItem(itemSlot, direction)
- local placeSuccess = false
- local reason = ""
- if type(itemSlot) ~= "number" then
- print("A valid inventory slot must be provided (number) not", type(itemSlot))
- elseif type(direction) ~= "string" then
- print("A valid direction must be provided (string)(up,down) not", type(direction))
- else
- turtle.select(itemSlot)
- if direction == "up" then
- placeSuccess, reason = turtle.placeUp()
- elseif direction == "down" then
- placeSuccess, reason = turtle.placeDown()
- elseif direction == "backwards" then
- turtle.turnRight()
- turtle.turnRight()
- placeSuccess, reason = turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- elseif direction == "forwards" then
- placeSuccess, reason = turtle.place()
- else
- print("Invalid direction")
- end
- end
- turtle.select(1)
- return placeSuccess, reason
- end -- end placeItem
- --[[
- refuel
- checks inventory for fuel items and refules the turtle with them
- retuns true if refuel was successful
- ]]
- local function refuel()
- local item = {}
- local refuelSuccess = false
- for i=1,16 do
- turtle.select(i)
- item = turtle.getItemDetail()
- if type(item) == "table" then
- for key, value in pairs(noFuelList) do
- if value ~= item.name then
- refuelSuccess = turtle.refuel()
- if refuelSuccess then
- turtle.select(1)
- return refuelSuccess
- end
- end
- end
- end
- end
- turtle.select(1)
- return refuelSuccess
- end -- end refuel
- --[[
- indexInventory
- Loops through the inventory and builds the inventory table
- ]]
- local function indexInventory()
- local item = {}
- for i=1,16 do
- turtle.select(i)
- item = turtle.getItemDetail()
- -- if item slot is not empty
- if type(item) == "table" then
- inventory[i] = item.name
- else
- -- else that inventory slot is empty so set to nil
- inventory[i] = nil
- end
- end -- for loop
- end -- end indexInventory
- --[[
- sortInventory
- checks the currently selected item and loops through inventory
- to find matching ones. When matching is found, moves to appropriate slot
- returns the result of transferTo, which is true if some items were moved
- ]]
- local function sortInventory()
- indexInventory()
- for i=1,16 do
- -- if slot is not empty, and is not full, compare to other slots
- if inventory[i] ~= nil and turtle.getItemCount(i) < 64 then
- for z=1,16 do
- if i ~= z then
- -- if slot is not empty, and is not full, do the comparison
- if inventory[z] ~= nil and turtle.getItemCount(z) < 64 then
- if inventory[i] == inventory[z] then
- turtle.select(z)
- turtle.transferTo(i, 64)
- -- if we managed to move all the items
- if turtle.getItemCount(z) == 0 then
- -- reset z to nil now that it's empty
- inventory[z] = nil
- end
- end -- if items match
- end -- if z is not empty or full
- end -- if i ~= zdifferent slots
- end -- for z 1-16
- end -- if i slot not empty or full
- end -- for i 1-16
- turtle.select(1)
- end -- end sortInventory
- --[[
- compareBlockToInventory
- Compare the block in front of the turtle with inventory
- and select matching blocks in inventory
- won't work with dust or gem types so sort inventory is still relevant, unless dust/gems get coordinated list
- ]]
- local function compareBlockToInventory()
- end -- end compareBlockToInventory
- --[[
- checkFullInventory
- Checks to see if the inventory is full
- returns true if its full
- ]]
- local function checkFullInventory()
- local item = {}
- local lastIndex = turtle.getSelectedSlot()
- -- if the inventory table has never been indexed, then 1st element will be nil
- -- so index it once, then continue checking inventory.
- if inventory[1] == nil then
- indexInventory()
- else
- -- check the most recent index that was set as nil
- turtle.select(getMostRecentNilIndex())
- item = turtle.getItemDetail()
- turtle.select(lastIndex)
- end
- -- if its still nil, aka doesn't return a table, then index inventory again
- -- ensures hopefull no items are ever missed while mining
- if type(item) == "table" then
- indexInventory()
- end
- -- check if inventory table has any nil entries
- for i=1,16 do
- -- if there are any nil slots after indexing, then inventory is not full.
- if inventory[i] == nil then
- setMostRecentNilIndex(i)
- return false
- end
- -- if no nil slots were found, inventory is "full", meaning all slots have an item.
- end -- end for loop
- return true
- end -- end checkFullInventory
- --[[
- moveForward
- moves the turtle forward one block, tracks steps
- ]]
- local function moveFoward()
- turtle.forward()
- setSteps(1)
- end -- end moveForward
- --[[
- moveUpward
- moves the turtle up one block
- ]]
- local function moveUpward()
- turtle.up()
- end -- end moveUpward
- --[[
- moveDownward
- moves the turtle up one block
- ]]
- local function moveDownward()
- turtle.down()
- end -- end moveDownward
- --[[
- digForwardTillEmpty
- digs until there is no block in front of the turtle
- ]]
- local function digForwardTillEmpty()
- local block
- local hasBlock
- while turtle.detect() do
- hasBlock, block = turtle.inspect()
- for key, value in pairs(noBreakList) do
- if block.name == value then
- print("Tried braking a block stored on the no break list! Check the block in front. Press enter to resume or hold ctrl+t to terminate the program. WARNING: resuming could result in a chest being broken.")
- read()
- end
- end
- turtle.dig()
- end
- end -- end digForwardTillEmpty
- --[[
- digUpTillEmpty
- digs until there is no block above the turtle
- ]]
- local function digUpTillEmpty()
- while turtle.detectUp() do
- turtle.digUp()
- end
- end -- end digUpTillEmpty
- --[[
- digDownTillEmpty
- digs until there is no block below the turtle
- ]]
- local function digDownTillEmpty()
- while turtle.detectDown() do
- turtle.digDown()
- end
- end -- end digDownTillEmpty
- --[[
- emptyInventory
- Empties the turtles inventory into an inventory in front of the turtle
- Prompts the user to place an inventory by the turtle if none is found
- returns false if no inventory was found
- ]]
- local function emptyInventory()
- local inv = turtle.inspect()
- local item = {}
- local found = false
- local cobbleKept = false
- if type(inv) == nil then
- print("Please put an inventory/chest behind turtle's start position to empty the inventory. Press Enter to resume.")
- read()
- emptyInventory()
- return
- end
- -- Loop through inventory
- for i=1,16 do
- found = false
- turtle.select(i)
- item = turtle.getItemDetail()
- if type(item) == "table" then
- -- first time we find cobble in inventory, keep it. Always have one stack of building material for
- -- filling gaps in floors and ceilings and keeping lava and water out.
- if item.name == "minecraft:cobblestone" and not cobbleKept then
- cobbleKept = true
- else
- -- Loop through the no drop list
- -- If item is found in no drop list, do not drop into inventory
- for key, value in pairs(noDropList) do
- -- break key/value loop if one is found
- if item.name == value then
- found = true
- break
- end -- if item is found in noDropList
- -- only drop coal in chest if fuel is over 2560 (32 coal)
- if item.name == "minecraft:coal" and
- item.name == value and
- (not turtle.getFuelLevel > 2560) then
- found = true
- break
- end -- if item is coal
- end -- for key value
- end -- if item is cobble and we haven't stored one stack yet
- if not found then
- turtle.drop()
- end -- if no matching "no drop" item was found
- end -- if slot is not empty
- end -- for loop
- turtle.select(1)
- end -- end emptyInventory
- --[[
- fuelToDistanceCheck
- Uses the turns and steps made to calculate how much fuel is required to get back
- returns true if can return home
- ]]
- local function fuelToDistanceCheck(currentLoopSteps, rows)
- local totalDistance
- local success
- local enoughFuel = true
- totalDistance = currentLoopSteps + rows
- if turtle.getFuelLevel() <= totalDistance + reserve then
- success = refuel()
- if success then
- if turtle.getFuelLevel() <= totalDistance + reserve then
- enoughFuel = false
- end -- second check
- else
- enoughFuel = false
- end -- if refuel successful
- end -- if fuelLevel is less than or equal to distance + reserve
- return enoughFuel
- end -- end fuelToDistanceCheck
- --[[
- placeTorch
- places a torch behind the turtle
- ]]
- --[[
- stripMineReturn
- Sends the turtle back to it's starting position
- If there is enough fuel, sends back to where it left off
- returns true if turtle continues where it left off
- ]]
- local function stripMineReturn(goingForward, currentLoopSteps, rows, height, posY)
- local block
- local isBlock
- local startPosY = posY
- -- first get to Y position 0 aka the ground
- -- if we're above the ground
- if posY > 0 then
- for i=1,height do
- -- sanity check, ensure we're not digging below zero
- if posY == 0 then
- break
- end -- end sanity check
- digDownTillEmpty()
- moveDownward()
- posY = posY - 1
- end -- end for i to height
- end -- end if posY > 0
- -- position turtle to cross the rows
- -- (ex. if the turtle was traveling forwards, away from start pos,
- -- this should turn to face the 'left' wall)
- if goingForward then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- -- if we completed any rows to begin with
- if rows > 0 then
- -- cut across all the rows back to row 1
- for i=1,rows do
- digUpTillEmpty()
- digForwardTillEmpty()
- moveFoward()
- end
- end
- -- face towards chest/start position
- turtle.turnLeft()
- -- if going away from home, current loop steps will represent how far we are from the chest
- -- but going towards home, steps represent how close we are. i.e. if steps are 3 and depth is 5, we are 2 away
- --, so only loop twice, or depth - steps
- if goingForward then
- for i=1,currentLoopSteps do
- digUpTillEmpty()
- digForwardTillEmpty()
- moveFoward()
- end
- else
- for i=1, currentLoopSteps do
- digUpTillEmpty()
- digForwardTillEmpty()
- moveFoward()
- end
- end
- -- check if the block in front of turtle is a chest
- isBlock, block = turtle.inspect()
- if type(block) ~= "table" then
- print("No block found at start position. There should be a chest to empty the turtle's inventory. Press enter to empty inventory.")
- else
- if (block.name ~= "minecraft:chest") and
- (block.name ~= "ironchest:iron_chest") then
- print("no chest found at start position/in front of turtle. If there is a chest, press enter to empty inventory.")
- print("block found:", block.name)
- read()
- end
- end
- -- empty the contents of the inventory into a chest
- emptyInventory()
- -- face forward
- turtle.turnRight()
- turtle.turnRight()
- --check fuel
- if fuelToDistanceCheck(currentLoopSteps, rows) then
- -- if fuel level is good, resume mining
- -- return to previous depth of row
- -- should this be 0 or 1?
- for i=1,currentLoopSteps do
- read()
- digUpTillEmpty()
- digForwardTillEmpty()
- moveFoward()
- end
- -- if we dug a full row or more
- if rows > 0 then
- turtle.turnRight()
- -- return to the current row
- for i=1,rows do
- digUpTillEmpty()
- digForwardTillEmpty()
- moveFoward()
- end
- -- face the direction the turtle was originally going
- if goingForward then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- -- return to starting Y position
- if startPosY > 0 then
- for i=1,height do
- -- sanity check, ensure we're not digging abouve height
- if posY == height then
- break
- end -- end sanity check
- digUpTillEmpty()
- moveUpward()
- posY = posY + 1
- end -- end for i to height
- end -- end if startPosY > 0
- return true, posY
- else
- return false, posY
- end -- if enough fuel to keep going
- end -- end stripMineReturn
- --[[
- stripMineUpDown
- Digs and moves the turtle up or down depending on height
- ]]
- local function stripMineUpDown(posY, height)
- -- if less than height, we're not at the cieling, so dig and move up
- if posY < height then
- for i=1,height do
- digUpTillEmpty()
- moveUpward()
- posY = posY + 1
- -- if, for whatever reason, the math is wrong or recursion breaks,
- -- just leave the loop once posY == max height
- if posY == height then
- break
- end
- end -- for i to height
- -- once at the cieling, check if ceiling is empty (i.e. - falling lava or water)
- if not turtle.detectUp() and posY == height then
- local itemSlot
- for key, value in pairs(buildMaterialList) do
- itemSlot = findItem(value)
- if itemSlot ~= nil then
- placeItem(itemSlot,"up")
- -- leave for loop
- break
- end -- end if slot not empty
- end -- end for pairs in buildingMaterialList
- end -- end if turtle doesn't detect solid block and posY is == height
- elseif posY == height then
- for i=1, height do
- digDownTillEmpty()
- moveDownward()
- posY = posY - 1
- -- same redundancy
- if posY == 0 then
- break
- end
- end -- end for i to height
- -- check if floor is empty
- if not turtle.detectDown() and posY < height then
- local itemSlot
- for key, value in pairs(buildMaterialList) do
- itemSlot = findItem(value)
- if itemSlot ~= nil then
- placeItem(itemSlot,"down")
- -- leave for loop
- break
- end -- end if slot not empty
- end -- end for pairs in buildMaterialList
- end -- end if turtle does not detect solid block below and posY is < height
- end
- return posY
- end -- end stripMineUpDown
- --[[
- stripMining
- Makes the turtle dig in a strip mine pattern
- inputs - number, how deep the tunnel goes, boolean if we're facing forward or not,
- number the number of rows dug, rowsSinceTorch, the number of rows since placing torchs
- ]]
- local function stripMining(depth, goingForward, rows, rowsSinceTorch, height, posY)
- local currentLoopSteps = 0
- local isInventoryFull = false
- local continue = false
- local stepsSinceTorch = 5 -- set to 5 so we always place a torch one block away from start and every wall of each new row
- local stepsToTorch = 6 -- number of steps to take PER torch
- local placeSuccess = false
- local torchCount = math.floor(depth / stepsToTorch )
- local torchesPlaced = 0
- -- if you're going backwards, then you are 'depth' away from starting position
- -- so instead, we'll start there and count backwards to 0 to keep track of how
- -- far away we are
- -- ... subtract 1 so we end on 0?
- if not goingForward then
- currentLoopSteps = depth - 1
- end
- -- torch count is how many times we place a torch during a row/loop
- -- if less than 1, set to 1 so we always place at least one.
- if torchCount < 1 then
- torchCount = 1
- end
- -- loop for dig depth (plus one to account for final loop where we ensure column is cleared)
- for i=1,depth+1 do
- -- print stats
- displayLogs(rows,currentLoopSteps,depth,height,posY,"start",goingForward)
- -- if fuel level is less than remaining distance + reserve
- if turtle.getFuelLevel() < (depth - i + reserve) then
- local refuelSuccess
- refuelSuccess = refuel()
- if not refuelSuccess then
- continue, posY = stripMineReturn(goingForward, currentLoopSteps, rows, height, posY)
- if not continue then
- return
- end
- end
- end
- -- check if ceiling is empty (i.e. - falling lava or water) if you're at the cieling (posY equals height)
- if not turtle.detectUp() and posY == height then
- local itemSlot
- for key, value in pairs(buildMaterialList) do
- itemSlot = findItem(value)
- if itemSlot ~= nil then
- placeItem(itemSlot,"up")
- -- leave for loop
- break
- end
- end
- end
- -- check if floor is empty if you're on the floor (posY less than max height)
- if not turtle.detectDown() and posY < height then
- local itemSlot
- for key, value in pairs(buildMaterialList) do
- itemSlot = findItem(value)
- if itemSlot ~= nil then
- placeItem(itemSlot,"down")
- -- leave for loop
- break
- end
- end
- end
- -- handles moving the turtle up or down before moving forward
- posY = stripMineUpDown(posY, height)
- -- if we have reached max depth, don't move forward.
- -- reminder, we do 1 extra loop to ensure we clear the whole column before starting a new row
- if i == depth then
- -- leave the dig up/down/forward loop and move onto starting a new row
- break
- end -- if reached depth
- -- after digging and moving up/down, move forward
- -- if Y position is < height, you're not at the cieling, so dig below
- digForwardTillEmpty()
- moveFoward()
- -- if going backwards, decrement, otherwise increment.
- if not goingForward then
- currentLoopSteps = currentLoopSteps - 1
- else
- currentLoopSteps = currentLoopSteps + 1
- end
- displayLogs(rows,currentLoopSteps,depth,height,posY,"mid",goingForward)
- -- Place a torch every four rows.
- if rowsSinceTorch >= 4 then
- -- Place a torch every 6 blocks or the depth if its smaller
- if stepsSinceTorch >= stepsToTorch or (stepsToTorch > depth and stepsSinceTorch >= depth - 2) then
- -- if we are on top block when placing torch, move to bottom, place torch, then move to top
- if posY == height then
- for i=1,height do
- digDownTillEmpty()
- moveDownward()
- end
- placeSuccess = placeItem(findItem("tconstruct:stone_torch"),"backwards")
- if not placeSuccess then
- placeSuccess = placeItem(findItem("minecraft:torch"),"backwards")
- end
- for i = 1,height do
- digUpTillEmpty()
- moveUpward()
- end
- else -- else just place like normal
- placeSuccess = placeItem(findItem("tconstruct:stone_torch"),"backwards")
- if not placeSuccess then
- placeSuccess = placeItem(findItem("minecraft:torch"),"backwards")
- end
- end
- stepsSinceTorch = 0
- torchesPlaced = torchesPlaced + 1
- -- if we've placed the allotted number of torches for this row,
- -- set rowsSinceTorch to 0 so we can place torches in another 4 rows
- if torchesPlaced >= torchCount then
- torchesPlaced = 0
- rowsSinceTorch = 0
- end
- end -- end if stepsSinceTorch eq 8
- end -- end if rowsSinceTorch eq 4
- isInventoryFull = checkFullInventory()
- if isInventoryFull then
- sortInventory()
- isInventoryFull = checkFullInventory()
- if isInventoryFull then
- continue, posY = stripMineReturn(goingForward, currentLoopSteps, rows, height, posY)
- if not continue then
- return
- end
- end
- end
- stepsSinceTorch = stepsSinceTorch + 1
- -- print stats
- displayLogs(rows,steps,depth,height,posY,"end",goingForward)
- end -- end for loop
- rows = rows + 1
- rowsSinceTorch = rowsSinceTorch + 1
- -- turn to start new shaft
- if goingForward then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- digForwardTillEmpty()
- moveFoward()
- if goingForward then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- if goingForward then
- goingForward = false
- else
- goingForward = true
- end
- stripMining(depth, goingForward, rows, rowsSinceTorch, height, posY)
- end -- end stripMining
- local input
- local heightToUse
- input = ""
- heightToUse = 1
- while input ~= "exit" do
- displayMenu()
- input = read()
- if input == "1" or input == "2" then
- -- set the height of the strip mine
- -- where the heightToUse is the number of blocks we go up
- -- (so going up 2 blocks means a 3 tall mine shaft)
- if input == "2" then
- print("Enter a value for the height of the strip mine")
- input = read()
- -- subtract 1 from the input. This is just for ease of use for the user.
- heightToUse = input - 1
- else
- heightToUse = 1
- end
- term.clear()
- print("Enter a value for the length of the strip mine")
- input = tonumber(read())
- if type(input) ~= "number" then
- print("depth must be a valid number")
- return
- end
- setDistanceToMine(depth)
- -- pass rowsSinceTorch as 4 to place torch on first row
- stripMining(tonumber(input), true, 0,4, heightToUse, 0)
- elseif input == "help" then
- input = ""
- while input ~= "exit" do
- displayHelpMenu()
- input = read()
- displayPatternHelp(input)
- end
- input = ""
- end
- end
- print("Program exit. Thank you for using Mining Toolkit Mk2")
Add Comment
Please, Sign In to add comment