sinkir

lua turtle tree

Mar 13th, 2021 (edited)
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. left = function()
  2. return turtle.turnLeft()
  3. end
  4.  
  5. right = function()
  6. return turtle.turnRight()
  7. end
  8.  
  9. up = function()
  10. return turtle.up()
  11. end
  12.  
  13. down = function()
  14. return turtle.down()
  15. end
  16.  
  17. back = function()
  18. return turtle.back()
  19. end
  20.  
  21. go = function()
  22. return turtle.forward()
  23. end
  24.  
  25. fuel = function()
  26. return turtle.getFuelLevel()
  27. end
  28.  
  29. selectId = function(id)
  30. return turtle.select(id)
  31. end
  32.  
  33. countId = function(id)
  34. return turtle.getItemCount(id)
  35. end
  36.  
  37. moveId = function(id, nb)
  38. return turtle.transferTo(id, nb)
  39. end
  40.  
  41. -- --------------------------------------
  42.  
  43. sNameWood = ""
  44. sNameSappling = ""
  45.  
  46.  
  47. -- --------------------------------------
  48.  
  49. function testFuel()
  50.  
  51. if(fuel() < 50)then
  52. local stickSlot = isThereSticks()
  53. if(stickSlot)then
  54. selectId(stickSlot)
  55. turtle.refuel(countId(stickSlot))
  56. testFuel()
  57. else
  58. selectId(1)
  59. turtle.refuel(1)
  60. end
  61. end
  62. end
  63.  
  64. function isThereSticks()
  65. local continue = true
  66. local slot = 1
  67. while continue do
  68. if(countId(slot) > 0)then
  69. if(getName(slot) == "minecraft:stick") then
  70. return slot
  71. end
  72. end
  73.  
  74. slot = slot + 1
  75. if(slot > 16)then
  76. continue = false
  77. end
  78. end
  79. return false
  80. end
  81.  
  82.  
  83.  
  84. function init()
  85. if(countId(1)==0) then
  86. print('Besoin du block a couper en slot 1')
  87. return false
  88. end
  89. if(turtle.detectDown()==false)then
  90. print('Besoin d\'coffre en desous de ma possition')
  91. return false
  92. end
  93. if(countId(16)==0) then
  94. print('Besoin de slapping en slot 16 (Le dernier)')
  95. return false
  96. end
  97.  
  98. sNameWood = getName(1)
  99. sNameSappling = getName(16)
  100.  
  101. return true
  102. end
  103.  
  104. function getName(s)
  105. local tab = turtle.getItemDetail(s)
  106. return tab.name
  107. end
  108.  
  109.  
  110. function coupeArbre()
  111.  
  112. selectId(1)
  113.  
  114. turtle.dig()
  115. go()
  116.  
  117. while turtle.compareUp() do
  118. turtle.digUp()
  119. up()
  120. end
  121. while turtle.detectDown() == false do
  122. down()
  123. end
  124.  
  125. back()
  126. selectId(16)
  127. turtle.place()
  128.  
  129.  
  130. testFuel()
  131. optiInv()
  132.  
  133. end
  134.  
  135. function optiInv()
  136. local continue = true
  137. local slot = 1
  138. while continue do
  139. if(slot == 1)then
  140. if (countId(slot)>10) then
  141. selectId(slot)
  142. turtle.dropDown(countId(slot) - 10)
  143. end
  144. elseif(slot == 16)then
  145. if (countId(slot)>10) then
  146. selectId(slot)
  147. turtle.dropDown(countId(slot) - 10)
  148. end
  149. else
  150. if (countId(slot)>0) then
  151. selectId(slot)
  152. if(getName(slot) == sNameSappling)then
  153. turtle.transferTo(16, countId(slot))
  154. else
  155. turtle.dropDown(countId(slot))
  156. end
  157. end
  158. end
  159. slot = slot + 1
  160. if(slot > 16)then
  161. continue = false
  162. end
  163. end
  164. end
  165.  
  166.  
  167. stop=false
  168. if(init()==false) then
  169. stop=true
  170. end
  171. while(stop==false)do
  172.  
  173. selectId(1)
  174. if(turtle.compare()==true)then
  175. coupeArbre()
  176. else
  177. turtle.suck()
  178. turtle.suckUp()
  179. end
  180. sleep(5)
  181.  
  182. end
  183.  
  184. print('end')
  185.  
Add Comment
Please, Sign In to add comment