dealingwith

New double oak farmer

Jan 24th, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. -- tree farmer
  2. -- requires a very specific tree farm setup
  3. -- which I will document somewhere and
  4. -- put a link to when that's done
  5. -- put fuel in first slot
  6. -- put 1 block of wood type in second slot
  7. -- put saplings of wood type in third slot
  8.  
  9. function fuel()
  10. if turtle.getFuelLevel() < 30 then
  11. turtle.select(1)
  12. if turtle.refuel(1) then
  13. return true
  14. end
  15. print("Refuelling failed.")
  16. return false
  17. end
  18. end
  19.  
  20. function chop ()
  21. local blocksMovedUp = 0
  22. while turtle.detect() do
  23. fuel()
  24. turtle.dig()
  25. if turtle.detectUp() then
  26. turtle.digUp()
  27. end
  28. turtle.up()
  29. blocksMovedUp = blocksMovedUp + 1
  30. end
  31. while blocksMovedUp > 0 do
  32. fuel()
  33. turtle.down()
  34. blocksMovedUp = blocksMovedUp - 1
  35. end
  36. -- plant new tree
  37. turtle.select(3)
  38. turtle.place()
  39. return true
  40. end
  41.  
  42. function detectTree()
  43. turtle.select(2)
  44. if turtle.compare() then
  45. return true
  46. else
  47. return false
  48. end
  49. end
  50.  
  51. function farmTree()
  52. tries = 0
  53. while not detectTree() do
  54. print("Tried " .. tries .. ". No tree. Waiting a minute")
  55. os.sleep(60)
  56. tries = tries + 1
  57. end
  58. chop()
  59. turtle.turnRight()
  60. turtle.turnRight()
  61. for i=4,16,1 do
  62. turtle.select(i)
  63. turtle.drop()
  64. end
  65. turtle.turnRight()
  66. turtle.turnRight()
  67. -- if there are no more saplings
  68. if turtle.getItemCount(3) == 0 then
  69. print("Out of samplings")
  70. return false
  71. end
  72. return true
  73. end
  74.  
  75. function right()
  76. turtle.turnRight()
  77. end
  78.  
  79. function left()
  80. turtle.turnLeft()
  81. end
  82.  
  83. function fif(val, a, b)
  84. if val then a() else b() end
  85. end
  86.  
  87. local args = {...}
  88. if #args > 1 or type(args[1]) ~= "string" then
  89. print("Takes argument: <right/left>")
  90. return
  91. end
  92.  
  93. ret = true
  94. left_tree = args[1] == "left"
  95. while ret == true do
  96. ret = farmTree()
  97. fif(left_tree, right, left)
  98. for i=1,10,1 do
  99. turtle.forward()
  100. end
  101. fif(left_tree, left, right)
  102. left_tree = not left_tree
  103. end
Advertisement
Add Comment
Please, Sign In to add comment