Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turtle Program to Dig Out Rooms with Configurable Size and Visual Guide
- -- Starts at the bottom-left corner of the room and ensures correct height handling, including sand/gravel.
- -- Function to display a visual representation of where to place the turtle
- local function showPlacementGuide()
- print("Place the turtle at the bottom-left corner of the room facing forward.")
- print("It should be one block below the desired floor level.")
- end
- -- Function to prompt user for room dimensions
- local function getRoomDimensions()
- print("Enter the dimensions for the room:")
- print("Length (blocks): ")
- local length = tonumber(io.read())
- print("Width (blocks): ")
- local width = tonumber(io.read())
- print("Height (blocks): ")
- local height = tonumber(io.read())
- return length, width, height
- end
- -- Function to calculate and check total fuel needed
- local function checkFuelNeeded(length, width, height)
- local totalBlocks = length * width * height
- local fuelNeeded = totalBlocks * 2 -- Estimate: 2 fuel per block (including turns and adjustments)
- print("Total blocks to mine: " .. totalBlocks)
- print("Estimated fuel needed: " .. fuelNeeded)
- if turtle.getFuelLevel() < fuelNeeded then
- print("Not enough fuel! Please refuel the turtle.")
- while turtle.getFuelLevel() < fuelNeeded do
- print("Place fuel in the turtle's inventory and press Enter.")
- os.pullEvent("turtle_inventory")
- turtle.refuel()
- end
- print("Turtle refueled! Fuel level: " .. turtle.getFuelLevel())
- else
- print("Sufficient fuel available. Fuel level: " .. turtle.getFuelLevel())
- end
- end
- -- Function to dig forward, handling falling blocks
- local function digForward()
- while turtle.detect() do
- turtle.dig()
- sleep(0.5) -- Wait for falling blocks to settle
- end
- turtle.forward()
- end
- -- Function to dig up, handling falling blocks
- local function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- sleep(0.5) -- Wait for falling blocks to settle
- end
- end
- -- Function to dig down, handling falling blocks
- local function digDown()
- while turtle.detectDown() do
- turtle.digDown()
- sleep(0.5) -- Wait for falling blocks to settle
- end
- end
- -- Function to dig forward, up, and down in one move
- local function digAll()
- digForward()
- digUp()
- digDown()
- end
- -- Main function to dig out the room
- local function digRoom(length, width, height)
- -- Start by moving up one block to account for the initial position
- turtle.up()
- for layer = 1, height do
- for w = 1, width do
- for l = 1, length do
- if l == 1 and w == 1 and layer > 1 then
- digUp()
- digDown()
- end
- digAll()
- end
- -- Turn at the end of the row
- if w < width then
- if w % 2 == 1 then
- turtle.turnRight()
- digForward()
- digUp()
- digDown()
- turtle.turnRight()
- else
- turtle.turnLeft()
- digForward()
- digUp()
- digDown()
- turtle.turnLeft()
- end
- end
- end
- -- Move up to the next layer if needed
- if layer < height then
- digUp()
- turtle.up()
- if width % 2 == 1 then
- turtle.turnRight()
- turtle.turnRight()
- end
- end
- end
- -- Ensure the turtle stops after completing the specified height
- if height > 1 then
- while turtle.down() do end
- end
- -- Return to the starting position
- turtle.turnRight()
- for i = 1, length - 1 do turtle.back() end
- turtle.turnRight()
- for i = 1, width - 1 do turtle.back() end
- turtle.turnRight()
- end
- -- Show placement guide
- showPlacementGuide()
- -- Get room dimensions from user
- local roomLength, roomWidth, roomHeight = getRoomDimensions()
- -- Check if sufficient fuel is available
- checkFuelNeeded(roomLength, roomWidth, roomHeight)
- -- Run the program
- digRoom(roomLength, roomWidth, roomHeight)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement