Guest User

Untitled

a guest
Dec 9th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. --declaring variables
  2. turtdir = 0
  3. glowy = 0
  4. glowx = 0
  5. print "This will mine a predefined pattern of blocks. Use after vertshaft or stairshaft."
  6. print "All values are positive integers."
  7. print "Fuel in slot 16, torches in slot 15."
  8. print "How wide is this mine?(x) !MUST BE AN ODD NUMBER!"
  9. x = io.read()
  10. x = tonumber(x)
  11. print "How far forward? (y)"
  12. y = io.read()
  13. y = tonumber(y)
  14. y = y-1
  15. print "How high? (z)"
  16. z = io.read()
  17. z = tonumber(z)
  18. z = z-1
  19. print "Press any key to run."
  20. os.pullEvent("char")
  21. -- origins
  22. sxo = x/2
  23. sxo = math.ceil(sxo)
  24. syo = y/2
  25. syo = math.ceil(syo)
  26. -- sxo and syo is used to find the turtle's start point. It is crucial that x be odd for this to work right.
  27. xo = 0
  28. yo = 0
  29. zo = 0
  30. setup = sxo/2
  31. setup = math.ceil(setup)
  32. -- declaring functions
  33. function checkFuel()
  34. if turtle.getFuelLevel() <= z*2+2 then
  35. turtle.select(16)
  36. turtle.refuel(1)
  37. end
  38. end
  39.  
  40. function moveForward()
  41. checkFuel()
  42. repeat
  43. turtle.dig()
  44. until turtle.forward()
  45. end
  46.  
  47. function mineUp()
  48. if zo == 0 then
  49. for i = 1,z do
  50. checkFuel()
  51. repeat
  52. turtle.digUp()
  53. until turtle.up()
  54. zo = zo+1
  55. end
  56. end
  57. end
  58.  
  59. function mineDown()
  60. if zo ~= 0 then
  61. repeat
  62. checkFuel()
  63. repeat
  64. turtle.digDown()
  65. until turtle.down()
  66. zo = zo-1
  67. until zo == 0
  68. end
  69. end
  70.  
  71. function checka()
  72. if turtle.getItemCount(14) >= 1 then
  73. turtle.turnLeft()
  74. for i = 1,yo do
  75. moveForward()
  76. checkFuel()
  77. end
  78. for i = 1,14 do
  79. turtle.select(i)
  80. turtle.drop()
  81. end
  82. turtle.turnLeft()
  83. turtle.turnLeft()
  84. for i = 1,yo do
  85. moveForward()
  86. checkFuel()
  87. end
  88. turtle.turnLeft()
  89. turtle.select(1)
  90. end
  91. end
  92.  
  93. function checkb()
  94. if turtle.getItemCount(14) >= 1 then
  95. turtle.turnRight()
  96. for i = 1,yo do
  97. moveForward()
  98. checkFuel()
  99. end
  100. for i = 1,14 do
  101. turtle.select(i)
  102. turtle.drop()
  103. end
  104. turtle.turnLeft()
  105. turtle.turnLeft()
  106. for i = 1,yo do
  107. moveForward()
  108. checkFuel()
  109. end
  110. turtle.turnRight()
  111. turtle.select(1)
  112. end
  113. end
  114.  
  115. function torch()
  116. if glowx > 6 or glowx < 0 then
  117. glowx = 0
  118. end
  119. if glowy == 5 and glowx == 6 then
  120. turtle.turnLeft()
  121. turtle.turnLeft()
  122. turtle.select(15)
  123. turtle.place()
  124. turtle.turnRight()
  125. turtle.turnRight()
  126. glowx = glowx-glowx
  127. end
  128. end
  129.  
  130. -- setting up to align
  131. turtle.turnLeft()
  132. for i = 1,setup do
  133. mineUp()
  134. moveForward()
  135. mineDown()
  136. moveForward()
  137. end
  138. turtle.turnLeft()
  139. turtle.turnLeft()
  140. mineUp()
  141. mineDown()
  142. for i = 1,setup do
  143. moveForward()
  144. end
  145. for i = 1,setup do
  146. moveForward()
  147. mineUp()
  148. moveForward()
  149. mineDown()
  150. end
  151. -- and finally, on line 147, we have reached the main loop.
  152. for i = 1,syo do
  153. turtdir = 1
  154. checkb()
  155. turtle.turnLeft()
  156. moveForward()
  157. yo = yo+1
  158. if glowy == 6 then
  159. glowy = glowy-glowy
  160. end
  161. glowy = glowy+1
  162. turtle.turnLeft()
  163. for a = 1,sxo-1 do
  164. mineUp()
  165. moveForward()
  166. glowx = glowx+1
  167. xo = xo+1
  168. mineDown()
  169. moveForward()
  170. xo = xo+1
  171. glowx = glowx+1
  172. torch()
  173. end
  174. turtdir = 2
  175. checka()
  176. turtle.turnRight()
  177. mineUp()
  178. mineDown()
  179. moveForward()
  180. yo = yo+1
  181. if glowy == 6 then
  182. glowy = glowy-glowy
  183. end
  184. glowy = glowy+1
  185. turtle.turnRight()
  186. for b = 1,sxo-1 do
  187. mineUp()
  188. moveForward()
  189. xo = xo-1
  190. glowx = glowx-1
  191. mineDown()
  192. moveForward()
  193. xo = xo-1
  194. glowx = glowx-1
  195. torch()
  196. end
  197. mineUp()
  198. mineDown()
  199. end
  200. if turtdir == 1 then
  201. turtle.turnLeft()
  202. for i = 1,yo do
  203. moveForward()
  204. checkFuel()
  205. end
  206. for i = 1,16 do
  207. turtle.select(i)
  208. turtle.drop()
  209. end
  210. end
  211. if turtdir == 2 then
  212. turtle.turnRight()
  213. for i = 1,yo do
  214. moveForward()
  215. checkFuel()
  216. end
  217. for i = 1,16 do
  218. turtle.select(i)
  219. turtle.drop()
  220. end
  221. end
Add Comment
Please, Sign In to add comment