Skip to content

Instantly share code, notes, and snippets.

@Cyrixus
Created April 15, 2012 00:35
Show Gist options
  • Save Cyrixus/2389048 to your computer and use it in GitHub Desktop.
Save Cyrixus/2389048 to your computer and use it in GitHub Desktop.
ComputerCraft Room Carving Program
--[[
room
A program for carving rectangular rooms out of the earth.
Assumes the origin (0,0) is at the bottom right of the room.
Matthew DiBernardo [04.10.2012]
]]--
local function startNextRow(rowNum)
-- Turn and get ready to start the next row
if rowNum % 2 == 0 then
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
else
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
end
end
local function returnToStart(x, y, doesStartOutsideRoom)
if (x+1) % 2 == 0 then
turtle.turnRight()
turtle.turnRight()
for i=1, y-1 do
turtle.forward()
end
end
turtle.turnRight()
for i=1, x-1 do
turtle.forward()
end
if doesStartOutsideRoom then
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
end
turtle.turnRight()
end
local function digLevel(x, y, doesStartOutsideRoom)
print("Digging a new level at size [", x, ", ", y, "]")
if doesStartOutsideRoom then
turtle.dig()
turtle.forward()
end
for i=0, x-1 do
-- Dig a row
for j=1, y-1 do
turtle.dig()
turtle.forward()
end
-- As long as we're not on the last row...
if i ~= x-1 then
startNextRow(i)
end
end
returnToStart(x, y, true)
end
local function digRoom(x, y, doesStartOutsideRoom)
print("Digging a new room at size [", x, ", ", y, "]")
if doesStartOutsideRoom then
turtle.dig()
turtle.forward()
end
for i=0, x-1 do
-- Dig a row
for j=1, y-1 do
turtle.dig()
turtle.digUp()
turtle.forward()
end
turtle.digUp() -- Finish the last top square of the row
-- As long as we're not on the last row...
if i ~= x-1 then
startNextRow(i)
end
end
returnToStart(x, y, true)
end
local function digBigRoom(x, y, z, doesStartOutsideRoom)
print("Digging a new room at size [", x, ", ", y, ", ", z, "]")
if doesStartOutsideRoom then
turtle.dig()
turtle.forward()
end
for k=1, z/3 do
turtle.digUp()
turtle.up()
if k > 1 then
turtle.digUp()
turtle.up()
end
for i=0, x-1 do
-- Dig a row
for j=1, y-1 do
turtle.dig()
turtle.digUp()
turtle.digDown()
turtle.forward()
end
-- Finish the top and bottom of the last square
turtle.digUp()
turtle.digDown()
if i ~= x-1 then
startNextRow(i)
end
end
returnToStart(x, y, false) -- Compensate for different start pos of next volume
turtle.up()
end
if z % 3 == 1 then
turtle.digUp()
turtle.up()
digLevel(x, y, false)
elseif z % 3 == 2 then
turtle.digUp()
turtle.up()
digRoom(x, y, false)
end
-- Go Back to Start
for k=1, z-1 do
turtle.down()
end
if doesStartOutsideRoom then
turtle.back()
end
end
local function usage()
print("room x y [z] [options]")
end
-- Program Start --
local args = { ... } -- Get program args
-- If we don't have enough args, don't run the program
if #args < 2 then
usage()
return
end
local sizeX = tonumber(args[1])
local sizeY = tonumber(args[2])
local sizeZ = 2
if #args == 3 then
sizeZ = tonumber(args[3])
end
if (sizeX < 1) or (sizeY < 1) or (sizeZ < 1) then
print("All provided dimensions must be at least 1")
end
print(sizeZ)
-- Dig room at the specified size
if sizeZ == 1 then
digLevel(sizeX, sizeY, true)
elseif sizeZ == 2 then
digRoom(sizeX, sizeY, true)
else
digBigRoom(sizeX, sizeY, sizeZ, true)
end
@Cyrixus
Copy link
Author

Cyrixus commented May 1, 2012

Yeah, RTP has quite a bit of work left to go before it's going to be serviceable for web services. I've had to divert from working on RTP directly to write some tools on top of the http lib (I play on a tekkit server, so I needed some tools like wget and an apt-get equivalent for fetching the RTP repos as I update them). The main problem with RTP right now is that computer craft doesn't have an equivalent to services, so everything has to be a front-end application unless you feel like spawning a bunch of shell instances. This basically kills the address-resolution algorithm, unless every machine is a dedicated RTP host or I write some fancy workaround for the shell problem.

Other than that, I've got most of the stuff worked out. Once I can get address resolution in there, I can start writing the DHCP and GTLD servers, and the rest is downhill. 10-20 hours of work, to get something functional, if I can ever get around to actually doing it. Not bad for rewriting the internet.

If all you want is a mail server, though, that'd be relatively easy to write. Your only real complication is if you need to extend the range of the rednet wireless by bouncing messages through proxy machines, and even then you can just set up dedicated tunnels to serve that purpose. Pretty straight forward stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment