Advertisement
asweigart

farmtrees

Sep 20th, 2017
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 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 blockExists, 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. -- loop until a tree has grown
  24. while true do
  25. blockExists, item = turtle.inspect()
  26. if item ~= nil and item['name'] == 'minecraft:sapling' then
  27. -- "dye" is the name ID for 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. end
  38.  
  39. hare.selectEmptySlot()
  40. shell.run('choptree') -- run choptree
  41.  
  42. -- move to and face chest
  43. turtle.back()
  44. turtle.turnLeft()
  45. turtle.turnLeft()
  46.  
  47. -- put logs into chest
  48. while hare.selectItem('minecraft:log') do
  49. logCount = logCount + turtle.getItemCount()
  50. print('Total logs: ' .. logCount)
  51. turtle.drop()
  52. end
  53.  
  54. -- face planting spot
  55. turtle.turnLeft()
  56. turtle.turnLeft()
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement