Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[Tree Farming Program by Al Swigart
- --Plants trees in a line
- --then cuts them down.]]
- os.loadAPI('hare') -- load the hare module
- local blockExists, item
- local logCount = 0
- function goFwd()
- turtle.forward()
- turtle.forward()
- end
- -- check if choptree program exists
- if not fs.exists('choptree') then
- error('You must install choptree program first.')
- end
- while true do
- -- check inventory for saplings
- if not hare.selectItem('minecraft:sapling') then
- error('Out of saplings.')
- end
- print('Planting...')
- turtle.place() -- plant sapling
- -- loop until a tree has grown
- while true do
- blockExists, item = turtle.inspect()
- if blockExists and item['name'] == 'minecraft:sapling' then
- print("Not yet grown.")
- os.sleep(30)
- else
- break -- tree has grown
- end
- end
- -- goes down the line checking each tree and cutting down the grown ones
- shell.run("choptree")
- turtle.place()
- while not blockExists and item['name'] == 'minecraft:cobblestone' do
- turtle.turnRight()
- goFwd()
- turtle.turnLeft()
- if blockExists and item['name'] == 'minecraft:log' then
- shell.run('choptree') -- run choptree
- hare.selectItem("minecraft:sapling")
- turtle.place()
- else
- print("Not yet grown.")
- end
- end
- -- returns to initial location
- turtle.turnLeft()
- for i = 1,12 do
- turtle.forward()
- end
- turtle.turnLeft()
- -- put logs into chest
- while hare.selectItem("minecraft:log") do
- logCount = logCount + turtle.getItemCount()
- print("Total logs: " .. logCount)
- turtle.drop()
- end
- -- face planting spot
- turtle.turnLeft()
- turtle.turnLeft()
- end
Add Comment
Please, Sign In to add comment