SoundChaos

Tree Felling

Aug 1st, 2014
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. turtle.refuel(1)
  2. turtle.up()
  3. o = 1
  4.  
  5. -- Checks for trees
  6. local function compareT()
  7. turtle.select(3) -- select slot 3
  8. turtle.suckDown()
  9. if turtle.compare() then -- if space in front is slot 3(a tree)
  10. turtle.dig() -- dig said tree
  11. turtle.forward() -- move to where tree was
  12. turtle.digDown() -- take out bottom tree block
  13. turtle.select(2) -- select sapling
  14. turtle.placeDown() -- place sapling
  15. turtle.select(3) -- select tree again
  16. turtle.digUp() -- dig 3rd tree spot
  17. turtle.up() -- move up to 3rd tree spot
  18. turtle.digUp() -- dig 4th tree spot
  19. turtle.up() -- move up to 4th tree spot
  20. turtle.digUp() -- dig possible 5th tree spot
  21. turtle.up() -- move up to possible 5th tree spot
  22. if turtle.compareUp() then -- checks if there is another tree on 6th spot
  23. turtle.digUp() -- if there is, he will dig it
  24. turtle.up() -- then he will move up
  25. if turtle.compareUp() then -- repeat last check
  26. turtle.digUp()
  27. else
  28. turtle.down()
  29. end
  30. else
  31. turtle.down()
  32. end
  33. turtle.down()
  34. turtle.down()
  35. turtle.down()
  36. turtle.select(1) -- select slot 1 again
  37. else
  38. turtle.forward()
  39. turtle.select(1)
  40. end
  41. end
  42.  
  43. -- Function to get the number of items in a given slot
  44. local function bcount()
  45. return turtle.getItemCount(p)
  46. end
  47.  
  48. -- Function to get the fuel level of the robot
  49. local function fcount()
  50. return turtle.getFuelLevel()
  51. end
  52.  
  53. -- check function
  54. local function check()
  55. print ("My current fuel level is " .. fcount())
  56. turtle.suckDown()
  57. if fcount() < 1 then
  58. print ("Attempting to eat my fuel...")
  59. if turtle.getItemCount(1) < 1 then
  60. print ("I am out of fuel...")
  61. o = 0
  62. end
  63. turtle.select(1)
  64. turtle.refuel(1)
  65. end
  66. end
  67.  
  68. repeat
  69. for t=1, 40 do
  70. compareT()
  71. check()
  72. end
  73. turtle.turnLeft()
  74. turtle.turnLeft()
  75. until o < 1
Advertisement
Add Comment
Please, Sign In to add comment