Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Minecraft Turtle Program to Dig Out a Room
- -- Function to display the menu and get user input
- function displayMenu()
- print("Enter the dimensions of the room to dig out:")
- io.write("Width: ")
- local width = tonumber(io.read())
- io.write("Length: ")
- local length = tonumber(io.read())
- io.write("Height: ")
- local height = tonumber(io.read())
- return width, length, height
- end
- -- Function to dig a line of blocks
- function digLine(length)
- for i = 1, length do
- if i < length then
- turtle.dig()
- turtle.forward()
- end
- end
- end
- -- Function to dig a layer of the room
- function digLayer(width, length)
- for w = 1, width do
- digLine(length)
- if w < width then
- if w % 2 == 1 then
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- end
- end
- end
- end
- -- Function to dig the room
- function digRoom(width, length, height)
- for h = 1, height do
- digLayer(width, length)
- if h < height then
- turtle.digDown()
- turtle.down()
- if width % 2 == 0 then
- -- If width is even, turtle ends up facing the right direction
- -- but needs to move to the next starting position
- turtle.turnRight()
- turtle.turnRight()
- for i = 1, length - 1 do
- turtle.forward()
- end
- end
- -- Turn around to face the right direction for the next layer
- turtle.turnRight()
- turtle.turnRight()
- end
- end
- end
- -- Main program
- local width, length, height = displayMenu()
- print("Starting to dig a room of size " .. width .. "x" .. length .. "x" .. height)
- digRoom(width, length, height)
- print("Room dug out successfully!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement