This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
kelm's profile picture

Building Toolset

Started by kelm, 28 October 2013 - 08:27 PM
kelm #1
Posted 28 October 2013 - 09:27 PM
Turtle Build Tools

I recently wrote a few tools which I've been using to build buildings quickly. The scripts aren't meant to build an entire building (they'd be really bland) but rather seperate pieces, and some of the more redundant parts. I intend to continue adding stuff to it, so hit me with any shapes you think might be useful!

Currently it includes two tools, a block builder and plane builder, both available on pastebin.

Plane Builder [Pastebin – EtXZHKdS]
Video Demonstration
[media]http://youtu.be/P9pG-k0q8Gs[/media]
Code [ http://pastebin.com/EtXZHKdS ]
Spoiler– Build Tools
– plane v1

local args = { … }

if args[1] == nil or args[2] == nil or turtle.getItemCount(1) < 1 or args[1] == "help" then
print ("Usage: build [forward length] [right length]")
print ("Put one of the building block in the turtle's")
print ("first slot.")
return
end

local stack = 0
local vertical = false
local flength = tonumber(args[1])
local rlength = tonumber(args[2])
local blocks = rlength * flength

if turtle.getFuelLevel() < blocks + 1 then
print ("You do not have enough fuel. This job needs ", fuelreq, " fuel.")
return
end

if args[3] == "-v" then
vertical = true
end

function step()
while not turtle.forward() do
turtle.dig()
end
end

function stepUp()
while not turtle.up() do
turtle.digUp()
end
end

function rotateRight()
turtle.turnRight()
if vertical then
stepUp()
else
step()
end
turtle.turnRight()
end

function rotateLeft()
turtle.turnLeft()
if vertical then
stepUp()
else
step()
end
turtle.turnLeft()
end

function placeDown()
while not turtle.placeDown() do
turtle.digDown()
end
end

– Find a block of the type identified in slot 1. Use no other block kind.
function findBlock()
stack = 0
local found = false
for i = 2, 16, 1 do
turtle.select(i)
if turtle.getItemCount(i) > 0 and turtle.compareTo(1) then
found = true
stack = turtle.getItemCount(i)
break
end
end
return found
end

– Start building at level of turtle placement.
stepUp()

for i = 1, rlength, 1 do
for j = 1, flength, 1 do
if stack < 1 then
print ("Waiting for stack.")
while not findBlock() do end
end
if not turtle.compareDown() then
placeDown()
stack = stack - 1
end
if j < flength then
step()
end
end
if i < rlength then
if i % 2 ~= 0 then
rotateRight()
else
rotateLeft()
end
end
end

Block Builder [Pastebin – jav0k41W]
Video Demonstration
[media]http://youtu.be/mGOynpnaJHQ[/media]
Code [ https://www.youtube....h?v=mGOynpnaJHQ ]
Spoiler– Build Tools
– block v1.3

local args = { … }

if args[1] == nil or args[2] == nil or turtle.getItemCount(1) < 1 or args[1] == "help" then
print ("Usage: block [wall length] [height]")
print ("Put one of the building block in the turtle's")
print ("first slot.")
return
end

local stack = 0
local cut = false
local length = tonumber(args[1]) - 1
local height = tonumber(args[2])
local fuelreq = (((length * 4) - 4) * height) + height

if args[3] == "-cc" then
print ("Cutting corners.")
cut = true
length = length - 1
end

if turtle.getFuelLevel() < fuelreq then
print ("You do not have enough fuel. This job needs ", fuelreq, " fuel.")
return
end

function step()
while not turtle.forward() do
turtle.dig()
end
end

function stepUp()
while not turtle.up() do
turtle.digUp()
end
end

function placeDown()
while not turtle.placeDown() do
turtle.digDown()
end
end

– Find a block of the type identified in slot 1. Use no other block kind.
function findBlock()
stack = 0
local found = false
for i = 2, 16, 1 do
turtle.select(i)
if turtle.getItemCount(i) > 0 and turtle.compareTo(1) then
found = true
stack = turtle.getItemCount(i)
break
end
end
return found
end

– Construct one side of the building; place and *then* move.
function wall()
for i = 1, length, 1 do
if stack < 1 then
print("Waiting for new stack.")
while not findBlock() do end
end
if not turtle.compareDown() then
placeDown()
stack = stack - 1
end
step()
end
end

function layer()
for i = 1, 4, 1 do
wall()
turtle.turnRight()
if cut then
step()
end
end
end

– Start building at level of turtle placement.
stepUp()

– Start ahead of the corner (otherwise placement can get confusing).
if cut then
step()
end

for i = 1, height, 1 do
layer()
stepUp()
end
deFENCE_ #2
Posted 31 October 2013 - 03:28 AM
Nice!