Advertisement
ardevlirn

Advanced smart wood farm

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