Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to get user input safely
- local function getNumber(prompt)
- print(prompt)
- local n = tonumber(read())
- while not n or n < 1 do
- print("Please enter a positive number.")
- n = tonumber(read())
- end
- return math.floor(n)
- end
- -- Prompt for dimensions and options
- local length = getNumber("Enter length:")
- local width = getNumber("Enter width:")
- local height = getNumber("Enter height:")
- print("Start at TOP or BOTTOM? (type 'top' or 'bottom')")
- local startPos = read():lower()
- while startPos ~= "top" and startPos ~= "bottom" do
- print("Please type 'top' or 'bottom'")
- startPos = read():lower()
- end
- -- Direction tracking (0=+X, 1=+Z, 2=-X, 3=-Z)
- local dir = 0
- local function turnLeft()
- turtle.turnLeft()
- dir = (dir - 1) % 4
- end
- local function turnRight()
- turtle.turnRight()
- dir = (dir + 1) % 4
- end
- local function face(targetDir)
- while dir ~= targetDir do
- turnRight()
- end
- end
- -- Movement functions with digging
- local function tryDig() while turtle.detect() do turtle.dig(); sleep(0.2) end end
- local function tryDigDown() while turtle.detectDown() do turtle.digDown(); sleep(0.2) end end
- local function tryDigUp() while turtle.detectUp() do turtle.digUp(); sleep(0.2) end end
- local function forward()
- tryDig()
- while not turtle.forward() do sleep(0.2) end
- end
- local function up()
- tryDigUp()
- while not turtle.up() do sleep(0.2) end
- end
- local function down()
- tryDigDown()
- while not turtle.down() do sleep(0.2) end
- end
- -- Fuel check
- local estimatedFuel = length * width * height * 1.5 + (length + width + height) * 2
- if turtle.getFuelLevel() < estimatedFuel then
- print("Warning: Low fuel! Required: "..estimatedFuel.." Current: "..turtle.getFuelLevel())
- print("Continue anyway? (y/n)")
- if read():lower() ~= "y" then return end
- end
- -- Dig one horizontal layer
- local function digLayer()
- for w = 1, width do
- -- Dig the row
- for l = 1, length-1 do
- forward()
- end
- -- Turn and move to next row (except on last row)
- if w < width then
- if w % 2 == 1 then
- turnRight()
- forward()
- turnRight()
- else
- turnLeft()
- forward()
- turnLeft()
- end
- end
- end
- -- Return to starting position of layer
- if width % 2 == 0 then
- -- Even width means we ended facing opposite direction
- turnLeft()
- for w = 1, width-1 do forward() end
- turnLeft()
- else
- -- Odd width means we need to turn around
- turnLeft()
- turnLeft()
- for l = 1, length-1 do forward() end
- turnRight()
- turnRight()
- end
- end
- -- Move to starting position
- if startPos == "top" then
- for h = 1, height-1 do
- down()
- end
- end
- -- Main digging loop
- for h = 1, height do
- print("Digging layer "..h.." of "..height)
- digLayer()
- if h < height then
- if startPos == "bottom" then
- up()
- else
- down()
- end
- end
- end
- -- Return to starting height
- if startPos == "bottom" then
- for h = 1, height-1 do down() end
- else
- for h = 1, height-1 do up() end
- end
- print("Quarry complete!")
Advertisement
Add Comment
Please, Sign In to add comment