added roomCreator
This commit is contained in:
parent
76b3392cad
commit
0a549697f3
66
src/main/programs/turtle-roomCreator.lua
Normal file
66
src/main/programs/turtle-roomCreator.lua
Normal file
@ -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 <depth> <width> <height>")
|
||||
else
|
||||
-- Excavating
|
||||
excavate(depth, width, height)
|
||||
print("Excavation completed!")
|
||||
end
|
Loading…
Reference in New Issue
Block a user