Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- === UTILITY FUNCTIONS ===
- function selectNextSlot()
- for i = 1, 16 do
- local slot = (turtle.getSelectedSlot() % 16) + 1
- turtle.select(slot)
- if turtle.getItemCount() > 0 then return true end
- end
- return false
- end
- function placeDown()
- while not turtle.placeDown() do
- if turtle.getItemCount() == 0 and not selectNextSlot() then
- error("Out of blocks!")
- end
- sleep(0.1)
- end
- end
- function placeForward()
- while not turtle.place() do
- if turtle.getItemCount() == 0 and not selectNextSlot() then
- error("Out of blocks!")
- end
- sleep(0.1)
- end
- end
- function forwardSafe()
- while not turtle.forward() do
- turtle.dig()
- sleep(0.1)
- end
- end
- function upSafe()
- while not turtle.up() do
- turtle.digUp()
- sleep(0.1)
- end
- end
- function downSafe()
- while not turtle.down() do
- turtle.digDown()
- sleep(0.1)
- end
- end
- -- === BUILD FUNCTIONS ===
- function buildFloor(length, width)
- for z = 1, width do
- for x = 1, length do
- placeDown()
- if x < length then forwardSafe() end
- end
- if z < width then
- if z % 2 == 1 then
- turtle.turnRight()
- forwardSafe()
- turtle.turnRight()
- else
- turtle.turnLeft()
- forwardSafe()
- turtle.turnLeft()
- end
- end
- end
- -- Return to origin
- if width % 2 == 1 then
- turtle.turnRight()
- for i = 1, length - 1 do turtle.back() end
- turtle.turnRight()
- else
- turtle.turnLeft()
- for i = 1, length - 1 do turtle.back() end
- turtle.turnLeft()
- end
- for i = 1, width - 1 do turtle.back() end
- end
- function buildWalls(length, width, height)
- local wallHeight = height - 2
- if wallHeight < 1 then return end
- -- Move up to wall base level (Y=2)
- upSafe()
- -- Build wall perimeter
- for h = 1, wallHeight do
- for side = 1, 4 do
- local distance = (side % 2 == 1) and length or width
- for i = 1, distance do
- if i == 1 or i == distance then
- placeForward()
- elseif side == 1 or side == 3 then
- if h == 1 then placeForward() end
- end
- if i < distance then forwardSafe() end
- end
- turtle.turnRight()
- end
- -- Go up for next wall layer
- if h < wallHeight then upSafe() end
- end
- -- Return down to floor
- for i = 1, wallHeight do downSafe() end
- end
- function buildCeiling(length, width, height)
- for i = 1, height - 1 do upSafe() end
- for z = 1, width do
- for x = 1, length do
- placeDown()
- if x < length then forwardSafe() end
- end
- if z < width then
- if z % 2 == 1 then
- turtle.turnRight()
- forwardSafe()
- turtle.turnRight()
- else
- turtle.turnLeft()
- forwardSafe()
- turtle.turnLeft()
- end
- end
- end
- -- Return to floor level and origin
- if width % 2 == 1 then
- turtle.turnRight()
- for i = 1, length - 1 do turtle.back() end
- turtle.turnRight()
- else
- turtle.turnLeft()
- for i = 1, length - 1 do turtle.back() end
- turtle.turnLeft()
- end
- for i = 1, width - 1 do turtle.back() end
- for i = 1, height - 1 do downSafe() end
- end
- -- === MAIN BUILD FUNCTION ===
- function buildHollowBox(length, width, height)
- if length < 2 or width < 2 or height < 3 then
- error("❌ Dimensions must be at least 2x2x3")
- end
- if turtle.getFuelLevel() == 0 then
- error("❌ Turtle needs fuel! Use turtle.refuel()")
- end
- if turtle.getItemCount() == 0 and not selectNextSlot() then
- error("❌ No blocks available")
- end
- print("▶ Building floor...")
- buildFloor(length, width)
- print("▶ Building walls...")
- buildWalls(length, width, height)
- print("▶ Building ceiling...")
- buildCeiling(length, width, height)
- print("✅ Done.")
- end
- -- === MENU ===
- function promptNumber(prompt)
- while true do
- io.write(prompt)
- local input = read()
- local number = tonumber(input)
- if number and number >= 2 then
- return math.floor(number)
- else
- print("Please enter a number ≥ 2.")
- end
- end
- end
- -- === START ===
- print("=== Build Hollow Structure ===")
- local len = promptNumber("Enter length (≥2): ")
- local wid = promptNumber("Enter width (≥2): ")
- local hei = promptNumber("Enter height (≥3): ")
- print("▶ Starting build: " .. len .. " x " .. wid .. " x " .. hei)
- buildHollowBox(len, wid, hei)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement