Advertisement
ardevlirn

CC turtle smart wood farm

Jan 1st, 2020
2,795
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.85 KB | None | 0 0
  1. --smart adaptive wood farming turtle by Ardevlirn
  2. --Instruction:
  3. --Create a path using the block you will place in slot 13
  4. --place dirt around the path (only at the same Y pos than the path)
  5. --place turtle on the path
  6. --place a chest next to the turtle and the path
  7. ----------------------------------
  8. --put 1 chest in slot 16,
  9. --at least 3 sappling in slot 15
  10. --1 wood in slot 14,
  11. --the block used for the path in slot 13
  12. --fuel in slot 12, if fuel is disabled no need to put some
  13. --those next variable can be changed
  14. --(will say when no more variable can be changed):
  15. --Will try to refuel when Fuel Level is under this amount :
  16. local minFuelForRefuel = 800
  17. --Will search the chest if there is less than this amount of fuel item in inventory:
  18. local minFuelInInventory = 12
  19. --If set to true will search the chest when under this amount of sappling left in inventory :
  20. local goSearchSapling = false
  21. local minSaplingInInventory = 3
  22. --PS: While searching for the chest the turtle will no longer place saplingID
  23. --and will not cut tree down
  24. ----------------------------------
  25. --those variable define in which slot each item must be placed
  26. local chestSlot = 16
  27. local saplingSlot = 15
  28. local woodSlot = 14
  29. local pathSlot = 13
  30. local fuelSlot = 12
  31. --no more variable to change
  32. -------------------------------------------------------------
  33.  
  34. local function Energy()
  35. turtle.select(fuelSlot)
  36. if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < minFuelForRefuel then
  37. local charbonNumb = turtle.getItemCount()
  38. if charbonNumb > 12 then
  39. turtle.refuel(10)
  40. else
  41. turtle.refuel(charbonNumb-2)
  42. end
  43. end
  44. end
  45.  
  46. local function chemin()
  47. turtle.select(pathSlot)
  48. return turtle.compareDown()
  49. end
  50.  
  51. local function testbois()
  52. turtle.select(woodSlot)
  53. return turtle.compare()
  54. end
  55.  
  56. local function testpousse()
  57. turtle.select(saplingSlot)
  58. return turtle.compare()
  59. end
  60.  
  61. local function testcoffre()
  62. turtle.select(chestSlot)
  63. return turtle.compare()
  64. end
  65.  
  66. local function plante()
  67. turtle.select(saplingSlot)
  68. if turtle.getItemCount(saplingSlot) > 2 then
  69. turtle.place()
  70. end
  71. end
  72.  
  73. local function detectCoupe()
  74. local _, blockUp = turtle.inspectUp()
  75. if blockUp.name == "minecraft:log" or blockUp.name == "minecraft:leaves" then
  76. return true
  77. else
  78. return false
  79. end
  80. end
  81.  
  82. local function preventStuck()
  83. local success,data = turtle.inspectDown()
  84. if data.name == "minecraft:log" or data.name == "minecraft:leaves" then
  85. return true
  86. else
  87. return false
  88. end
  89. end
  90.  
  91. local function coupe()
  92. turtle.select(woodSlot)
  93. turtle.dig()
  94. turtle.forward()
  95. while detectCoupe() do
  96. turtle.digUp()
  97. turtle.up()
  98. for i=0,3 do
  99. if turtle.detect() then
  100. if testbois() then
  101.  
  102. else
  103. turtle.dig()
  104. end
  105. end
  106. turtle.turnRight()
  107. end
  108. end
  109. if not turtle.back() then
  110. turtle.turnRight()
  111. turtle.turnRight()
  112. turtle.dig()
  113. turtle.forward()
  114. turtle.turnRight()
  115. turtle.turnRight()
  116. end
  117. while not chemin() do
  118. if preventStuck() then
  119. turtle.digDown()
  120. end
  121. turtle.down()
  122. end
  123. plante()
  124. turtle.suck()
  125. end
  126.  
  127. local function vide(itemID)
  128. local selecteddItem = 0
  129. for slot = 1,11 do
  130. turtle.select(slot)
  131. selecteddItem = turtle.getItemDetail()
  132. if itemID and selecteddItem then
  133. if selecteddItem.name == itemID then
  134. turtle.drop()
  135. end
  136. else
  137. turtle.drop()
  138. end
  139. end
  140. end
  141.  
  142. local function provision()
  143. vide()
  144. for i=1,16 do
  145. turtle.select(i)
  146. turtle.suck()
  147. end
  148. vide()
  149. end
  150.  
  151. local function gocoffre()
  152. local foundChest = false
  153. while foundChest ~= true do
  154. for i=0,3 do
  155. if testcoffre() then
  156. foundChest = true
  157. break
  158. else
  159. turtle.turnRight()
  160. end
  161. end
  162. if foundChest ~= true then
  163. turtle.turnLeft()
  164. for i=0,3 do
  165. Energy()
  166. if turtle.forward() then
  167. if chemin() then
  168. break
  169. else
  170. Energy()
  171. turtle.back()
  172. turtle.turnRight()
  173. end
  174. else
  175. turtle.turnRight()
  176. end
  177. end
  178. end
  179. end
  180. provision()
  181. end
  182. --turtle script made by Ardevlirn
  183. local function settingUp()
  184. --gocoffre()
  185. while turtle.detectDown() ~= true or preventStuck() do
  186. Energy()
  187. if preventStuck() then
  188. turtle.digDown()
  189. end
  190. turtle.down()
  191. end
  192. local didMove = false
  193. while chemin() ~= true do
  194. if turtle.back() then
  195. didMove = true
  196. end
  197. if chemin() ~= true then
  198. if didMove then
  199. turtle.forward()
  200. end
  201. turtle.turnRight()
  202. end
  203. end
  204. end
  205.  
  206. local function start()
  207. local stop = false
  208. settingUp()
  209. while stop ~= true do
  210. Energy()
  211. for i=0,3 do
  212. if testcoffre() then
  213. provision()
  214. elseif testbois() then
  215. Energy()
  216. coupe()
  217. turtle.select(saplingSlot)
  218. turtle.suck()
  219. elseif testpousse() then
  220. turtle.select(saplingSlot)
  221. turtle.suck()
  222. Energy()
  223. else
  224. plante()
  225. turtle.select(saplingSlot)
  226. turtle.suck()
  227. end
  228. turtle.turnRight()
  229. end
  230. if turtle.getItemCount(11) ~= nil and turtle.getItemCount(11) >= 1 then
  231. gocoffre()
  232. end
  233. if turtle.getItemCount(saplingSlot) ~= nil and goSearchSapling == true and turtle.getItemCount(saplingSlot) <= minSaplingInInventory then
  234. local selecteddItem = 0
  235. turtle.select(saplingSlot)
  236. local saplingID = turtle.getItemDetail()
  237. for slot = 1,11 do
  238. turtle.select(slot)
  239. selecteddItem = turtle.getItemDetail()
  240. if saplingID and selecteddItem then
  241. if selecteddItem.name == saplingID.name then
  242. turtle.transferTo(saplingSlot,(64-saplingID.count))
  243. end
  244. end
  245. end
  246. if turtle.getItemCount(saplingSlot) ~= nil and turtle.getItemCount(saplingSlot) <= minSaplingInInventory then
  247. gocoffre()
  248. end
  249. end
  250. turtle.turnLeft()
  251. for i=0,3 do
  252. Energy()
  253. if turtle.forward() then
  254. if chemin() then
  255. break
  256. else
  257. Energy()
  258. turtle.back()
  259. turtle.turnRight()
  260. end
  261. else
  262. turtle.turnRight()
  263. end
  264. end
  265. if turtle.getFuelLevel() ~= "unlimited" and turtle.getItemCount(fuelSlot) ~= nil and turtle.getItemCount(fuelSlot) <= minFuelInInventory then
  266. local selecteddItem = 0
  267. turtle.select(fuelSlot)
  268. local fuelID = turtle.getItemDetail()
  269. for slot = 1,11 do
  270. turtle.select(slot)
  271. selecteddItem = turtle.getItemDetail()
  272. if fuelID and selecteddItem then
  273. if selecteddItem.name == fuelID.name then
  274. turtle.transferTo(fuelSlot,(64-fuelID.count))
  275. end
  276. end
  277. end
  278. if turtle.getItemCount(fuelSlot) ~= nil and turtle.getItemCount(fuelSlot) <= minFuelInInventory then
  279. gocoffre()
  280. end
  281. end
  282. end
  283. end
  284.  
  285. start()
Advertisement
Comments
  • mattywuu
    24 days
    # text 0.22 KB | 0 0
    1. This code worked yesterday yet now my turtle in a new world is just going around the track and not placeing any saplings even if I give it more or put some in the chest. Won't even brake any trees when they grow, whats going on?
Add Comment
Please, Sign In to add comment
Advertisement