Skip to content

Instantly share code, notes, and snippets.

@maddiesch
Created September 5, 2014 18:13
Show Gist options
  • Save maddiesch/8e7239dc0d088b8cf8b1 to your computer and use it in GitHub Desktop.
Save maddiesch/8e7239dc0d088b8cf8b1 to your computer and use it in GitHub Desktop.
Create a room with a ComputerCraft Mining Turtle
--[[
By: skylarsch
Usage: room <length (9)> <width (9)> <height (5)>
Each of the arguments are optional, but if you must specify all the values before the one you want to change.
--]]
-- MARK: Helper Functions
function fwd() -- Move forward
while not turtle.forward() do
turtle.dig()
end
end
function move(ammount) -- Move forward by the number of blocks
for i = 0, ammount, 1 do
fwd()
end
end
function refuel() -- Refuel the turtle if it needs it
local slot = 1
while turtle.getFuelLevel() < 50 do
if slot > 16 then
print("Failed to refuel turtle")
turtle.select(1)
return false
end
turtle.select(slot)
if not turtle.refuel(1) then
slot = slot + 1
end
end
turtle.select(1)
return true
end
function up()
while not turtle.up() do
turtle.digUp()
end
end
function down()
while not turtle.down() do
turtle.digDown()
end
end
function goDown(ammount)
for i = 0, ammount, 1 do
down()
end
end
function makeFloor(l, w)
for i = 0, w + 1, 1 do
move(l)
if (i % 2 == 0) then
if i <= w then
turtle.turnRight()
fwd()
turtle.turnRight()
else
turtle.turnLeft()
move(w)
turtle.turnLeft()
move(l)
turtle.turnLeft()
turtle.turnLeft()
end
else
if i <= w then
turtle.turnLeft()
fwd()
turtle.turnLeft()
else
turtle.turnRight()
move(w)
turtle.turnRight()
end
end
refuel()
end
end
-- MARK: Main App
local argv = {...}
local length = (argv[1] or 9) - 2
local width = (argv[2] or 9) - 2
local height = (argv[3] or 5) - 1
print("Creating Room:")
print(" "..(length + 2).."x"..(width + 2).."x"..(height + 1))
if not refuel() then
print("Aborting...")
return
end
for floor = 0, height, 1 do
makeFloor(length, width)
if floor < height then
up()
else
goDown(height - 1)
end
if not refuel() then
print("Aborting...")
return
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment