Advertisement
Nawiks

DoubleTreeFarm

Feb 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. ready = false
  2. digLeaf = false
  3.  
  4. function saveRoutinePosition(action)
  5.  
  6. dataFile = fs.open("Data", "w")
  7. dataFile.write(action)
  8. dataFile.close()
  9. end
  10.  
  11. function readRoutine()
  12.  
  13. dataFile = fs.open("Data", "r")
  14. action = dataFile.readAll()
  15. dataFile.close()
  16. return action
  17. end
  18.  
  19. function refuel()
  20.  
  21. if(turtle.getFuelLevel() < turtle.getFuelLimit()/2) then
  22. turtle.select(1)
  23. turtle.refuel(turtle.getItemCount() - 1)
  24. end
  25. end
  26.  
  27. function dropContainer(slot, amount, where)
  28.  
  29. turtle.select(slot)
  30.  
  31. while turtle.getItemCount(slot) - amount < 1 do
  32. if amount ~= 0 then
  33. amount = amount - 1
  34. end
  35. end
  36.  
  37. if amount ~= 0 then
  38. if where == "up" then
  39. return turtle.dropUp(amount)
  40. elseif where == "down" then
  41. return turtle.dropDown(amount)
  42. else
  43. return turtle.drop(amount)
  44. end
  45. else
  46. return false
  47. end
  48. end
  49.  
  50. function chestArea()
  51.  
  52. for i = 5, 16 do
  53. dropContainer(i, turtle.getItemCount(i), "down")
  54. end
  55. turtle.select(3)
  56. while not turtle.compare() do
  57. turtle.turnRight()
  58. end
  59. turtle.select(1)
  60. if turtle.getItemCount(1) <= 20 then
  61. turtle.suck(40)
  62. end
  63. turtle.select(4)
  64. if turtle.getItemCount(4) <= 20 then
  65. turtle.suck(40)
  66. end
  67. turtle.turnRight()
  68. if not turtle.detect() then
  69. while turtle.getItemCount() == 1 do
  70. print("Plus de sapling !")
  71. sleep(10)
  72. print("Go remettre des saplings !")
  73. end
  74. turtle.place()
  75. end
  76. turtle.turnRight()
  77. turtle.turnRight()
  78. if not turtle.detect() then
  79. while turtle.getItemCount() == 1 do
  80. print("Plus de sapling !")
  81. sleep(10)
  82. print("Go remettre des saplings !")
  83. end
  84. turtle.place()
  85. end
  86. turtle.select(2)
  87. while not turtle.compare() do
  88. sleep(5)
  89. turtle.turnRight()
  90. turtle.turnRight()
  91. end
  92. end
  93.  
  94. function checkWood()
  95.  
  96. nTurn = 0
  97.  
  98. while not turtle.compare() do
  99.  
  100. if nTurn == 4 then
  101.  
  102. if not turtle.detectUp() and digLeaf then
  103.  
  104. saveRoutinePosition("reset")
  105. turtle.select(3)
  106. while not turtle.compareDown() do
  107. if turtle.detectDown() and not turtle.compareDown() then
  108. turtle.digDown()
  109. end
  110. turtle.down()
  111. end
  112.  
  113. saveRoutinePosition("chestArea")
  114. chestArea()
  115. break
  116. else
  117. turtle.up()
  118. break
  119. end
  120.  
  121. end
  122. turtle.turnRight()
  123. nTurn = nTurn + 1
  124.  
  125. end
  126.  
  127. end
  128.  
  129. refuel()
  130.  
  131. if fs.exists("Data") then
  132. if readRoutine() == "checkWoodLeafDig" then
  133. ready = true
  134. digLeaf = true
  135. end
  136. if readRoutine() == "" then
  137. saveRoutinePosition("chestArea")
  138. end
  139. else
  140. saveRoutinePosition("chestArea")
  141. end
  142.  
  143. while true do
  144.  
  145. while ready do
  146.  
  147. --Dig wood
  148. turtle.select(2)
  149. if not turtle.compare() then
  150. checkWood()
  151. if not digLeaf then
  152. saveRoutinePosition("checkWoodLeafNoDig")
  153. else
  154. saveRoutinePosition("checkWoodLeafDig")
  155. end
  156. else
  157. turtle.dig()
  158. turtle.turnRight()
  159. turtle.turnRight()
  160. if turtle.compare() then
  161. turtle.dig()
  162. end
  163. if turtle.digUp() then
  164. saveRoutinePosition("digUp")
  165. digLeaf = true
  166. end
  167. turtle.up()
  168. if not digLeaf then
  169. saveRoutinePosition("checkWoodLeafNoDig")
  170. else
  171. saveRoutinePosition("checkWoodLeafDig")
  172. end
  173. end
  174.  
  175. end
  176.  
  177. if not ready and readRoutine() == "reset" then
  178.  
  179. turtle.select(3)
  180. while not turtle.compareDown() do
  181. if turtle.detectDown() and not turtle.compareDown() then
  182. turtle.digDown()
  183. end
  184. turtle.down()
  185. end
  186. saveRoutinePosition("chestArea")
  187. chestArea()
  188. ready = true
  189. end
  190.  
  191. if not ready and readRoutine() == "chestArea" then
  192. chestArea()
  193. ready = true
  194. end
  195.  
  196. if not ready and readRoutine() == "digUp" then
  197. turtle.up()
  198. ready = true
  199. end
  200.  
  201. if not ready and readRoutine() == "checkWoodLeafNoDig" then
  202. turtle.up()
  203. ready = true
  204. end
  205.  
  206. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement