Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Smart Filler: With Fuel Estimation & Direction Choice
- -- Ask for numeric input
- local function askNumber(prompt)
- print(prompt)
- local val = tonumber(read())
- while not val do
- print("Please enter a valid number:")
- val = tonumber(read())
- end
- return math.floor(val)
- end
- -- Ask for direction choice
- local function askDirection()
- print("Build direction? Type 'up' for bottom-to-top or 'down' for top-to-bottom:")
- local dir = read()
- while dir ~= "up" and dir ~= "down" do
- print("Please type 'up' or 'down':")
- dir = read()
- end
- return dir
- end
- -- Prompt user
- local length = askNumber("Enter length:")
- local width = askNumber("Enter width:")
- local height = askNumber("Enter height:")
- local direction = askDirection()
- -- Estimate fuel (very safe estimate: each block = move + turn + dig)
- local estimatedMoves = length * width * height * 2
- print("Estimated fuel needed: "..estimatedMoves)
- -- Try refueling from slot 1
- turtle.select(1)
- if turtle.getFuelLevel() < estimatedMoves then
- print("Refueling from slot 1...")
- if not turtle.refuel(64) then
- print("⚠️ Refuel failed or no valid fuel in slot 1.")
- else
- print("Refueled. Fuel level: "..turtle.getFuelLevel())
- end
- end
- -- Final check
- if turtle.getFuelLevel() < estimatedMoves then
- print("❌ Not enough fuel. Need at least "..estimatedMoves..".")
- return
- end
- print("✅ Fuel OK. Starting build from "..direction.."...")
- -- Block selection
- local function selectBlock()
- for i = 2, 16 do
- turtle.select(i)
- if turtle.getItemCount() > 0 then return true end
- end
- return false
- end
- -- Safe forward
- local function forward()
- while not turtle.forward() do
- turtle.dig()
- sleep(0.2)
- end
- end
- -- Safe up/down
- local function moveUp()
- while not turtle.up() do
- turtle.digUp()
- sleep(0.2)
- end
- end
- local function moveDown()
- while not turtle.down() do
- turtle.digDown()
- sleep(0.2)
- end
- end
- -- Place block below
- local function place()
- if not selectBlock() then
- print("❌ Out of blocks!")
- return false
- end
- if not turtle.detectDown() then
- return turtle.placeDown()
- end
- return true
- end
- -- Main fill logic
- local function buildLayer()
- for w = 1, width do
- for l = 1, length do
- if not place() then return false end
- if l < length then forward() end
- end
- 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 start of row
- 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
- return true
- end
- -- Build loop
- local function build()
- if direction == "up" then
- for h = 1, height do
- print("Building layer "..h.." / "..height)
- if not buildLayer() then return end
- if h < height then moveUp() end
- end
- else
- for i = 1, height - 1 do moveUp() end
- for h = height, 1, -1 do
- print("Building layer "..h.." / "..height)
- if not buildLayer() then return end
- if h > 1 then moveDown() end
- end
- end
- end
- build()
- print("✅ Build complete!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement