Advertisement
Inksaver

harvestTree02

Nov 22nd, 2014
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. --[[
  2.     harvestTree02.lua
  3.     http://pastebin.com/XJi4y9Gc
  4.     Using functions for entire script.
  5.     Script runs from the main() statement at the end
  6. ]]--
  7.  
  8. function harvestTree()
  9.     turtle.dig()       -- dig base of tree
  10.     --use wood to refuel if needed
  11.     if turtle.getFuelLevel() < 15 then
  12.         turtle.craft()   -- craft wood to planks(1 wood, 1 planks = 15 fuel)
  13.         turtle.refuel()  -- add 4 x 15 fuel
  14.     end
  15.     turtle.forward() -- go under tree
  16.     -- Loop to climb up tree and harvest trunk and surrounding leaves
  17.     while turtle.detectUp() do -- continue loop while block detected above
  18.         turtle.digUp() -- Dig block above
  19.         turtle.up()    -- Move up
  20.         -- Inner loop to check for leaves
  21.         for i = 1, 4 do
  22.             if turtle.detect() then -- check if leaves in front
  23.                 turtle.dig() --Dig leaves
  24.             end
  25.             turtle.turnRight()
  26.         end
  27.     end
  28.     -- At top of the tree. New loop to return to ground
  29.     while not turtle.detectDown() do -- While nothing detected below
  30.         turtle.down() -- Go down
  31.     end
  32. end
  33.  
  34. function main()
  35.     os.sleep(2)   -- pause for 2 secs to allow time to press esc
  36.     harvestTree() -- Call the harvestTree function
  37. end
  38.  
  39. --*********************Program runs from here*****************
  40. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement