DustyHands

startupSolo

Mar 29th, 2021
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.33 KB | None | 0 0
  1. --[[Tree Farming Program by Al Swigart
  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 blockExists 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.turnLeft()
  44.   turtle.turnLeft()
  45.  
  46.   -- put logs into chest
  47.   while hare.selectItem("minecraft:log") do
  48.     logCount = logCount + turtle.getItemCount()
  49.     print("Total logs: " .. logCount)
  50.     turtle.drop()
  51.   end
  52.  
  53.   -- face planting spot
  54.   turtle.turnLeft()
  55.   turtle.turnLeft()
  56. end
Advertisement
Add Comment
Please, Sign In to add comment