Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turtle Dirt Filler with Full Debug and Fuel Check
- -- 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)
- -- Check fuel
- local fuel = turtle.getFuelLevel()
- if fuel == "unlimited" then
- print("Fuel: Unlimited (creative mode)")
- elseif fuel == 0 then
- print("ERROR: Turtle has no fuel. Please refuel before running the script.")
- return
- else
- print("Fuel level: "..fuel)
- end
- -- 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 feedback and fuel check
- local function forward()
- local tries = 0
- while not turtle.forward() do
- if turtle.getFuelLevel() == 0 then
- print("ERROR: Out of fuel!")
- return false
- end
- print("Blocked. Digging forward...")
- turtle.dig()
- sleep(0.5)
- tries = tries + 1
- if tries > 10 then
- print("ERROR: Can't move forward after multiple attempts.")
- return false
- end
- end
- return true
- end
- -- Move up with feedback and fuel check
- local function moveUp()
- local tries = 0
- while not turtle.up() do
- if turtle.getFuelLevel() == 0 then
- print("ERROR: Out of fuel!")
- return false
- end
- print("Blocked above. Digging up...")
- turtle.digUp()
- sleep(0.5)
- tries = tries + 1
- if tries > 10 then
- print("ERROR: Can't move up after multiple attempts.")
- return false
- end
- end
- return true
- end
- -- Build one hori
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement