DustyHands

startup

Mar 29th, 2021 (edited)
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1. --[[Tree Farming Program by Al Swigart
  2. --Plants trees in a line
  3. --then cuts them down.]]
  4.  
  5. os.loadAPI('hare') -- load the hare module
  6.  
  7. local blockExists, item
  8. local logCount = 0
  9. function goFwd()
  10.   turtle.forward()
  11.   turtle.forward()
  12. end
  13.  
  14. -- check if choptree program exists
  15. if not fs.exists('choptree') then
  16.   error('You must install choptree program first.')
  17. end
  18.  
  19. while true do
  20.   -- check inventory for saplings
  21.   if not hare.selectItem('minecraft:sapling') then
  22.     error('Out of saplings.')
  23.   end
  24.  
  25.   print('Planting...')
  26.   turtle.place() -- plant sapling
  27.  
  28.   -- loop until a tree has grown
  29.   while true do
  30.     blockExists, item = turtle.inspect()
  31.     if blockExists and item['name'] == 'minecraft:sapling' then
  32.       print("Not yet grown.")
  33.       os.sleep(30)
  34.     else
  35.       break -- tree has grown
  36.     end
  37.   end
  38.   -- goes down the line checking each tree and cutting down the grown ones
  39.   shell.run("choptree")
  40.   turtle.place()
  41.   while not blockExists and item['name'] == 'minecraft:cobblestone' do
  42.     turtle.turnRight()
  43.     goFwd()
  44.     turtle.turnLeft()
  45.     if blockExists and item['name'] == 'minecraft:log' then
  46.         shell.run('choptree') -- run choptree
  47.         hare.selectItem("minecraft:sapling")
  48.         turtle.place()
  49.     else
  50.         print("Not yet grown.")
  51.     end
  52.   end
  53.   -- returns to initial location
  54.   turtle.turnLeft()
  55.   for i = 1,12 do
  56.     turtle.forward()
  57.   end
  58.   turtle.turnLeft()
  59.    
  60.   -- put logs into chest
  61.   while hare.selectItem("minecraft:log") do
  62.     logCount = logCount + turtle.getItemCount()
  63.     print("Total logs: " .. logCount)
  64.     turtle.drop()
  65.   end
  66.  
  67.   -- face planting spot
  68.   turtle.turnLeft()
  69.   turtle.turnLeft()
  70. end
Add Comment
Please, Sign In to add comment