Posted 30 January 2013 - 08:47 PM
Place turtle in centre of room. It uses some routines from the tunnel and excavate programs.
If you want a room that is more than 3 blocks high, for instance if you want to pave the floor or ceiling, then you will need to move the turtle back to the centre and embed it in the floor or ceiling and set it off again.
http://pastebin.com/UrgqLk8U
pastebin get UrgqLk8U
If you want a room that is more than 3 blocks high, for instance if you want to pave the floor or ceiling, then you will need to move the turtle back to the centre and embed it in the floor or ceiling and set it off again.
http://pastebin.com/UrgqLk8U
pastebin get UrgqLk8U
Spoiler
local tArgs = { ... }
if #tArgs ~= 1 then
print( "Usage: makeroom <size>" )
return
end
-- Mine in a spiral pattern
local size = tonumber( tArgs[1] )
if size < 1 then
print( "Room size must be positive" )
return
end
local collected = 0
local function collect()
collected = collected + 1
if math.fmod(collected, 25) == 0 then
print( "Mined "..collected.." items." )
end
end
local function tryDig()
while turtle.detect() do
if turtle.dig() then
collect()
sleep(0.5)
else
return false
end
end
return true
end
local function tryDigUp()
while turtle.detectUp() do
if turtle.digUp() then
collect()
sleep(0.5)
else
return false
end
end
return true
end
local function tryDigDown()
while turtle.detectDown() do
if turtle.digDown() then
collect()
sleep(0.5)
else
return false
end
end
return true
end
local function refuel()
local fuelLevel = turtle.getFuelLevel()
if fuelLevel == "unlimited" or fuelLevel > 0 then
return
end
local function tryRefuel()
for n=1,16 do
if turtle.getItemCount(n) > 0 then
turtle.select(n)
if turtle.refuel(1) then
turtle.select(1)
return true
end
end
end
turtle.select(1)
return false
end
if not tryRefuel() then
print( "Add more fuel to continue." )
while not tryRefuel() do
sleep(1)
end
print( "Resuming Room." )
end
end
local function tryUp()
refuel()
while not turtle.up() do
if turtle.detectUp() then
if not tryDigUp() then
return false
end
elseif turtle.attackUp() then
collect()
else
sleep( 0.5 )
end
end
return true
end
local function tryDown()
refuel()
while not turtle.down() do
if turtle.detectDown() then
if not tryDigDown() then
return false
end
elseif turtle.attackDown() then
collect()
else
sleep( 0.5 )
end
end
return true
end
local function tryForward()
refuel()
while not turtle.forward() do
if turtle.detect() then
if not tryDig() then
return false
end
elseif turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
return true
end
local function channelForward(length)
refuel()
for i=1,length do
tryDigUp()
tryDigDown()
tryForward()
end
return true
end
print( "Making Room..." )
n=1
while n < size do
channelForward(n)
turtle.turnRight()
channelForward(n)
turtle.turnRight()
n=n+1
end
channelForward(n-1)
tryDigUp()
tryDigDown()
print( "Room complete." )
print( "Mined "..collected.." items total." )