Advertisement
Melodicolt

Untitled

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