diff --git a/src/main/programs/turtle-roomCreator.lua b/src/main/programs/turtle-roomCreator.lua new file mode 100644 index 0000000..8cb3fc8 --- /dev/null +++ b/src/main/programs/turtle-roomCreator.lua @@ -0,0 +1,66 @@ +-- Function to dig a cuboid with given dimensions +function excavate(depth, width, height) + -- Digging loop + for h = 1, height do + -- Digging a layer + for w = 1, width do + -- Digging a row + for d = 1, depth do + turtle.dig() -- Digging forward + turtle.forward() -- Moving forward + end + + -- If not the last row, return to the starting point + if w < width then + -- Turning around + if w % 2 == 0 then + turtle.turnRight() + else + turtle.turnLeft() + end + -- Returning to the starting point + for i = 1, depth do + turtle.forward() + end + -- Turning to the correct direction + if w % 2 == 0 then + turtle.turnLeft() + else + turtle.turnRight() + end + end + end + + -- Returning to the starting point of the layer + if h < height then + -- Turning around + turtle.turnLeft() + turtle.turnLeft() + -- Going up one level + for i = 1, width do + turtle.forward() + end + -- Turning to the correct direction + if h % 2 == 0 then + turtle.turnRight() + else + turtle.turnLeft() + end + end + end +end + +-- Retrieving parameters from input +local args = {...} +local depth = tonumber(args[1]) +local width = tonumber(args[2]) +local height = tonumber(args[3]) + +-- Validating input +if depth == nil or width == nil or height == nil then + print("Usage: excavate ") +else + -- Excavating + excavate(depth, width, height) + print("Excavation completed!") +end