Advertisement
Melodicolt

Untitled

Aug 2nd, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. local direction = 0
  2.  
  3. function refuelTurtle()
  4. if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 50 then
  5. local fuelCounter = 0
  6. for i = 1, 16 do
  7. if turtle.getItemCount(i) > 0 then
  8. local data = turtle.getItemDetail(i)
  9. if data.name == "minecraft:coal" then
  10. turtle.select(i)
  11. if turtle.refuel() then
  12. print("Refueled...")
  13. else
  14. print("For some reason I found fuel but I couldn't load it, master...")
  15. end
  16. end
  17. else
  18. fuelCounter = fuelCounter + 1
  19. end
  20. end
  21. if fuelCounter == 16 then
  22. print("I'm all out of fuel, master...")
  23. fuelCounter = 0
  24. end
  25. else
  26. print("Refueling unnecessary...")
  27. end
  28. end
  29.  
  30. function checkInventory()
  31. local emptyInvSlots = 0
  32. for i = 1, 16 do
  33. if turtle.getItemCount(i) == 0 then
  34. emptyInvSlots = emptyInvSlots + 1
  35. end
  36. end
  37. if emptyInvSlots == 0 then
  38. print("My inventory is full, master...")
  39. emptyInvSlots = 0
  40. else
  41. print("Still ", emptyInvSlots, " empty inventory slots remaining...")
  42. emptyInvSlots = 0
  43. end
  44. end
  45.  
  46. function move()
  47. refuelTurtle()
  48. checkInventory()
  49. if turtle.forward() then
  50. print("1..2..1..2..")
  51. else
  52. print("I'm stuck, master...")
  53. end
  54. findTree()
  55. end
  56.  
  57. function moveAround()
  58. turtle.turnRight()
  59. if turtle.forward() then
  60. moveRight()
  61. else
  62. turtle.turnLeft()
  63. moveLeft()
  64. end
  65. end
  66.  
  67. function moveRight()
  68. turtle.turnLeft()
  69. if turtle.forward() then
  70. if turtle.forward() then
  71. turtle.turnLeft()
  72. if turtle.forward() then
  73. turtle.turnRight()
  74. print("I moved around the tree.")
  75. move()
  76. else
  77. print("Couldn't go right, trying left...")
  78. turtle.turnLeft()
  79. turtle.forward()
  80. turtle.forward()
  81. turtle.turnRight()
  82. turtle.forward()
  83. turtle.turnRight()
  84. moveLeft()
  85. end
  86. else
  87. print("Couldn't go right, trying left...")
  88. turtle.turnLeft()
  89. turtle.turnLeft()
  90. turtle.forward()
  91. turtle.turnRight()
  92. turtle.forward()
  93. turtle.turnRight()
  94. moveLeft()
  95. end
  96. else
  97. print("Couldn't go right, trying left...")
  98. turtle.turnLeft()
  99. turtle.forward()
  100. turtle.turnRight()
  101. moveLeft()
  102. end
  103. end
  104.  
  105. function moveLeft()
  106. turtle.turnLeft()
  107. if turtle.forward() then
  108. turtle.turnRight()
  109. if turtle.forward() then
  110. if turtle.forward() then
  111. turtle.turnRight()
  112. if turtle.forward() then
  113. turtle.turnLeft()
  114. print("I moved around the tree.")
  115. move()
  116. else
  117. print("I'm seriously stuck, master...")
  118. end
  119. else
  120. print("I'm seriously stuck, master...")
  121. end
  122. else
  123. print("I'm seriously stuck, master...")
  124. end
  125. else
  126. print("I'm seriously stuck, master...")
  127. end
  128. end
  129.  
  130. function findTree()
  131. local success, data = turtle.inspect()
  132. if success then
  133. if data.name == "minecraft:log" then
  134. cut()
  135. elseif data.name == "minecraft:fence" then
  136. if direction == 0 then
  137. turtle.turnRight()
  138. if turtle.forward() then
  139. turtle.turnRight()
  140. direction = 1
  141. move()
  142. else
  143. print("Couldn't turn right, trying left...")
  144. turtle.turnLeft()
  145. turtle.turnLeft()
  146. if turtle.forward() then
  147. turtle.turnLeft()
  148. move()
  149. else
  150. print("Couldn't turn left either, so I'm stuck, master...")
  151. end
  152. end
  153. elseif direction == 1 then
  154. turtle.turnLeft()
  155. if turtle.forward() then
  156. turtle.turnLeft()
  157. direction = 0
  158. move()
  159. else
  160. print("Couldn't turn left, trying right...")
  161. turtle.turnRight()
  162. turtle.turnRight()
  163. if turtle.forward() then
  164. turtle.turnRight()
  165. move()
  166. else
  167. print("Couldn't turn right either, so I'm stuck, master...")
  168. end
  169. end
  170. else
  171. print("I've lost my way, master...")
  172. end
  173. else
  174. moveAround()
  175. end
  176. else
  177. move()
  178. end
  179. print(direction)
  180. end
  181.  
  182. function cut()
  183. local movesUp = 0
  184. local success, data = turtle.inspect()
  185. while success do
  186. success, data = turtle.inspect()
  187. if localData.name == "minecraft:log" then
  188. turtle.dig()
  189. turtle.digUp()
  190. turtle.up()
  191. movesUp = movesUp + 1
  192. print("Cutting the log")
  193. end
  194. print("Looping...")
  195. end
  196. print("Done cutting the tree")
  197. for i = 1, movesUp do
  198. turtle.down()
  199. print("Moving down again...")
  200. end
  201. if turtle.forward() then
  202. if turtle.forward() then
  203. turtle.turnLeft()
  204. turtle.turnLeft()
  205. placeSapling()
  206. else
  207. print("Couldn't move forward, master...")
  208. end
  209. else
  210. print("Couldn't move forward, master...")
  211. end
  212. end
  213.  
  214. function placeSapling()
  215. for i = 1, 16 do
  216. if turtle.getItemCount(i) > 0 then
  217. local data = turtle.getItemDetail(i)
  218. if data.name == "minecraft:sapling" then
  219. turtle.select(i)
  220. turtle.place()
  221. turtle.turnLeft()
  222. turtle.turnLeft()
  223. move()
  224. end
  225. end
  226. end
  227. end
  228.  
  229. move()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement