Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. x = 0
  2. y = 0
  3. z = 0
  4. --Facing direction start with 1 being 90 degrees left. 2 is backwards etc.
  5. --By convention we will always face 0 when not doing something.
  6. --We will take this to be right.
  7. facing = 0
  8.  
  9. function turnLeft()
  10. facing = facing - 1
  11. if facing < 0 then
  12. facing = facing + 4
  13. end
  14. turtle.turnLeft()
  15. end
  16.  
  17. function turnRight()
  18. facing = facing + 1
  19. if facing > 3 then
  20. facing = facing - 4
  21. end
  22. turtle.turnRight()
  23. end
  24.  
  25. function faceXLeft()
  26. if facing == 0 then
  27. turnLeft()
  28. turnLeft()
  29. elseif facing == 1 then
  30. turnRight()
  31. elseif facing == 2 then
  32. return
  33. elseif facing == 3 then
  34. turnLeft()
  35. end
  36. end
  37.  
  38. function faceXRight()
  39. if facing == 0 then
  40. return
  41. elseif facing == 1 then
  42. turnLeft()
  43. elseif facing == 2 then
  44. turnLeft()
  45. turnLeft()
  46. elseif facing == 3 then
  47. turnRight()
  48. end
  49. end
  50.  
  51. function faceYUp()
  52. if facing == 0 then
  53. turnLeft()
  54. elseif facing == 1 then
  55. turnLeft()
  56. turnLeft()
  57. elseif facing == 2 then
  58. turnRight()
  59. elseif facing == 3 then
  60. return
  61. end
  62. end
  63.  
  64. function faceYDown()
  65. if facing == 0 then
  66. turnRight()
  67. elseif facing == 1 then
  68. return
  69. elseif facing == 2 then
  70. turnLeft()
  71. elseif facing == 3 then
  72. turnLeft()
  73. turnLeft()
  74. end
  75. end
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. function zUp()
  83. while turtle.detectUp() do
  84. while not turtle.digUp() do
  85. --loop
  86. end
  87. end
  88. while not turtle.up() do
  89. turtle.digUp()
  90. end
  91. z = z + 1
  92. end
  93.  
  94. function zDown()
  95. while turtle.detectDown() do
  96. while not turtle.digDown() do
  97. --loop
  98. end
  99. end
  100. while not turtle.down() do
  101. turtle.digDown()
  102. end
  103. z = z - 1
  104. end
  105.  
  106. function xLeft()
  107. faceXLeft()
  108. while turtle.dig() do
  109. while not turtle.dig() do
  110. --loop
  111. end
  112. end
  113. while not turtle.forward() do
  114. turtle.dig()
  115. end
  116. x = x - 1
  117. end
  118.  
  119. function xRight()
  120. faceXRight()
  121. while turtle.detect() do
  122. while not turtle.dig() do
  123. --loop
  124. end
  125. end
  126. while not turtle.forward() do
  127. turtle.dig()
  128. end
  129. x = x + 1
  130. end
  131.  
  132. function yUp()
  133. faceYUp()
  134. while turtle.detect() do
  135. while not turtle.dig() do
  136. --loop
  137. end
  138. end
  139. while not turtle.forward() do
  140. turtle.dig()
  141. end
  142. y = y + 1
  143. end
  144.  
  145. function yDown()
  146. faceYDown()
  147. while turtle.detect() do
  148. while not turtle.dig() do
  149. --loop
  150. end
  151. end
  152. while not turtle.forward() do
  153. turtle.dig()
  154. end
  155. y = y - 1
  156. end
  157.  
  158.  
  159.  
  160.  
  161. function zUpIsBlock()
  162. return turtle.detectUp()
  163. end
  164.  
  165. function zDownIsBlock()
  166. return turtle.detectDown()
  167. end
  168.  
  169. function xLeftIsBlock()
  170. faceXLeft()
  171. return turtle.detect()
  172. end
  173.  
  174. function xRightIsBlock()
  175. faceXRight()
  176. return turtle.detect()
  177. end
  178.  
  179. function yUpIsBlock()
  180. faceYUp()
  181. return turtle.detect()
  182. end
  183.  
  184. function yDownIsBlock()
  185. faceYDown()
  186. return turtle.detect()
  187. end
  188.  
  189.  
  190.  
  191. --find direction to start
  192. while turtle.detect() do
  193. turtle.turnLeft()
  194. end
  195. facing = 0
  196. --we're assumed to now be facing to the right
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. --Now well get the params from the spacing.
  205. --Its just a box. We assume to be on x center and edge on y and z.
  206. --First we get to and edge
  207.  
  208. while not xRightIsBlock() do
  209. xRight()
  210. end
  211.  
  212. --Now at right end
  213. maxX = x
  214.  
  215.  
  216.  
  217. while not xLeftIsBlock() do
  218. xLeft()
  219. end
  220.  
  221. minX = x
  222.  
  223. --Now we in top left
  224.  
  225.  
  226. minZ = 0
  227. maxZ = 10
  228.  
  229. --square
  230. minY = -(maxX - minX)
  231. maxY = y
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238. --start (from top left)
  239. --We are on the minX and minY in top left
  240.  
  241. while y > minY do
  242.  
  243. while x < maxX do
  244. --Mine from far left to right
  245.  
  246. if z == minZ then
  247. while z < maxZ do
  248. zUp()
  249. end
  250. else
  251. while z > minZ do
  252. zDown()
  253. end
  254. end
  255.  
  256. xRight()
  257.  
  258. end
  259. --now at far right
  260. yDown()
  261.  
  262. if z == minZ then
  263. while z < maxZ do
  264. zUp()
  265. end
  266. else
  267. while z > minZ do
  268. zDown()
  269. end
  270. end
  271.  
  272. if y == minY then
  273. break
  274. end
  275.  
  276. while x > minX do
  277. --Mine from far right to left
  278.  
  279. if z == minZ then
  280. while z < maxZ do
  281. zUp()
  282. end
  283. else
  284. while z > minZ do
  285. zDown()
  286. end
  287. end
  288.  
  289. xLeft()
  290. end
  291.  
  292. --now on far left
  293. yDown()
  294.  
  295. end
  296.  
  297. while z > minZ do
  298. zDown()
  299. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement