ComputerCraft/Tree_Farm/farmtree.lua

52 lines
1.1 KiB
Lua
Raw Normal View History

2020-11-06 15:05:04 +00:00
--[[Tree Farming App by Al Sweigart
Plants tree and cuts it down.]]
2020-11-06 11:00:34 +00:00
2020-11-06 15:05:04 +00:00
os.loadAPI('hare.lua') -- Load the hare module
2020-11-06 11:00:34 +00:00
local blockExists, item
local logCount = 0
2020-11-06 15:05:04 +00:00
-- Check if choptree program exists
2020-11-06 11:00:34 +00:00
if not fs.exists('choptree.lua') then
2020-11-06 15:05:04 +00:00
error('You must install choptree app first')
2020-11-06 11:00:34 +00:00
end
while true do
2020-11-06 15:05:04 +00:00
-- Check inventory for saplings
2020-11-06 11:00:34 +00:00
if not hare.selectItem('minecraft:spruce_sapling') then
2020-11-06 15:05:04 +00:00
error('Out of saplings')
2020-11-06 11:00:34 +00:00
end
2020-11-06 15:05:04 +00:00
2020-11-06 11:00:34 +00:00
print('Planting...')
2020-11-06 15:05:04 +00:00
turtle.place() -- plant sapling
-- Loop until tree is grown
2020-11-06 11:00:34 +00:00
while true do
blockExists, item = turtle.inspect()
2020-11-06 15:05:04 +00:00
if item['name'] ~= 'minecraft:spruce_log' then
print('wait 5 seconds')
os.sleep(5)
2020-11-06 11:00:34 +00:00
else
2020-11-06 15:05:04 +00:00
break -- tree has grown
end
2020-11-06 11:00:34 +00:00
end
hare.selectEmptySlot()
2020-11-06 15:05:04 +00:00
shell.run('choptree.lua') -- run choptree
2020-11-06 11:00:34 +00:00
-- move to and face chest
turtle.back()
turtle.turnLeft()
turtle.turnLeft()
-- put logs into chest
2020-11-06 15:05:04 +00:00
while hare.selectItem('minecraft:spruce_log') do
logCount = logCount + turtle.getItemCount()
2020-11-06 11:00:34 +00:00
print('Total logs: ' .. logCount)
turtle.drop()
end
2020-11-06 15:05:04 +00:00
--face planting sport
2020-11-06 11:00:34 +00:00
turtle.turnLeft()
turtle.turnLeft()
end