ComputerCraft/Tree_Farm/treeautofarm.lua

70 lines
1.3 KiB
Lua
Raw Permalink Normal View History

2020-12-20 21:57:38 +00:00
--[[
treeautofarm program by The_Lux
This program checks a tree farm with given length and width and
chops the tree down, when it finds one.
]]
-- In which direction should the farm be automated?
DIRECTION = 'right'
NUM_OF_TREES = 9
TREE_SAPLING = 'oak'
TREE_DISTANCE = 3
DISTANCE = 3
WIDTH = 2
-- bring turtle in position
if DIRECTION == 'right' then
turtle.turnRight()
else
turtle.turnLeft()
end
turtle.forward()
if DIRECTION == 'right' then
turtle.turnLeft()
else
turtle.turnRight()
end
while true do
-- Wait a few minutes
os.sleep(300)
for i = 1, WIDTH do
-- Check a line of Trees
shell.run('treeline.lua', NUM_OF_TREES, TREE_DISTANCE, TREE_SAPLING)
-- Go to the next line. But only, if it isn't the last loop
if i < WIDTH then
if DIRECTION == 'right' then
turtle.turnRight()
else
turtle.turnLeft()
end
for j = 1, DISTANCE do
turtle.forward()
end
if DIRECTION == ' right' then
turtle.turnLeft()
else
turtle.turnRight()
end
end
end
-- Go back to start
if DIRECTION == 'right' then
turtle.turnRight()
else
turtle.turnLeft()
end
for i = 1, ((WIDTH - 1) * DISTANCE) do
turtle.forward()
end
if DIRECTION == ' right' then
turtle.turnLeft()
else
turtle.turnRight()
end
end