Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Mining Turtle Program
- --User configurable
- local heightLimit = -58 -- Minimum height to stop mining (bedrock start assumed at y=-59)
- local yHeight = -55 --preferred baseline height, will be overwritten if gps works
- local enderchestName = "kibe:entangled_chest" -- name of the enderchest like thing you're using
- -------------------------
- local limit = 3
- local width = 3
- local startPos = {x = 1, y = 0, z = 1} -- Starting position
- local currentPos = {x = 0, y = 0, z = 0} -- Track position
- local miningPos = {x = 0, y = 0, z = 0} -- Track position
- local lowerStart = 1
- local returning = false
- local miningReturn = false
- local useBlacklist = false
- local blacklist = {}
- local rememberSelected = nil
- local statistics = {}
- local useEnderchest = false
- local startingSequenceVar = true
- local turtleX, turtleY, turtleZ = gps.locate()
- if turtleY then
- yHeight = turtleY
- end
- ---get API
- if fs.exists("API") == false then
- shell.run("pastebin", "get", "EzkfU5ZM", "API")
- end
- shaka = require("API")
- fs.delete("statistics")
- function lookForEnderchest()
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item and item.name == enderchestName then
- useEnderchest = true
- return true
- end
- end
- useEnderchest = false
- end
- --- main menu
- function configureSettings()
- lookForEnderchest()
- local blacklistEnabled = true
- local quarryLength = limit or 3
- local quarryWidth = width or 1
- local startLower = lowerStart or 1
- local startYHeight = yHeight or 64 -- Default Current Y Lvl
- local selectedOption = 1
- local options = {"Blacklist", "Quarry Length", "Quarry Width", "Lower Start", "Current Y lvl"}
- local function drawMenu()
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.gray)
- term.clearLine()
- shaka.centerText("<=== Quarry Configuration Menu ===>", 1)
- term.setTextColor(colors.white)
- term.setCursorPos(1, 3)
- for i, option in ipairs(options) do
- if i == selectedOption then
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- else
- term.setTextColor(colors.lightGray)
- term.setBackgroundColor(colors.black)
- end
- if option == "Blacklist" then
- -- Set highlight for the entire line
- if i == selectedOption then
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black) -- Highlight background
- else
- term.setTextColor(colors.lightGray)
- term.setBackgroundColor(colors.black)
- end
- -- Print the option label normally
- write(string.format("- %s: ", option))
- -- Now print ON or OFF in the appropriate color
- if blacklistEnabled then
- term.setTextColor(colors.green) -- Green for ON
- write("ON")
- else
- term.setTextColor(colors.red) -- Red for OFF
- write("OFF")
- end
- -- Reset colors after the line
- term.setTextColor(colors.lightGray)
- term.setBackgroundColor(colors.black)
- print("") -- Move to the next line
- elseif option == "Quarry Length" then
- print(string.format("- %s: %d", option, quarryLength))
- elseif option == "Quarry Width" then
- print(string.format("- %s: %d", option, quarryWidth))
- elseif option == "Lower Start" then
- print(string.format("- %s: %d", option, startLower))
- elseif option == "Current Y lvl" then
- print(string.format("- %s: %d", option, startYHeight))
- end
- end
- term.setCursorPos(1, 8)
- term.setTextColor(colors.lightGray)
- write("- Use Enderchest: ")
- if useEnderchest then
- term.setTextColor(colors.green)
- enderText = "YES"
- else
- term.setTextColor(colors.red)
- enderText = "NO"
- end
- write(enderText)
- term.setTextColor(colors.gray)
- write(" (checks inv)")
- term.setCursorPos(1, 10)
- shaka.changeColors(colors.black, colors.yellow)
- print("- Use w, a, s, d, arrows or mousewheel.")
- term.setTextColor(colors.green)
- term.setBackgroundColor(colors.black)
- print("- Press Enter to start mining.")
- end
- -- Main loop for handling user interaction
- local running = true
- while running do
- drawMenu()
- local event, param1, param2, param3 = os.pullEvent()
- if event == "key" then
- if rememberSelected ~= nil then
- selectedOption = rememberSelected
- rememberSelected = nil
- end
- if param1 == keys.up or param1 == keys.w then
- selectedOption = math.max(1, selectedOption - 1)
- elseif param1 == keys.down or param1 == keys.s then
- selectedOption = math.min(#options, selectedOption + 1)
- elseif (param1 == keys.left or param1 == keys.a) or (param1 == keys.right or param1 == keys.d) then
- if selectedOption == 1 then
- blacklistEnabled = not blacklistEnabled
- elseif selectedOption == 2 then
- if param1 == keys.left or param1 == keys.a then
- quarryLength = math.max(3, quarryLength - 1)
- else
- quarryLength = quarryLength + 1
- end
- elseif selectedOption == 3 then
- if param1 == keys.left or param1 == keys.a then
- quarryWidth = math.max(1, quarryWidth - 1)
- else
- quarryWidth = quarryWidth + 1
- end
- elseif selectedOption == 4 then
- if param1 == keys.left or param1 == keys.a then
- startLower = math.max(1, startLower - 1)
- else
- startLower = startLower + 1
- end
- elseif selectedOption == 5 then
- if param1 == keys.left or param1 == keys.a then
- startYHeight = startYHeight - 1
- else
- startYHeight = startYHeight + 1
- end
- end
- elseif param1 == keys.enter then
- running = false
- elseif param1 == keys.backspace then
- os.reboot()
- end
- elseif event == "mouse_scroll" then
- if selectedOption ~= nil then
- rememberSelected = selectedOption
- end
- selectedOption = nil
- if param1 == -1 then -- Scroll up
- if param3 == 3 then
- blacklistEnabled = not blacklistEnabled
- elseif param3 == 4 then
- quarryLength = quarryLength + 3
- elseif param3 == 5 then
- quarryWidth = quarryWidth + 3
- elseif param3 == 6 then
- startLower = startLower + 3
- elseif param3 == 7 then
- startYHeight = startYHeight + 3
- end
- elseif param1 == 1 then -- Scroll down
- if param3 == 3 then
- blacklistEnabled = not blacklistEnabled
- elseif param3 == 4 then
- quarryLength = math.max(3, quarryLength - 3)
- elseif param3 == 5 then
- quarryWidth = math.max(1, quarryWidth - 3)
- elseif param3 == 6 then
- startLower = math.max(1, startLower - 3)
- elseif param3 == 7 then
- startYHeight = startYHeight - 3
- end
- end
- elseif event == "turtle_inventory" then
- lookForEnderchest()
- end
- end
- -- Apply the configuration to global variables
- limit = quarryLength
- width = quarryWidth
- lowerStart = startLower
- useBlacklist = blacklistEnabled
- startPos.y = startYHeight
- end
- function isInventoryInFront()
- -- Attempt to wrap the block in front as a peripheral
- local peripheralName = peripheral.getType("front")
- if peripheralName then
- -- Check if the peripheral type includes "inventory" capabilities
- local methods = peripheral.getMethods("front")
- if methods then
- for _, method in ipairs(methods) do
- if method == "list" then
- -- If the "list" method exists, it's likely an inventory
- return true
- end
- end
- end
- end
- return false -- No inventory detected
- end
- function startingSequence()
- shaka.changeColors(colors.black, colors.white)
- shaka.clearScreen()
- if useEnderchest == false then
- term.setTextColor(colors.orange)
- print("- Checking if there is an inventory..")
- turtle.turnLeft()
- turtle.turnLeft()
- if isInventoryInFront() then
- term.setTextColor(colors.green)
- print("\n- Good job, inventory detected.")
- else
- repeat
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1, 3)
- term.clearLine()
- shaka.changeColors(colors.red, colors.black)
- print("!Please place inventory in front of me!")
- sleep(1)
- until isInventoryInFront()
- shaka.changeColors(colors.black, colors.green)
- print("Thanks!")
- end
- turtle.turnRight()
- turtle.turnRight()
- else
- print("- Enderchest detected")
- end
- shaka.changeColors(colors.black, colors.yellow)
- print("\n- Position set, safety checks done.\n")
- term.setTextColor(colors.green)
- textutils.slowPrint("- Starting..", 10)
- startingSequenceVar = false
- end
- -- Helper functions
- function isBlacklisted(blockName)
- if useBlacklist == false then
- return false
- end
- blacklist = shaka.readFile("blacklist.txt")
- if blacklist == false then
- blacklist = {}
- end
- for _, name in ipairs(blacklist) do
- if name == blockName then
- return true
- end
- end
- return false
- end
- function addToBlacklist()
- useBlacklist = true
- -- Load or initialize the blacklist
- local blacklist = shaka.readFile("blacklist.txt")
- if not blacklist then
- blacklist = {}
- end
- -- Function to display the main blacklist menu
- local function drawMenu()
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.gray)
- term.clearLine()
- shaka.centerText("<=== Blacklist Configuration ===>", 1)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.gray)
- term.setCursorPos(1, 11)
- print("[B] to view blacklist\nBackspace to return")
- term.setTextColor(colors.white)
- term.setCursorPos(1, 3)
- term.setTextColor(colors.green)
- print("Slot <15: Add items")
- term.setTextColor(colors.red)
- print("Slot 16: Remove items")
- term.setTextColor(colors.lightGray)
- term.setCursorPos(1, 6)
- print("Detected changes:")
- end
- -- Function to display the blacklist with scrolling
- local function viewBlacklist()
- local currentPage = 1
- local itemsPerPage = 9
- local function drawBlacklist()
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.gray)
- term.clearLine()
- shaka.centerText("<=== Blacklist Items ===>", 1)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1, 3)
- term.setTextColor(colors.white)
- -- Determine the range of items to display
- local startIndex = (currentPage - 1) * itemsPerPage + 1
- local endIndex = math.min(#blacklist, currentPage * itemsPerPage)
- -- Display items
- for i = startIndex, endIndex do
- print(string.format("%d. %s", i, shaka.prettyName(blacklist[i])))
- end
- -- Display navigation info
- term.setCursorPos(1, 11)
- term.setTextColor(colors.gray)
- print("Use arrows or W/S to scroll.\nBackspace to return")
- end
- -- Scrollable menu loop
- local running = true
- while running do
- drawBlacklist()
- local event, param1 = os.pullEvent("key")
- if param1 == keys.up or param1 == keys.w then
- currentPage = math.max(1, currentPage - 1)
- elseif param1 == keys.down or param1 == keys.s then
- local maxPages = math.ceil(#blacklist / itemsPerPage)
- currentPage = math.min(maxPages, currentPage + 1)
- elseif param1 == keys.backspace or param1 == keys.escape then
- running = false -- Return to the main menu
- end
- end
- end
- -- Function to add an item to the blacklist and save immediately
- local function addItemToBlacklist(itemName)
- if not isBlacklisted(itemName) then
- table.insert(blacklist, itemName)
- shaka.writeFile("blacklist.txt", blacklist) -- Save updated blacklist immediately
- term.setTextColor(colors.green)
- write("+ ".. shaka.prettyName(itemName))
- textutils.slowPrint(" added", 10)
- else
- term.setTextColor(colors.yellow)
- write("> ".. shaka.prettyName(itemName))
- textutils.slowPrint(" already known", 10)
- end
- end
- -- Function to remove an item from the blacklist and save immediately
- local function removeItemFromBlacklist(itemName)
- for i = #blacklist, 1, -1 do
- if blacklist[i] == itemName then
- table.remove(blacklist, i)
- shaka.writeFile("blacklist.txt", blacklist) -- Save updated blacklist immediately
- term.setTextColor(colors.red)
- write("- ".. shaka.prettyName(itemName))
- textutils.slowPrint(" removed", 10)
- return true
- end
- end
- return false
- end
- -- Main menu loop
- local running = true
- while running do
- drawMenu()
- local event, param1 = os.pullEvent() -- Wait for an event
- if event == "turtle_inventory" then
- -- Inventory change detected, process slots
- term.setCursorPos(1, 8) -- Start displaying items below the menu
- -- Handle slots 1-15 for adding to the blacklist
- for i = 1, 15 do
- local item = turtle.getItemDetail(i)
- if item then
- addItemToBlacklist(item.name)
- sleep(0.5)
- end
- end
- -- Handle slot 16 for removing from the blacklist
- local slot16Item = turtle.getItemDetail(16)
- if slot16Item then
- removeItemFromBlacklist(slot16Item.name)
- sleep(0.5)
- end
- elseif event == "key" then
- if param1 == keys.b then
- viewBlacklist() -- Open the blacklist viewer
- elseif param1 == keys.backspace then
- running = false -- Exit the blacklist menu
- end
- end
- end
- useBlacklist = false
- end
- -- Function to start the main menu
- function startMenu()
- while true do
- shaka.clearScreen()
- term.setTextColor(colors.yellow)
- shaka.centerText("=== Quarry Mining Menu ===", 1)
- term.setTextColor(colors.white)
- term.setCursorPos(1, 3)
- print("1. Configure blacklist")
- print("2. Start mining")
- -- Wait for user input
- local success, key = os.pullEvent("key")
- if key == keys.one then
- -- Blacklist configuration
- addToBlacklist()
- elseif key == keys.two then
- -- Quarry configuration
- configureSettings()
- break
- elseif key == keys.enter then
- -- Start mining
- -- return
- end
- end
- end
- function savePosition()
- local file = fs.open("position.txt", "w")
- file.writeLine(textutils.serialize(currentPos))
- file.close()
- end
- function printPosition()
- -- print("x: ", currentPos.x,"y: ", currentPos.y,"z :", currentPos.z)-- "baseLine Top: ", startPos.y - lowerStart)
- -- print("minX: ", miningPos.x, "minY: ", miningPos.y)
- end
- function loadPosition()
- shaka.clearScreen()
- if fs.exists("position.txt") then
- local file = fs.open("position.txt", "r")
- local data = textutils.unserialize(file.readLine())
- file.close()
- if data and type(data) == "table" then
- currentPos = data
- else
- print("Starting position set.")
- currentPos = {x = startPos.x, y = startPos.y, z = startPos.z}
- end
- else
- print("Position file not found, using startPos.")
- currentPos = {x = startPos.x, y = startPos.y, z = startPos.z}
- end
- end
- function calculateFuelForReturn(currentPos, startingPos)
- -- Calculate the distance between the current position and starting position
- local dx = math.abs(currentPos.x - startingPos.x)
- local dy = math.abs(currentPos.y - startingPos.y)
- local dz = math.abs(currentPos.z - startingPos.z)
- -- The total distance is the sum of the absolute differences in all coordinates
- local totalDistance = dx + dy + dz
- -- Return the calculated fuel cost
- return totalDistance
- end
- function checkFuelForReturn(currentPos, startingPos)
- -- Calculate the fuel needed to return home
- local fuelNeeded = calculateFuelForReturn(currentPos, startingPos)
- -- Get the current fuel level of the turtle
- local currentFuel = turtle.getFuelLevel()
- -- Check if the turtle has enough fuel
- if currentFuel < fuelNeeded + 50 then
- -- Not enough fuel
- term.setBackgroundColor(colors.red)
- shaka.clearScreen()
- print("Warning: Low on fuel, returning home!")
- print("Fuel required: " .. fuelNeeded)
- print("Current fuel: " .. currentFuel)
- returnToStart()
- print("Hit enter to restart")
- while true do
- success, key = os.pullEvent("key")
- if key == keys.enter then
- os.reboot()
- end
- end
- end
- end
- -------movement functions
- function moveDown()
- checkFuelForReturn(currentPos, startPos)
- if turtle.down() then
- currentPos.y = currentPos.y - 1
- savePosition()
- printPosition()
- recordStatistics("moveDown")
- return true
- else
- recordStatistics("timesScanned")
- recordStatistics("timesMined")
- local success, data = turtle.inspectDown()
- recordStatistics(data.name)
- turtle.digDown()
- end
- return false
- end
- function moveUp()
- checkFuelForReturn(currentPos, startPos)
- if turtle.up() then
- currentPos.y = currentPos.y + 1
- savePosition()
- printPosition()
- recordStatistics("moveUp")
- return true
- else
- recordStatistics("timesScanned")
- recordStatistics("timesMined")
- local success, data = turtle.inspectUp()
- recordStatistics(data.name)
- turtle.digUp()
- end
- return false
- end
- function moveForward()
- checkFuelForReturn(currentPos, startPos)
- if turtle.forward() then
- if returning == false then
- currentPos.x = currentPos.x + 1
- else
- currentPos.x = currentPos.x - 1
- end
- savePosition()
- printPosition()
- recordStatistics("moveForward")
- return true
- else
- recordStatistics("timesScanned")
- recordStatistics("timesMined")
- local success, data = turtle.inspect()
- recordStatistics(data.name)
- turtle.dig()
- end
- return false
- end
- function moveZ()
- if turtle.forward() then
- currentPos.z = currentPos.z + 1
- savePosition()
- printPosition()
- recordStatistics("moveSide")
- return true
- else
- recordStatistics("timesMined")
- recordStatistics("timesScanned")
- local success, data = turtle.inspect()
- recordStatistics(data.name)
- turtle.dig()
- end
- return false
- end
- ----------------------
- function recordStatistics(name)
- -- Initialize the key for the given name if it doesn't exist
- if statistics[name] == nil then
- statistics[name] = 0
- end
- -- Increment the counter for the specific item
- statistics[name] = statistics[name] + 1
- -- Save the updated statistics to a file
- shaka.writeFile("statistics", statistics)
- end
- function mineDirection()
- for i = 1, 4 do
- local success, data = turtle.inspect()
- recordStatistics("timesScanned")
- if not success then
- recordStatistics("scannedAir")
- end
- if success and not isBlacklisted(data.name) then
- -- Determine whether to mine based on conditions
- local shouldMine = true
- if currentPos.x == startPos.x and currentPos.z == startPos.z and i == 3 then
- shouldMine = false
- end
- if currentPos.z == startPos.z then
- if not returning and i == 4 then
- shouldMine = false
- elseif returning and i == 2 then
- shouldMine = false
- end
- end
- if currentPos.z >= width then
- if not returning and i == 2 then
- shouldMine = false
- elseif returning and i == 4 then
- shouldMine = false
- end
- end
- if (currentPos.x == limit and not returning) or (currentPos.x == startPos.x and returning) then
- if i == 1 then
- shouldMine = false
- end
- end
- if shouldMine then
- recordStatistics(data.name)
- repeat
- sleep(0.1)
- until not turtle.dig()
- recordStatistics("timesMined")
- end
- end
- turtle.turnRight()
- end
- end
- function changeLane()
- if returning == false then
- returning = true
- turtle.turnRight()
- for i =1, 2 do
- if currentPos.z == width then
- break
- end
- repeat until moveZ()
- end
- turtle.turnRight()
- else
- returning = false
- turtle.turnLeft()
- for i =1, 2 do
- if currentPos.z == width then
- break
- end
- repeat until moveZ()
- end
- turtle.turnLeft()
- end
- repeat until moveForward()
- mineDirection()
- end
- function isInventoryFull()
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then
- return false
- end
- end
- return true
- end
- function unloadInventory()
- -- Check if there's an inventory in front
- if not isInventoryInFront() then
- printError("No inventory detected in front")
- repeat sleep(1) until isInventoryInFront()
- end
- -- Main unloading logic
- shaka.changeColors(colors.black, colors.white)
- shaka.clearScreen()
- print("Starting to unload turtle inventory...\n")
- for slot = 1, 16 do
- if turtle.getItemCount(slot) > 0 then
- -- Select the slot with items
- turtle.select(slot)
- -- Attempt to drop items into the inventory
- while not turtle.drop() do
- -- If the drop fails, inform the user and retry
- shaka.clearScreen()
- printError("Failed to drop items from slot [" .. slot.."]")
- print("Inventory may be full, please clear space!")
- sleep(1)
- end
- print("Emptied slot " .. slot)
- end
- end
- term.setTextColor(colors.green)
- print("All items successfully unloaded.")
- turtle.select(1) -- Reset turtle's selected slot
- end
- function enderUnload()
- -- Locate the Ender Chest in the turtle's inventory
- local enderChestSlot = nil
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item and item.name == enderchestName then
- enderChestSlot = slot
- break
- end
- end
- -- Place the Ender Chest in front of the turtle
- turtle.select(enderChestSlot)
- if not turtle.placeUp() then
- printError("Failed to place the Ender Chest. Make sure the front is clear.")
- repeat turtle.digUp() until turtle.placeUp()
- end
- -- Unload all items into the Ender Chest
- for slot = 1, 16 do
- if slot ~= enderChestSlot and turtle.getItemCount(slot) > 0 then
- turtle.select(slot)
- while not turtle.dropUp() do
- printError("Ender Chest is full, clear space.")
- sleep(1)
- end
- end
- end
- -- Break the Ender Chest to retrieve it
- turtle.select(enderChestSlot)
- if not turtle.digUp() then
- printError("Failed to retrieve the Ender Chest!")
- return false
- end
- -- Reset selection to slot 1
- turtle.select(1)
- print("Successfully unloaded inventory into Ender Chest.")
- return true
- end
- function returnToStart()
- print("Returning to start")
- miningPos.x = currentPos.x
- miningPos.y = currentPos.y
- miningPos.z = currentPos.z
- miningReturn = returning
- -- Turn around to mine blocks on the way back
- if returning == false then
- turtle.turnLeft()
- turtle.turnLeft()
- returning = true
- end
- -- Move back to the starting position
- turtle.turnRight()
- while currentPos.z > startPos.z do
- repeat
- turtle.dig()
- until turtle.forward()
- currentPos.z = currentPos.z - 1
- end
- turtle.turnLeft()
- while currentPos.x > startPos.x do
- moveForward()
- end
- while currentPos.y < startPos.y do
- moveUp()
- end
- if useEnderchest == false then
- unloadInventory()
- else
- enderUnload()
- end
- -- Turn back to the original orientation
- turtle.turnLeft()
- turtle.turnLeft()
- returning = false
- end
- function resumeMining()
- print("Resuming mining")
- -- move down to saved position
- while currentPos.y > miningPos.y do
- repeat until moveDown()
- end
- -- Move forward to the saved position
- while currentPos.x < miningPos.x do
- repeat until moveForward()
- end
- --move on z axis to saved position
- if currentPos.z ~= miningPos.z then
- turtle.turnRight()
- while currentPos.z < miningPos.z do
- repeat until moveZ()
- end
- if miningReturn then
- turtle.turnRight()
- returning = true
- else
- turtle.turnLeft()
- returning = false
- end
- end
- end
- function invCheck()
- if isInventoryFull() then
- if useEnderchest == false then
- returnToStart()
- resumeMining()
- else
- enderUnload()
- end
- end
- end
- function getLimit()
- -- Move forward by 3 blocks
- for _ = 1, 3 do
- repeat until moveForward()
- if returning == false then
- if currentPos.x == limit then
- mineDirection()
- return true
- end
- else
- if currentPos.x == startPos.x then
- mineDirection()
- return true
- end
- end
- end
- mineDirection()
- return false
- end
- function showEnd()
- shaka.clearScreen()
- term.setTextColor(colors.green)
- statistics.timesMined = statistics.timesMined or 0
- shaka.centerText("Mined "..statistics.timesMined.."/"..statistics.timesScanned.." scanned", 1)
- term.setCursorPos(1, 2)
- term.setTextColor(colors.lightGray)
- -- Convert the table to a list of key-value pairs
- local sortedList = {}
- for key, value in pairs(statistics) do
- if shaka.stringFind(key, ":") then
- table.insert(sortedList, {key = key, value = value})
- end
- end
- -- Sort the list by the value (count) in descending order
- table.sort(sortedList, function(a, b)
- return a.value > b.value
- end)
- -- Display the sorted items
- for _, entry in ipairs(sortedList) do
- print(shaka.prettyName(entry.key) .. " [" .. entry.value.."]")
- end
- end
- function oneRow()
- --function to stop
- local function killSwitch()
- if getLimit() then
- if currentPos.y == startPos.y - lowerStart then
- while currentPos.y > heightLimit do
- invCheck()
- if moveDown() then
- mineDirection()
- end
- end
- else
- while currentPos.y < startPos.y - lowerStart do
- invCheck()
- if moveUp() then
- mineDirection()
- end
- end
- end
- shaka.changeColors(colors.black, colors.gray)
- print("- Quarry boundary reached")
- return true
- end
- return false
- end
- ------main function
- while true do
- -- Mine downward until bedrock or height limit
- if currentPos.y >= startPos.y - lowerStart then
- while currentPos.y > heightLimit do
- invCheck()
- if moveDown() then
- mineDirection()
- end
- end
- else
- while currentPos.y < startPos.y - lowerStart do
- invCheck()
- if moveUp() then
- mineDirection()
- end
- end
- end
- if killSwitch() then break end
- end
- end
- -- Main mining loop
- local function mainLoopVertical()
- startMenu()
- loadPosition()
- startingSequence()
- if lowerStart ~= 0 then
- for i = 1, lowerStart do
- repeat until moveDown()
- end
- mineDirection()
- end
- while true do
- oneRow()
- -- print("Status: ", currentPos.z, width)
- if currentPos.z >= width then
- break
- end
- changeLane()
- end
- returnToStart()
- showEnd()
- end
- mainLoopVertical()
Add Comment
Please, Sign In to add comment