Advertisement
Melodicolt

Untitled

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