Skip to content

Instantly share code, notes, and snippets.

@maddiesch
Created September 5, 2014 18:14
Show Gist options
  • Save maddiesch/6e8ed57d388e22094dc7 to your computer and use it in GitHub Desktop.
Save maddiesch/6e8ed57d388e22094dc7 to your computer and use it in GitHub Desktop.
Create a branch mine using a ComputerCraft Mining Turtle
--[[
By: skylarsch
Usage: branch <number of tunnels (8)> <length of each tunnel (10)> <space between tunnels (2)>
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 digUp() -- Dig up
while turtle.detectUp() do
turtle.digUp()
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 makeTunnel(length)
for i = 0, length, 1 do
digUp()
fwd()
end
digUp()
end
function aboutFace()
turtle.turnRight()
turtle.turnRight()
end
-- MARK: Main App Start
local argv = {...}
local brCount = (argv[1] or 8) - 1
local brLength = (argv[2] or 10) - 1
local brSpace = argv[3] or 2
print("Creating Branch Mine")
if not refuel() then
print("Aborting...")
return
end
for tunnel = 0, brCount, 1 do
makeTunnel(brLength)
aboutFace()
move(brLength)
if tunnel == brCount then
break
end
turtle.turnLeft()
move(brSpace)
turtle.turnLeft()
if not refuel() then
print("Aborting...")
return
end
end
local back = brCount * (brSpace + 1) - 1
turtle.turnRight()
move(back)
turtle.turnRight()
refuel()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment