TheSommer

Treefeller

Jan 25th, 2013
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. --[[
  2.     Author
  3.         Rasmus Sommer aka. TheSommer
  4.         youtube.com/thesommersmc
  5.         twitch.tv/thesommer
  6.    
  7.     How to use:
  8.         (WORKS WELL WITH BIRCH, SPRUCE OR FIR)
  9.         Slot 1 - Fuel
  10.         Slot 2 - Saplings
  11.         Slot 3 - Bonemeal
  12.    
  13.         treefeller <amount>
  14. --]]
  15.  
  16. local tArgs = { ... }
  17. if #tArgs ~= 1 then
  18.     print( "Usage: treefeller <amount>" )
  19.     return
  20. end
  21.  
  22. local length = tonumber( tArgs[1] )
  23. if length < 1 then
  24.     print( "Amount must be positive" )
  25.     return
  26. end
  27.  
  28. local function tryRefuel()
  29.     if turtle.getFuelLevel() == 0 then
  30.         turtle.select(1)
  31.         turtle.refuel(1)
  32.     end
  33. end
  34.  
  35. local function tryDig()
  36.     while turtle.detect() == true do
  37.         turtle.dig()
  38.         sleep(0.5)
  39.     end
  40. end
  41.  
  42. local function tryDigUp()
  43.     while turtle.detectUp() == true do
  44.         turtle.digUp()
  45.         sleep(0.5)
  46.     end
  47. end
  48.  
  49. local function tryUp()
  50.     tryDigUp()
  51.     tryRefuel()
  52.     turtle.up()
  53. end
  54.  
  55. local function tryDown()
  56.     while turtle.detectDown() == true do
  57.         turtle.digDown()
  58.         sleep(0.5)
  59.     end
  60.     tryRefuel()
  61.     turtle.down()
  62. end
  63.  
  64. local function tryForward()
  65.     tryDig()
  66.     tryRefuel()
  67.     turtle.forward()
  68. end
  69.  
  70. local count = 1
  71.  
  72. for i = 1, length do
  73.     turtle.select(2)
  74.     turtle.place()
  75.     turtle.select(3)
  76.     while turtle.place() == true do
  77.         sleep(0.5)
  78.     end
  79.     tryForward()
  80.     while turtle.detectUp() == true do
  81.         tryUp()
  82.     end
  83.     while turtle.detectDown() == false do
  84.         tryDown()
  85.     end
  86.     turtle.back()
  87. end
Advertisement
Add Comment
Please, Sign In to add comment