Advertisement
Guest User

ttturtle

a guest
Oct 26th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. pX = 0
  2. pZ = 0
  3. pY = 0
  4.  
  5. dX = 0
  6. dZ = 0
  7. dY = 0
  8.  
  9. oX = 1 --Assume the turtle is set on the X axis at start
  10. oZ = 0
  11.  
  12. tX = 1
  13. tZ = 0
  14.  
  15. mineWidth = 10
  16. mineLenght = 3
  17.  
  18. running = true
  19. debug = true
  20.  
  21. debug = false
  22.  
  23. function main()
  24. for i = 0, mineWidth do
  25.  
  26. refuel()
  27.  
  28. while pX < mineLenght do
  29. moveForward()
  30. inspectUp()
  31. inspectDown()
  32. turnRight()
  33. inspect()
  34. turnRight()
  35. turnRight()
  36. inspect()
  37. turnRight()
  38. end
  39.  
  40. moveUp()
  41. moveUp()
  42. moveUp()
  43. turnRight()
  44. turnRight()
  45.  
  46. refuel()
  47.  
  48. while pX > 0 do
  49. moveForward()
  50. inspectUp()
  51. inspectDown()
  52. turnRight()
  53. inspect()
  54. turnRight()
  55. turnRight()
  56. inspect()
  57. turnRight()
  58. end
  59.  
  60. turnRight()
  61. moveForward()
  62. moveForward()
  63. moveDown()
  64. turnRight()
  65.  
  66. refuel()
  67.  
  68. while pX < mineLenght do
  69. moveForward()
  70. inspectUp()
  71. inspectDown()
  72. turnRight()
  73. inspect()
  74. turnRight()
  75. turnRight()
  76. inspect()
  77. turnRight()
  78. end
  79.  
  80. turnRight()
  81. turnRight()
  82. moveDown()
  83.  
  84. refuel()
  85.  
  86. while pX > 0 do
  87. moveForward()
  88. inspectUp()
  89. inspectDown()
  90. turnRight()
  91. inspect()
  92. turnRight()
  93. turnRight()
  94. inspect()
  95. turnRight()
  96. end
  97.  
  98. turnRight()
  99. moveForward()
  100. moveForward()
  101. moveDown()
  102. turnRight()
  103. end
  104. end
  105.  
  106. function refuel()
  107. fuelLevel = turtle.getFuelLevel()
  108.  
  109. if(fuelLevel < 1000) then
  110. for slot = 1,16 do
  111. turtle.select(slot)
  112. if turtle.refuel(1) then
  113. return true
  114. end
  115. end
  116. else
  117. --goHome()
  118. --shutDown()
  119. end
  120. end
  121.  
  122. function inspect()
  123. if debug then
  124. print ("Position : "..pX.." "..pZ.." "..pY)
  125. print ("Orientation: "..oX.." "..oZ)
  126. end
  127. success,material = turtle.inspect()
  128. if material.name ~= "minecraft:stone" and material.name ~= "minecraft:dirt" then
  129. turtle.dig()
  130. end
  131. end
  132.  
  133. function inspectUp()
  134. success,material = turtle.inspectUp()
  135. if material.name ~= "minecraft:stone" and material.name ~= "minecraft:dirt" then
  136. turtle.digUp()
  137. end
  138. end
  139.  
  140. function inspectDown()
  141. success,material = turtle.inspectDown()
  142. if material.name ~= "minecraft:stone" and material.name ~= "minecraft:dirt" then
  143. turtle.digDown()
  144. end
  145. end
  146.  
  147. function drop()
  148. dZ = pZ
  149. while pZ ~= 0 do
  150. if oX == 1 then
  151. turtle.turnRight()
  152. elseif oX == -1 then
  153. turtle.turnLeft()
  154. end
  155.  
  156. if oZ == 1 then
  157. turnRight()
  158. turnRight()
  159. else
  160. moveForward()
  161. end
  162. end
  163.  
  164. for i = 2,16 do
  165. turtle.select(i)
  166. turtle.dropDown()
  167. end
  168.  
  169. turnRight()
  170. turnRight()
  171.  
  172. while dZ ~= 0 do
  173. if oX == 1 then
  174. turtle.turnRight()
  175. elseif oX == -1 then
  176. turtle.turnLeft()
  177. elseif oZ == 1 then
  178. turnRight()
  179. turnRight()
  180. else
  181. moveForward()
  182. end
  183. end
  184. end
  185.  
  186. function moveForward()
  187. if debug then
  188. print ("Position : "..pX.." "..pZ.." "..pY)
  189. print ("Orientation: "..oX.." "..oZ)
  190. end
  191. if turtle.forward() then
  192. if oX == 1 then
  193. pX = pX + 1
  194. elseif oX == -1 then
  195. pX = pX - 1
  196. elseif oZ == 1 then
  197. pZ = pZ + 1
  198. else
  199. pZ = pZ - 1
  200. end
  201. else
  202. turtle.dig()
  203. turtle.forward()
  204. if oX == 1 then
  205. pX = pX + 1
  206. elseif oX == -1 then
  207. pX = pX - 1
  208. elseif oZ == 1 then
  209. pZ = pZ + 1
  210. else
  211. pZ = pZ - 1
  212. end
  213. end
  214. end
  215.  
  216. function moveUp()
  217. if debug then
  218. print ("Position : "..pX.." "..pZ.." "..pY)
  219. print ("Orientation: "..oX.." "..oZ)
  220. end
  221. if turtle.up() then
  222. pY = pY + 1
  223. else
  224. turtle.digUp()
  225. turtle.up()
  226. pY = pY + 1
  227. end
  228. end
  229.  
  230. function moveDown()
  231. if debug then
  232. print ("Position : "..pX.." "..pZ.." "..pY)
  233. print ("Orientation: "..oX.." "..oZ)
  234. end
  235. if turtle.down() then
  236. pY = pY - 1
  237. else
  238. turtle.digDown()
  239. turtle.down()
  240. pY = pY - 1
  241. end
  242. end
  243.  
  244. function goHome() --Return in X
  245. dZ = pZ
  246.  
  247. while dX ~= 0 do
  248. if dX > 0 then
  249. if oX == 1 then
  250. turnRight()
  251. turnRight()
  252. elseif oX == -1 then
  253. moveForward()
  254. else
  255. turnRight()
  256. end
  257. else
  258. if oX == 1 then
  259. moveForward()
  260. elseif oX == -1 then
  261. turnRight()
  262. turnRight()
  263. else
  264. turnLeft()
  265. end
  266. end
  267. end
  268.  
  269. while pZ ~= 0 do
  270. if dX > 0 then
  271. if oX == 1 then
  272. turnRight()
  273. turnRight()
  274. elseif oX == -1 then
  275. moveForward()
  276. else
  277. turnRight()
  278. end
  279. else
  280. if oX == 1 then
  281. moveForward()
  282. elseif oX == -1 then
  283. turnRight()
  284. turnRight()
  285. else
  286. turnLeft()
  287. end
  288. end
  289. end
  290.  
  291.  
  292. end
  293.  
  294. function shutDown()
  295. running = false
  296. end
  297.  
  298. function turnRight()
  299. turtle.turnRight()
  300. if oX == 1 then
  301. oX = 0
  302. oZ = -1
  303. elseif oX == -1 then
  304. oX = 0
  305. oZ = 1
  306. elseif oZ == 1 then
  307. oX = 1
  308. oZ = 0
  309. else
  310. oX = -1
  311. oZ = 0
  312. end
  313. end
  314.  
  315. function turnLeft()
  316. turtle.turnLeft()
  317. if oX == 1 then
  318. oX = 0
  319. oZ = 1
  320. elseif oX == -1 then
  321. oX = 0
  322. oZ = -1
  323. elseif oZ == 1 then
  324. oX = -1
  325. oZ = 0
  326. else
  327. oX = 1
  328. oZ = 0
  329. end
  330. end
  331.  
  332. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement