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"
- }
- -- 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
- 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 check and refuel if needed
- local function checkAndRefuel()
- if turtle.getFuelLevel() < minimumFuel then
- -- Try to refuel from any slot
- for slot = 1, 16 do
- turtle.select(slot)
- turtle.refuel()
- end
- -- Check if the fuel level is still below the required threshold
- if turtle.getFuelLevel() < minimumFuel then
- print("Low fuel! Please add fuel to the turtle's inventory and type 'y' to continue.")
- repeat
- local input = read()
- -- Try to refuel again in case fuel was added
- for slot = 1, 16 do
- turtle.select(slot)
- turtle.refuel()
- end
- until turtle.getFuelLevel() >= minimumFuel or input == "y"
- end
- end
- end
- -- Function to automatically drop non-coal items into a chest
- local function depositItems()
- for slot = 1, 16 do
- turtle.select(slot)
- local itemDetail = turtle.getItemDetail()
- if itemDetail and itemDetail.name ~= "minecraft:coal" then
- turtle.dropUp()
- end
- end
- end
- -- Function to handle full inventory by placing a chest above and depositing items
- local function handleFullInventory()
- print("Inventory full! Moving up to place chest and deposit items.")
- turtle.up() -- Move up before placing the chest
- turtle.select(1) -- Assume the chest is in slot 1
- if turtle.getItemDetail().name == "minecraft:chest" then
- turtle.placeUp()
- depositItems()
- else
- print("No chest found in the first slot! Please add a chest and type 'y' to continue.")
- repeat
- local input = read()
- until input == "y"
- turtle.placeUp()
- depositItems()
- end
- turtle.down() -- Move back down to resume mining
- end
- -- Function to check if the inventory is full
- local function isInventoryFull()
- for slot = 1, 16 do
- if turtle.getItemCount(slot) == 0 then
- return false
- end
- end
- return true
- end
- -- Function to mine a single layer horizontally
- local function mineLayer(width, length)
- for l = 1, length do
- for w = 1, width do
- -- Check fuel level before continuing
- checkAndRefuel()
- -- Handle full inventory by placing a chest and depositing items
- if isInventoryFull() then
- handleFullInventory()
- end
- -- Dig forward and move forward, but skip digging the last block of the row
- if w < width then
- if turtle.detect() then
- turtle.dig()
- dropTrash()
- end
- turtle.forward()
- elseif w == width then
- if l < length then
- -- Turn around without digging the last block
- if l % 2 == 1 then
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- end
- end
- end
- end
- end
- end
- -- Function to mine the perimeter horizontally, layer by layer
- local function quarryHorizontal(width, length, depth)
- for d = 1, depth do
- mineLayer(width, length)
- if d < depth then
- -- Move down to the next layer
- turtle.digDown()
- turtle.down()
- end
- end
- end
- -- Function to mine vertically, column by column
- local function digColumn(depth)
- local successfulDownMoves = 0
- for d = 1, depth do
- -- Check fuel level before digging down
- checkAndRefuel()
- -- Handle full inventory by placing a chest and depositing items
- if isInventoryFull() then
- handleFullInventory()
- end
- -- 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 vertically (column by column)
- local function quarryVertical(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())
- -- Ask the user which mining style to use
- print("Select mining style: (v)ertical or (h)orizontal")
- local miningStyle = read()
- -- Display fuel level and wait for user confirmation
- displayFuelLevel()
- -- Run the selected quarry function based on user input
- if miningStyle == "v" then
- quarryVertical(width, length, depth)
- elseif miningStyle == "h" then
- quarryHorizontal(width, length, depth)
- else
- print("Invalid mining style selected. Please restart the program and choose 'v' for vertical or 'h' for horizontal.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement