tArgs = {...}
local fuelSlot, chestSlot = 16, 15
local height = 0
function goUp(distance)
if distance == nil then distance = 1 end
shell.run("go", "up", distance)
end
function goDown(distance)
if distance == nil then distance = 1 end
shell.run("go", "up", distance)
end
function goForward(distance)
if distance == nil then distance = 1 end
shell.run("go", "forward", distance)
end
function goBack(distance)
if distance == nil then distance = 1 end
shell.run("go", "back", distance)
end
function digUp(distance)
if distance == nil then distance = 1 end
for i = 1, distance do
while turtle.detectUp() == true do
turtle.digUp()
sleep(0.5)
end
if distance > 1 then
goUp()
end
end
end
function dig(distance)
if distance == nil then distance = 1 end
for i = 1, distance do
while turtle.detect() == true do
turtle.dig()
sleep(0.5)
end
end
end
function digDown(distance)
if distance == nil then distance = 1 end
for i = 1, distance do
turtle.digDown()
sleep(0.5)
if distance > 1 then
goDown()
end
end
end
function getFuel()
return turtle.getFuelLevel()
end
function returnToStart()
goDown(height)
height = 0
end
function dropLoad()
shell.run("turn", "around")
for i = 1, 14 do
turtle.select(i)
turtle.drop()
end
turtle.select(1)
end
if tArgs[1] == "-h" then
print("Usage: lumberjack <redwood>")
elseif tArgs[1] == nil then
if turtle.getItemCount(chestSlot) == 0 or turtle.getItemCount(fuelSlot) == 0 then
print("Please insert a chest into slot "..chestSlot.." and fuel into slot "..fuelSlot..", then run lumberjack again")
else
shell.run("turn", "around")
turtle.select(chestSlot)
turtle.place()
turtle.select(1)
shell.run("turn", "around")
dig()
goForward()
while turtle.detectUp() == true do
digUp()
goUp()
height = height + 1
if getFuel() == 0 then
turtle.select(fuelSlot)
turtle.refuel(5)
turtle.select(1)
end
end
returnToStart()
dropLoad()
end
elseif tArgs[1] == "redwood" then
if turtle.getItemCount(chestSlot) == 0 or turtle.getItemCount(fuelSlot) == 0 then
print("Please insert a chest into slot "..chestSlot.." and fuel into slot "..fuelSlot..", then run lumberjack again")
else
shell.run("turn", "around")
turtle.select(chestSlot)
turtle.place()
turtle.select(1)
shell.run("turn", "around")
dig()
goForward()
while turtle.detectUp() == true do
shell.run("turn", "right")
dig()
shell.run("turn", "left")
dig()
goForward()
shell.run("turn", "right")
dig()
shell.run("turn", "left")
goBack()
digUp()
goUp()
height = height + 1
if getFuel() == 0 then
turtle.select(fuelSlot)
turtle.refuel(5)
turtle.select(1)
end
end
if turtle.detect() == true then
dig()
shell.run("turn", "right")
dig()
shell.run("turn", "left")
goForward()
shell.run("turn", "right")
dig()
shell.run("turn", "left")
goBack()
end
returnToStart()
dropLoad()
end
else
print("Usage: lumberjack <redwood>")
end