Advertisement
asweigart

farmtrees

Jul 29th, 2016
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. --[[ Tree Farming program By Al Sweigart
  2. Plants tree then cuts it down. ]]
  3.  
  4. os.loadAPI('hare') -- load the hare module
  5.  
  6. local result, item
  7. local logCount = 0
  8.  
  9. -- check if choptree program exists
  10. if not fs.exists('choptree') then
  11. error('You must install choptree program first.')
  12. end
  13.  
  14. while true do
  15. -- check inventory for saplings
  16. if not hare.selectItem('minecraft:sapling') then
  17. error('Out of saplings.')
  18. end
  19.  
  20. print('Planting...')
  21. turtle.place() -- plant sapling
  22.  
  23. -- wait until a tree has grown
  24. while true do
  25. result, item = turtle.inspect()
  26. if item ~= nil and item['name'] == 'minecraft:sapling' then
  27. -- "dye" is the name of bone meal
  28. if not hare.selectItem('minecraft:dye') then
  29. error('Out of bone meal.')
  30. end
  31.  
  32. print('Using bone meal...')
  33. turtle.place() -- use bone meal
  34. else
  35. break -- tree has grown
  36. end
  37. os.sleep(2)
  38. end
  39.  
  40. hare.selectEmptySlot()
  41. shell.run('choptree') -- run choptree
  42.  
  43. -- move to and face chest
  44. turtle.back()
  45. turtle.turnLeft()
  46. turtle.turnLeft()
  47.  
  48. -- put logs into chest
  49. while hare.selectItem('minecraft:log') do
  50. logCount = logCount + turtle.getItemCount()
  51. print('Total logs: ' .. logCount)
  52. turtle.drop()
  53. end
  54.  
  55. -- face planting spot
  56. turtle.turnLeft()
  57. turtle.turnLeft()
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement