Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turtle Dirt Filler with Debug Feedback
- -- Function to prompt for numeric input
- local function askForNumber(prompt)
- print(prompt)
- local input = read()
- local number = tonumber(input)
- while not number do
- print("Please enter a valid number.")
- input = read()
- number = tonumber(input)
- end
- return number
- end
- -- Ask for area dimensions
- local length = askForNumber("Enter length:")
- local width = askForNumber("Enter width:")
- local height = askForNumber("Enter height:")
- print("Preparing to build area of size "..length.." x "..width.." x "..height)
- -- Function to select dirt in inventory
- local function selectDirt()
- for i = 1, 16 do
- turtle.select(i)
- local item = turtle.getItemDetail()
- if item and item.name:find("dirt") then
- print("Selected dirt in slot "..i)
- return true
- end
- end
- print("No dirt found in inventory!")
- return false
- end
- -- Place dirt below turtle
- local function placeDown()
- if turtle.detectDown() then
- print("Block already exists below.")
- return true
- end
- if not turtle.placeDown() then
- print("Trying to select dirt to place...")
- if not selectDirt() then
- print("ERROR: Out of dirt. Cannot continue.")
- return false
- end
- if not turtle.placeDown() then
- print("ERROR: Failed to place dirt even after selecting.")
- return false
- end
- end
- print("Placed dirt below.")
- return true
- end
- -- Move forward with digging if needed
- local function forward()
- while not turtle.forward() do
- print("Blocked. Digging forward...")
- turtle.dig()
- sleep(0.5)
- end
- end
- -- Move up with digging if needed
- local function moveUp()
- while not turtle.up() do
- print("Blocked above. Digging up...")
- turtle.digUp()
- sleep(0.5)
- end
- end
- -- Build one horizontal layer
- local function buildLayer(layerNum)
- print("Starting layer "..layerNum.."...")
- for w = 1, width do
- for l = 1, length do
- if not placeDown() then
- print("Stopping layer due to placement failure.")
- return false
- end
- if l < length then
- forward()
- end
- end
- -- Move to next row
- if w < width then
- if w % 2 == 1 then
- turtle.turnRight()
- forward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- forward()
- turtle.turnLeft()
- end
- end
- end
- -- Return to starting row direction
- if width % 2 == 1 then
- turtle.turnRight()
- for i = 1, length - 1 do forward() end
- turtle.turnRight()
- else
- turtle.turnLeft()
- for i = 1, length - 1 do forward() end
- turtle.turnLeft()
- end
- print("Finished layer "..layerNum..".")
- return true
- end
- -- Build all layers
- for h = 1, height do
- if not buildLayer(h) then
- print("Build aborted on layer "..h)
- return
- end
- if h < height then
- print("Moving up to layer "..(h + 1))
- moveUp()
- end
- end
- print("✅ Build complete! All "..height.." layer(s) placed.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement