Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Room builder
- -- Can build any box shaped rooms of any size (WxDXH)
- -- Will auto select slot for fuel and build materials
- -- If it runs out of fuel or material mid build it will pause and wait for more
- --
- -- Made by Amumia amumia.pyramid at gmail dot com
- -- Use at your own risk
- function buildPlatform(width, depth)
- realWidth = width + 1
- realDepth = depth + 1
- for i = 1, realWidth do
- for j = 1, realDepth do
- checkCanContinue()
- turtle.placeDown()
- if not (realDepth == j) then
- turtle.forward()
- end
- end
- if not (realWidth == i) then
- -- Change row
- if (i % 2) == 0 then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- turtle.forward()
- if (i % 2) == 0 then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- end
- end
- function build4Walls(width, depth, height)
- for i = 1, height do
- turtle.up();
- for j = 1, 4 do
- if j % 2 == 0 then
- size = depth
- else
- size = width
- end
- checkCanContinue()
- turtle.placeDown()
- for k = 1, size do
- turtle.forward()
- checkCanContinue()
- turtle.placeDown()
- end
- turtle.turnRight()
- end
- end
- end
- function selectMaterialSlot()
- hasMaterials = false
- while not hasMaterials do
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- currentSlot = i
- print("Selecting slot " .. i .. " with " .. turtle.getItemCount(i) .. "units")
- hasMaterials = true
- break
- end
- end
- if not hasMaterials then
- print("Need more materials. Press key to continue")
- io.read()
- end
- end
- end
- function checkSlotHasMaterial(slot)
- if turtle.getItemCount(slot) <= 0 then
- selectMaterialSlot()
- end
- end
- function checkFuelLevel()
- if turtle.getFuelLevel() <= 10 then
- shell.run("refuel all")
- while turtle.getFuelLevel() <= 0 do
- print("Need more fuel. Press key to continue")
- io.read()
- shell.run("refuel all")
- end
- end
- end
- function checkCanContinue()
- checkFuelLevel()
- checkSlotHasMaterial(currentSlot)
- end
- currentSlot = 1
- print("Room builder")
- print("Width:")
- width = io.read()
- width = tonumber(width) + 1
- print("Depth:")
- depth = io.read()
- depth = tonumber(depth) + 1
- print("Height:")
- height = io.read()
- height = tonumber(height)
- -- Prepare for building (fuel and materials)
- checkCanContinue()
- -- Position to start floor
- if turtle.detectDown() then
- turtle.up();
- end
- -- Build floor
- buildPlatform(width, depth)
- -- Position to build walls
- if depth > width then
- turtle.turnLeft()
- for i = 1, width do
- turtle.forward()
- end
- turtle.turnLeft()
- sleep(1)
- turtle.turnLeft()
- elseif width > depth then
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, depth do
- turtle.forward()
- end
- turtle.turnRight()
- else
- if not ((width + 1) % 2 == 0) then
- turtle.turnRight()
- end
- turtle.turnRight()
- end
- -- Build walls
- build4Walls(width, depth, height)
- -- Position to build ceiling
- turtle.up()
- for i = 1, width do
- turtle.forward()
- end
- turtle.turnRight()
- -- Build ceiling
- buildPlatform(width, depth)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement