Saereth

TreeFarm+SanityChecking

May 28th, 2014
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. function makeTree()
  20. if turtle.getItemCount(1)==0 then
  21. print("Not enough Saplings.")
  22. return
  23. end
  24.  
  25. if turtle.getItemCount(2)==0 then
  26. print("Not enough BoneMeal.")
  27. return
  28. end
  29. turtle.select(1)
  30. turtle.place()
  31. sleep(1)
  32. turtle.select(2)
  33. turtle.place()
  34. sleep(1)
  35. end
  36.  
  37.  
  38.  
  39. function resetPos()
  40. print("Resetting position.")
  41.  
  42. r=0
  43. while r==0 do
  44. down()
  45. if turtle.detectDown()==true then
  46. r=1
  47. end
  48. end
  49. back()
  50. end
  51.  
  52.  
  53. function cutTree()
  54. print("tree cut")
  55. hi = 0
  56. while not turtle.detectUp() and hi<7 do
  57. up() hi=hi+1
  58. print("cut loop")
  59. print(hi)
  60. end
  61. du() up() du() up() du() l() l()
  62. c(1) r() c(2) r() c(4) r() c(4) r()
  63. c(4) r() c(1) r() c(3) l() c(2) l()
  64. c(2) back() l() c(1) l() down()
  65. for r=1,hi do dd() down() end
  66. dd() back()
  67. down()
  68. print(hi)
  69. end
  70.  
  71. function checkMats()
  72. -- Checking saplings slot
  73. print("Checking for mats.")
  74. sleep(2)
  75. if turtle.getItemCount(1)==0 then
  76. print("Not enough Saplings.")
  77. s=1
  78. turtle.turnLeft()
  79. turtle.select(1)
  80. turtle.suck()
  81. turtle.turnRight()
  82. if turtle.getItemCount(1)>0 then
  83. s=0
  84. end
  85. end
  86.  
  87. -- Checking bonemeal slot
  88. if turtle.getItemCount(2)==0 then
  89. print("Not enough bonemeal.")
  90. turtle.turnLeft()
  91. turtle.turnLeft()
  92. turtle.select(1)
  93. turtle.suck()
  94. turtle.turnRight()
  95. turtle.turnRight()
  96. end
  97.  
  98. end
  99.  
  100. function checkStop()
  101. if s==0 then
  102. shell.exit()
  103. end
  104. end
  105.  
  106. function ConsolidateMats()
  107. turtle.turnLeft()
  108. print("Consolidating saplings.")
  109. for i=3,15 do
  110. turtle.select(i)
  111.  
  112. if turtle.compareTo(1) then -- It's a sapling not in slot one
  113. turtle.drop() -- put it in the chest to our left
  114. end
  115. end
  116. turtle.turnRight()
  117. print("Sending all other mats to processing.")
  118. for i=3,15 do
  119. turtle.select(i)
  120. turtle.dropDown()
  121. end
  122. end
  123.  
  124. while true do
  125. makeTree()
  126. checkMats()
  127. cutTree()
  128. ConsolidateMats()
  129. checkStop()
  130. end
Advertisement
Add Comment
Please, Sign In to add comment