Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to check if the turtle has enough fuel to move
- local function checkFuel()
- if turtle.getFuelLevel() < 100 then
- for slot = 1, 16 do
- turtle.select(slot)
- if turtle.refuel(1) then
- break
- end
- end
- end
- end
- -- Function to drop all items from inventory into the chest
- local function dropItems()
- turtle.turnLeft()
- turtle.turnLeft()
- for slot = 2, 16 do
- turtle.select(slot)
- turtle.drop()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- -- Setup section
- print("Welcome to the Mining Turtle Script Setup!")
- print("Please answer the following questions:")
- print()
- -- Get starting height
- print("At which height should the turtle start mining? (Enter a number):")
- local startHeight = tonumber(read())
- -- Get tunnel height
- print("What should be the height of the tunnel? (Enter a number):")
- local tunnelHeight = tonumber(read())
- -- Choose mining mode
- print("Mining Mode:")
- print("1. Mine All Blocks")
- print("2. Mine Ores Only")
- print("Enter 1 or 2:")
- local miningMode = tonumber(read())
- -- Get tunnel dimensions
- print("Enter the desired tunnel dimensions:")
- print("Length:")
- local length = tonumber(read())
- print("Width:")
- local width = tonumber(read())
- -- Choose whether to refuel with coal found while mining
- print("Should the turtle refuel with coal it finds while mining?")
- print("1. Yes")
- print("2. No")
- print("Enter 1 or 2:")
- local refuelOption = tonumber(read())
- local shouldRefuel = (refuelOption == 1)
- -- Main mining function
- local function mine()
- local currentHeight = 0
- while currentHeight < tunnelHeight do
- -- Check and refill fuel
- checkFuel()
- -- Dig down to the starting height
- while currentHeight > startHeight do
- turtle.down()
- currentHeight = currentHeight - 1
- end
- -- Mine ores in the current layer
- for h = 1, tunnelHeight do
- for i = 1, width do
- for j = 1, length - 1 do
- while turtle.detect() do
- turtle.dig()
- end
- turtle.forward()
- end
- -- Check and refill fuel after each row
- checkFuel()
- -- Turn around at the end of each row
- if i < width then
- if i % 2 == 0 then
- turtle.turnRight()
- while turtle.detect() do
- turtle.dig()
- end
- turtle.forward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- while turtle.detect() do
- turtle.dig()
- end
- turtle.forward()
- turtle.turnLeft()
- end
- end
- end
- -- Go up to the next layer, if not the last layer
- if h < tunnelHeight then
- for k = 1, h do
- turtle.up()
- currentHeight = currentHeight + 1
- end
- end
- end
- -- Return to the surface
- while currentHeight > 0 do
- turtle.up()
- currentHeight = currentHeight - 1
- end
- -- Deposit items into the chest
- dropItems()
- -- Refuel with coal if required and available
- if shouldRefuel then
- turtle.select(1)
- while turtle.detect() do
- turtle.dig()
- end
- turtle.refuel()
- end
- end
- end
- -- Start the mining process
- mine()
Advertisement
Add Comment
Please, Sign In to add comment