Guest User

tree

a guest
Aug 11th, 2012
1,562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. function f(loc)
  2.  while not turtle[loc]() do
  3.   sleep(0.5)
  4.  end
  5. end
  6. function up() f("up") end
  7. function down() f("down") end
  8. function fw() f("forward") end
  9. function back() f("back") end
  10. function l() f("turnLeft") end
  11. function r() f("turnRight") end
  12. function d() turtle.dig() end
  13. function du() turtle.digUp() end
  14. function dd() turtle.digDown() end
  15. function c(x)
  16. for i=1,x do d() fw() du() dd() end
  17. end
  18.  
  19.  
  20.  
  21. function cutTree()
  22. print("tree cut")
  23. hi = 0
  24. while not turtle.detectUp() do
  25. up() hi=hi+1
  26. end
  27. du() up() du() up() du() l() l()
  28. c(1) r() c(2) r() c(4) r() c(4) r()
  29. c(4) r() c(1) r() c(3) l() c(2) l()
  30. c(2) back() l() c(1) l() down()
  31. for r=1,hi do dd() down() end
  32. dd() turtle.placeDown() back()
  33. down() down()
  34. print(hi)
  35. end
  36.  
  37. function scanTree()
  38. if not turtle.detectDown() then
  39. r() fw() fw()
  40. for k=2,16 do
  41. turtle.select(k)
  42. turtle.drop()
  43. end
  44. turtle.select(1)
  45. back() back()
  46. l()
  47. end
  48. up() sleep(1)
  49. if turtle.detect() then
  50. up()
  51. if turtle.detect() then
  52. down()
  53. cutTree()
  54. else
  55. down()
  56. down()
  57. end
  58. else
  59. turtle.select(1) turtle.place()
  60. down()
  61. end
  62. l() if turtle.detect() then
  63. back() r() fw() r() fw()
  64. fw() fw()
  65. else
  66. l() l()
  67. if turtle.detect() then
  68. back() l() fw() l() fw()
  69. fw() fw()
  70. else
  71. fw() l() fw() fw() l() fw() r() fw()
  72. fw() fw()
  73. end
  74. end
  75. end
  76.  
  77. while true do
  78. scanTree()
  79. end
Advertisement
Add Comment
Please, Sign In to add comment