Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define the trash items
- local trashItems = {
- "minecraft:dirt",
- "minecraft:cobblestone",
- "minecraft:diorite",
- "minecraft:cobbled_deepslate",
- "minecraft:andesite",
- "minecraft:gravel",
- "minecraft:sand",
- "minecraft:granite",
- "minecraft:amethyst_block",
- }
- -- Minimum fuel level required to start or continue mining
- local minimumFuel = 100
- -- Function to check if an item is trash
- local function isTrash(item)
- for _, trash in ipairs(trashItems) do
- if item == trash then
- return true
- end
- end
- return false
- end
- -- Function to automatically drop trash items from the inventory (thank you u/fatboychummy for helping with performance)
- local function dropTrash()
- for slot = 1, 16 do
- local itemDetail = turtle.getItemDetail(slot) -- Get details about a slot without selecting it.
- if itemDetail and isTrash(itemDetail.name) then
- turtle.select(slot) -- Only select the slot if it has trash.
- turtle.dropDown()
- end
- end
- end
- -- Function to ensure the block in front is cleared before moving forward
- local function ensureClearAhead()
- while turtle.detect() do
- turtle.dig()
- dropTrash() -- Check for trash after digging a block
- sleep(0.5) -- Small delay to allow any falling blocks to settle
- end
- end
- -- Function to check and refuel if needed
- local function checkAndRefuel()
- if turtle.getFuelLevel() < minimumFuel then
- print("Low fuel! Please add fuel to the turtle's inventory and type 'y' to continue.")
- repeat
- -- Try to refuel from any slot
- for slot = 1, 16 do
- turtle.select(slot)
- turtle.refuel()
- end
- -- Check if enough fuel is added
- local input = read()
- until turtle.getFuelLevel() >= minimumFuel or input == "y"
- end
- end
- -- Function to dig straight down in one column
- local function digColumn(depth)
- local successfulDownMoves = 0
- for d = 1, depth do
- -- Check fuel level before digging down
- checkAndRefuel()
- -- Detect and handle bedrock
- local success, data = turtle.inspectDown()
- if success and data.name == "minecraft:bedrock" then
- print("Bedrock detected, skipping block...")
- dropTrash() -- Check for trash after detecting bedrock
- break -- Stop moving down further in this column
- else
- -- Dig down and move down
- if turtle.detectDown() then
- turtle.digDown()
- dropTrash() -- Check for trash after digging a block
- end
- turtle.down()
- successfulDownMoves = successfulDownMoves + 1
- end
- end
- return successfulDownMoves
- end
- -- Function to return to the top of the column, adjusting for bedrock
- local function returnToTop(successfulDownMoves)
- for i = 1, successfulDownMoves do
- turtle.up()
- end
- end
- -- Function to dig a quarry straight down
- local function quarry(width, length, depth)
- local x, z = 0, 0 -- Track position within the quarry
- for l = 1, length do
- for w = 1, width do
- local successfulDownMoves = digColumn(depth)
- returnToTop(successfulDownMoves)
- -- Move to the next position
- if w < width then
- ensureClearAhead() -- Ensure the next column is clear
- turtle.forward()
- x = x + 1
- end
- end
- -- Move to the next row
- if l < length then
- if l % 2 == 1 then
- turtle.turnRight()
- ensureClearAhead() -- Ensure the next column is clear
- turtle.forward()
- turtle.turnRight()
- z = z + 1
- else
- turtle.turnLeft()
- ensureClearAhead() -- Ensure the next column is clear
- turtle.forward()
- turtle.turnLeft()
- z = z + 1
- end
- end
- end
- end
- -- Function to display fuel level and wait for user input before starting
- local function displayFuelLevel()
- local fuelLevel = turtle.getFuelLevel()
- print("Current fuel level: " .. fuelLevel)
- print("Type 'y' to start the quarry operation.")
- repeat
- local input = read()
- until input == "y"
- end
- -- Get quarry dimensions from the user
- print("Enter quarry width:")
- local width = tonumber(read())
- print("Enter quarry length:")
- local length = tonumber(read())
- print("Enter quarry depth:")
- local depth = tonumber(read())
- -- Display fuel level and wait for user confirmation
- displayFuelLevel()
- -- Run the quarry function with user-provided dimensions
- quarry(width, length, depth)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement