You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
903 B
48 lines
903 B
local robot = require("robot")
|
|
local os = require("os")
|
|
|
|
local length = ...
|
|
|
|
if not length then
|
|
print('Usage: lumberjack <length>')
|
|
return
|
|
end
|
|
|
|
local function mine_tree()
|
|
local n = 0
|
|
robot.swing()
|
|
robot.forward()
|
|
robot.swingDown()
|
|
while robot.detectUp() do
|
|
robot.swingUp()
|
|
robot.up()
|
|
n = n + 1
|
|
end
|
|
for _ = 1, n do
|
|
while not robot.down() do end
|
|
end
|
|
robot.placeDown()
|
|
end
|
|
|
|
while true do
|
|
for _ = 1, length do
|
|
if robot.detect() then
|
|
mine_tree()
|
|
else
|
|
while not robot.forward() do end
|
|
end
|
|
robot.suckDown()
|
|
end
|
|
robot.turnAround()
|
|
for _ = 1, length do
|
|
if robot.detect() then
|
|
mine_tree()
|
|
else
|
|
while not robot.forward() do end
|
|
end
|
|
robot.suckDown()
|
|
end
|
|
robot.turnAround()
|
|
os.execute("sleep 5")
|
|
end
|