Posted 02 January 2013 - 05:56 PM
Hi all, first post, first program.
Just started with Minecraft/Tekkit last week. I built this turtle control program to help me make some bridges from place to place (or tunnels if it encounters mountains). It uses World Anchors (since it's my private server with friends) to let it keep marching along while I'm doing other things.
Let me know if there are glaring rookie mistakes, but I figured I'd share, since I was having reasonably good results (understandably, it has trouble with sand/gravel) with a few of these building road networks in my world.
Things to note:
Pastebin: http://pastebin.com/25r96GRx (I think that's right - I've never used it before.)
Edit: This was done in Tekkit, so no compat ability issues there. Didn't realize that was a common problem.
Edit2: Spoiler tag for folding. Right.
Also realized that a screenshot might be useful.
Just started with Minecraft/Tekkit last week. I built this turtle control program to help me make some bridges from place to place (or tunnels if it encounters mountains). It uses World Anchors (since it's my private server with friends) to let it keep marching along while I'm doing other things.
Let me know if there are glaring rookie mistakes, but I figured I'd share, since I was having reasonably good results (understandably, it has trouble with sand/gravel) with a few of these building road networks in my world.
Things to note:
- Fuel the guy up with about 15 charcoal (~1400 fuel) first, then
- Load whatever bridge material you want in slots 1-14
- Pop world anchors into slot 15
- Pop torches into slot 16
Pastebin: http://pastebin.com/25r96GRx (I think that's right - I've never used it before.)
Spoiler
-- ---------------------------------
-- Various Variables and Settings --
local currentSlot = 1
local materialReferenceSlot = 14
local anchorSlot = 15
local torchSlot = 16
local supplied = true
local rowCount = 0
local lampFreq = 6
-- --------------------
-- Utility Functions --
-- checkSupply ensures that there is material to build with on hand
local function checkSupply()
turtle.select(currentSlot)
-- If the current slot is empty
if turtle.getItemCount(currentSlot) == 0 then
-- bump up a slot
currentSlot = currentSlot + 1
-- make sure it is not past the reference slot
if currentSlot == (anchorSlot + 1) then
supplied = false
currentSlot = currentSlot - 1
return
end
-- still in the supplies section, so that is good
turtle.select(currentSlot)
-- make sure it has the right material
if turtle.compareTo(materialReferenceSlot) then
supplied = true
else
supplied = false
end
-- if the current slot is NOT empty
else
-- make sure that the current slot still has the right material in it
if turtle.compareTo(materialReferenceSlot) then
supplied = true
else
supplied = false
end
end
end
--
local function forwardDig(mode)
if turtle.detect() then
turtle.dig()
end
if mode == "place" then
checkSupply()
turtle.place()
elseif mode == "move" then
turtle.forward()
else
-- do nothing
end
end
local function downDig(mode)
if turtle.detectDown() then
turtle.digDown()
end
if mode == "place" then
checkSupply()
turtle.placeDown()
elseif mode == "move" then
turtle.down()
else
-- do nothing
end
end
local function upDig(mode)
if turtle.detectUp() then
turtle.digUp()
end
if mode == "place" then
checkSupply()
turtle.placeUp()
elseif mode == "move" then
turtle.up()
else
-- do nothing
end
end
local function turnAround()
-- It is not an ambiturn.
turtle.turnRight()
turtle.turnRight()
end
local function placeTorch(whichWay)
turtle.select(torchSlot)
if whichWay == "forward" then
turtle.place()
elseif whichWay == "up" then
turtle.placeUp()
end
turtle.select(currentSlot)
end
local function placeAnchor()
turtle.select(anchorSlot)
turtle.place()
turtle.select(currentSlot)
end
-- -----------------
-- Main Functions --
-- ensures the things needed (fuel, material, torches, world anchors) are on hand
local function checkStarting()
local ReadyToGo = true
local ErrorList = {}
-- Check that the 14th slot has a material for reference
if turtle.getItemCount(materialReferenceSlot) == 0 then
ReadyToGo = false
table.insert(ErrorList,"Reference Material missing in slot 14.")
end
-- Slots 1 throuth 13 need to be at least 64 of the material in slot 14
for i = 1, 13 do
turtle.select(i)
if turtle.getItemCount(i) == 0 then
ReadyToGo = false
table.insert(ErrorList,"Missing material in slot "..tostring(i))
else
if not turtle.compareTo(14) then
ReadyToGo = false
table.insert(ErrorList,"Wrong material in slot "..tostring(i))
end
end
end
-- Slot 15 needs to be at least 12 world anchor type objects
if turtle.getItemCount(anchorSlot) == 0 then
ReadyToGo = false
table.insert(ErrorList,"Anchor type object missing in slot 15.")
end
-- Slot 16 needs to be at least 60 torch type objects
if turtle.getItemCount(torchSlot) <= 59 then
ReadyToGo = false
table.insert(ErrorList,"Insufficient torch objects missing in slot 16, should be 60-64.")
end
-- Based on my calculations, with the above payload, it will go about 180 meters/blocks.
-- That will take about 1,290 fuel with the movements planned
if turtle.getFuelLevel() < 1290 then
ReadyToGo = false
table.insert(ErrorList,"Turtle should have at least 1,290 fuel (17 coal/charcoal). Please refuel.")
end
if not ReadyToGo then
print("Cannot start building. Issues:")
for i=1,#ErrorList do
print(" -"..tostring(ErrorList[i]))
end
else
print("Supplies/fuel appear to be ready.")
print("Starting...")
end
supplied = ReadyToGo
return ReadyToGo
end
-- Create normal segment pair
local function createNormal()
-- First section
forwardDig("move")
turtle.turnRight()
downDig("place")
forwardDig("place")
upDig("move")
upDig("")
turnAround()
forwardDig("move")
downDig("move")
downDig("place")
forwardDig("place")
turtle.turnRight()
forwardDig("move")
-- Second section
turtle.turnLeft()
downDig("place")
forwardDig("place")
upDig("move")
upDig("")
turnAround()
forwardDig("move")
downDig("move")
downDig("place")
forwardDig("place")
turtle.turnLeft()
end
-- Create arch/light pair
local function createArch()
-- First section, same as normal
forwardDig("move")
turtle.turnRight()
downDig("place")
forwardDig("place")
upDig("move")
upDig("")
turnAround()
forwardDig("move")
downDig("move")
downDig("place")
forwardDig("place")
turtle.turnRight()
forwardDig("move")
-- Second section, quite different, is an arch with torches
turtle.turnLeft()
downDig("place")
forwardDig("place")
upDig("move")
forwardDig("place")
upDig("move")
forwardDig("place")
upDig("place")
turnAround()
forwardDig("move")
turnAround()
placeTorch("forward")
turnAround()
upDig("place")
forwardDig("place")
downDig("move")
placeTorch("up")
forwardDig("place")
downDig("move")
forwardDig("place")
downDig("place")
turtle.turnLeft()
end
-- Place/collect World Anchors to not overload system, but keep going sans player
local function rollingAnchor()
turtle.back()
turtle.back()
placeAnchor()
turnAround()
for i = 1,16 do
turtle.forward()
end
turtle.dig() -- nix the old world anchor
turtle.suck() -- try to pick it back up
turnAround()
for i = 1,16 do
turtle.forward()
end
-- Move over the new WA back to 'current position'
turtle.up()
turtle.forward()
turtle.forward()
turtle.down()
end
-- --------
-- Main --
if checkStarting() then
-- setup a first anchor
turnAround()
placeAnchor()
turnAround()
while supplied do
for i = 1,3 do
createNormal()
createNormal()
createArch()
end
rollingAnchor()
end
end
Edit: This was done in Tekkit, so no compat ability issues there. Didn't realize that was a common problem.
Edit2: Spoiler tag for folding. Right.
Also realized that a screenshot might be useful.