Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 KB | None | 0 0
  1. --put coal in slot 1 and what to not mine in slot 2. 3 is another not mine.
  2. --so coal, cobble, smooth
  3.  
  4.  
  5.  
  6. x = 0
  7. y = 0
  8. z = 0
  9. --Facing direction start with 1 being 90 degrees left. 2 is backwards etc.
  10. --By convention we will always face 0 when not doing something.
  11. --We will take this to be right.
  12. facing = 0
  13.  
  14. oldX = 0
  15. oldY = 0
  16. oldZ = 0
  17.  
  18. hundredStepsCount = 0
  19.  
  20. function eachStep()
  21.  
  22.  
  23. if z >= oldZ then --we did not just move down
  24. turtle.select(2)
  25. if not turtle.compareUp() then
  26. turtle.select(3)
  27. if not turtle.compareUp() then
  28. turtle.digUp()
  29. end
  30. end
  31. end
  32.  
  33. if z <= oldZ then --we did not just move up
  34. turtle.select(2)
  35. if not turtle.compareDown() then
  36. turtle.select(3)
  37. if not turtle.compareDown() then
  38. turtle.digDown()
  39. end
  40. end
  41. end
  42.  
  43. turtle.select(2)
  44. if not turtle.compare() then
  45. turtle.select(3)
  46. if not turtle.compare() then
  47. turtle.dig()
  48. end
  49. end
  50.  
  51. --refuel and drop cobble every now and then. Doing this often slows it down
  52. if hundredStepsCount == 0 then
  53.  
  54. for i = 4, 16 do
  55. turtle.select(i)
  56. if turtle.compareTo(2) then
  57. turtle.drop()
  58. end
  59. end
  60.  
  61. if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 201 then
  62. turtle.select(1)
  63. if turtle.getItemCount() > 5 then
  64. turtle.refuel(5)
  65. end
  66. end
  67.  
  68. end
  69.  
  70.  
  71. hundredStepsCount = hundredStepsCount + 1
  72. if hundredStepsCount == 101 then
  73. hundredStepsCount = 0
  74. end
  75.  
  76.  
  77. oldX = x
  78. oldY = y
  79. oldZ = z
  80. end
  81.  
  82.  
  83.  
  84.  
  85.  
  86. function turnLeft()
  87. facing = facing - 1
  88. if facing < 0 then
  89. facing = facing + 4
  90. end
  91. turtle.turnLeft()
  92. end
  93.  
  94. function turnRight()
  95. facing = facing + 1
  96. if facing > 3 then
  97. facing = facing - 4
  98. end
  99. turtle.turnRight()
  100. end
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. function faceXLeft()
  108. if facing == 0 then
  109. turnLeft()
  110. turnLeft()
  111. elseif facing == 1 then
  112. turnRight()
  113. elseif facing == 2 then
  114. return
  115. elseif facing == 3 then
  116. turnLeft()
  117. end
  118. end
  119.  
  120. function faceXRight()
  121. if facing == 0 then
  122. return
  123. elseif facing == 1 then
  124. turnLeft()
  125. elseif facing == 2 then
  126. turnLeft()
  127. turnLeft()
  128. elseif facing == 3 then
  129. turnRight()
  130. end
  131. end
  132.  
  133. function faceYUp()
  134. if facing == 0 then
  135. turnLeft()
  136. elseif facing == 1 then
  137. turnLeft()
  138. turnLeft()
  139. elseif facing == 2 then
  140. turnRight()
  141. elseif facing == 3 then
  142. return
  143. end
  144. end
  145.  
  146. function faceYDown()
  147. if facing == 0 then
  148. turnRight()
  149. elseif facing == 1 then
  150. return
  151. elseif facing == 2 then
  152. turnLeft()
  153. elseif facing == 3 then
  154. turnLeft()
  155. turnLeft()
  156. end
  157. end
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164. function zUp()
  165. while turtle.detectUp() do
  166. while not turtle.digUp() do
  167. --loop
  168. end
  169. end
  170. while not turtle.up() do
  171. turtle.digUp()
  172. end
  173. z = z + 1
  174. eachStep()
  175. end
  176.  
  177. function zDown()
  178. while turtle.detectDown() do
  179. while not turtle.digDown() do
  180. --loop
  181. end
  182. end
  183. while not turtle.down() do
  184. turtle.digDown()
  185. end
  186. z = z - 1
  187. eachStep()
  188. end
  189.  
  190. function xLeft()
  191. faceXLeft()
  192. while turtle.detect() do
  193. while not turtle.dig() do
  194. --loop
  195. end
  196. end
  197. while not turtle.forward() do
  198. turtle.dig()
  199. end
  200. x = x - 1
  201. eachStep()
  202. end
  203.  
  204. function xRight()
  205. faceXRight()
  206. while turtle.detect() do
  207. while not turtle.dig() do
  208. --loop
  209. end
  210. end
  211. while not turtle.forward() do
  212. turtle.dig()
  213. end
  214. x = x + 1
  215. eachStep()
  216. end
  217.  
  218. function yUp()
  219. faceYUp()
  220. while turtle.detect() do
  221. while not turtle.dig() do
  222. --loop
  223. end
  224. end
  225. while not turtle.forward() do
  226. turtle.dig()
  227. end
  228. y = y + 1
  229. eachStep()
  230. end
  231.  
  232. function yDown()
  233. faceYDown()
  234. while turtle.detect() do
  235. while not turtle.dig() do
  236. --loop
  237. end
  238. end
  239. while not turtle.forward() do
  240. turtle.dig()
  241. end
  242. y = y - 1
  243. eachStep()
  244. end
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253. function zUpIsBlock()
  254. return turtle.detectUp()
  255. end
  256.  
  257. function zDownIsBlock()
  258. return turtle.detectDown()
  259. end
  260.  
  261. function xLeftIsBlock()
  262. faceXLeft()
  263. return turtle.detect()
  264. end
  265.  
  266. function xRightIsBlock()
  267. faceXRight()
  268. return turtle.detect()
  269. end
  270.  
  271. function yUpIsBlock()
  272. faceYUp()
  273. return turtle.detect()
  274. end
  275.  
  276. function yDownIsBlock()
  277. faceYDown()
  278. return turtle.detect()
  279. end
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288. --find direction to start
  289. while turtle.detect() do
  290. turtle.turnLeft()
  291. end
  292. facing = 0
  293. --we're assumed to now be facing to the right
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301. --Now well get the params from the spacing.
  302. --Its just a box. We assume to be on x center and edge on y and z.
  303. --First we get to and edge
  304.  
  305. while not xRightIsBlock() do
  306. xRight()
  307. end
  308.  
  309. --Now at right end
  310. maxX = x
  311.  
  312.  
  313.  
  314. while not xLeftIsBlock() do
  315. xLeft()
  316. end
  317.  
  318. minX = x
  319.  
  320. --Now we in top left
  321.  
  322.  
  323. minZ = 0
  324. maxZ = 10
  325.  
  326. --square
  327. minY = -(maxX - minX)
  328. maxY = y
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335. --start (from top left)
  336. --We are on the minX and minY in top left
  337.  
  338. while y > minY do
  339.  
  340. while x < maxX do
  341. --Mine from far left to right
  342.  
  343. if z == minZ then
  344. while z < maxZ do
  345. zUp()
  346. end
  347. else
  348. while z > minZ do
  349. zDown()
  350. end
  351. end
  352.  
  353. xRight()
  354.  
  355. end
  356. --now at far right
  357.  
  358. if z == minZ then
  359. while z < maxZ do
  360. zUp()
  361. end
  362. else
  363. while z > minZ do
  364. zDown()
  365. end
  366. end
  367.  
  368. yDown()
  369.  
  370.  
  371.  
  372. if y == minY then
  373. break
  374. end
  375.  
  376. while x > minX do
  377. --Mine from far right to left
  378.  
  379. if z == minZ then
  380. while z < maxZ do
  381. zUp()
  382. end
  383. else
  384. while z > minZ do
  385. zDown()
  386. end
  387. end
  388.  
  389. xLeft()
  390. end
  391.  
  392. if z == minZ then
  393. while z < maxZ do
  394. zUp()
  395. end
  396. else
  397. while z > minZ do
  398. zDown()
  399. end
  400. end
  401.  
  402. --now on far left
  403. yDown()
  404.  
  405. end
  406.  
  407. while z > minZ do
  408. zDown()
  409. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement