Advertisement
HarvDad

qclear

Sep 21st, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. -- qclear - Use a quarry frame preparation to clear an area.
  2. -- This program places the landmarks and then waits for the user
  3. -- to enable the frame with a right-click.
  4. -- Then it waits for the user to place the quarry machine block.
  5. -- The user must then power the quarry to get it started.
  6. -- The turtle then breaks the quarry machine block as soon as
  7. -- the quarry frame appears.
  8.  
  9. -- Quarry land markers must be placed in slot 2
  10. -- At least 3 solid blocks (maybe dirt) must be placed in slot 3
  11.  
  12. -- Rev: 1.0
  13.  
  14. args = {...}
  15. nArgs = #args
  16.  
  17. height = 10
  18. length = 20
  19. width = 7
  20.  
  21. quarrySlot = 1
  22. markerSlot = 2
  23. blockSlot = 3
  24. conduitSlot = 4
  25.  
  26. x = 0
  27. y = 0
  28. z = 0
  29.  
  30. length = 0
  31. width = 0
  32. height = 0
  33.  
  34. goodToGo = true
  35.  
  36. function getArgs()
  37. result = true
  38.  
  39. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  40. print("Clear blocks from length, width, height")
  41. print("Place 4 quarry land markers in slot 2")
  42. print("Place 4 solid blocks (dirt?) in slot 3")
  43. print("Usage: qclear <length><width><height>")
  44. return false
  45. end
  46.  
  47. if nArgs ~= 3 then
  48. print("Usage: qclear <length><width><height>")
  49. return false
  50. end
  51.  
  52. length = tonumber(args[1])
  53. if length == nil then
  54. print("\"", args[1], "\" is not a valid length")
  55. return false
  56. end
  57. if length < 1 then
  58. print("length must be a positive number greater than zero")
  59. result = false
  60. end
  61.  
  62. width = tonumber(args[2])
  63. if width == nil then
  64. print("\"", args[2], "\" is not a valid width")
  65. return false
  66. end
  67. if width < 1 then
  68. print("width must be a positive number greater than zero")
  69. result = false
  70. end
  71.  
  72. height = tonumber(args[3])
  73. if height == nil then
  74. print("\"", args[3], "\" is not a valid height")
  75. return false
  76. end
  77.  
  78. return result
  79. end
  80.  
  81. function forward(nBlocks)
  82. for i=1,nBlocks do
  83. for j=1,10 do
  84. if turtle.forward() then
  85. break
  86. else
  87. turtle.dig()
  88. end
  89. end
  90. end
  91. end
  92.  
  93. function up(nBlocks)
  94. for i=1,nBlocks do
  95. for j=1,10 do
  96. if turtle.up() then
  97. break
  98. else
  99. turtle.digUp()
  100. end
  101. end
  102. y = y+1
  103. end
  104. end
  105.  
  106. function down(nBlocks)
  107. for i=1,nBlocks do
  108. for j=1,10 do
  109. if turtle.down() then
  110. break
  111. else
  112. turtle.digDown()
  113. end
  114. end
  115. y = y-1
  116. end
  117. end
  118.  
  119. function placeMarkers()
  120. turtle.turnLeft()
  121. forward(1)
  122. turtle.turnLeft()
  123. forward(1)
  124. turtle.turnLeft()
  125. turtle.turnLeft()
  126.  
  127. if not turtle.detectDown() then
  128. turtle.select(blockSlot)
  129. turtle.placeDown()
  130. end
  131. up(1)
  132. turtle.select(markerSlot)
  133. turtle.placeDown()
  134.  
  135. up(height-1)
  136. turtle.select(blockSlot)
  137. turtle.placeDown()
  138. up(1)
  139. turtle.select(markerSlot)
  140. turtle.placeDown()
  141.  
  142. forward(length+1)
  143. while y > 0 do
  144. down(1)
  145. end
  146. turtle.turnRight()
  147. forward(1)
  148. placeLandMarker()
  149.  
  150. forward(width)
  151. turtle.turnRight()
  152.  
  153. forward(length+1)
  154. placeBlock()
  155. turtle.turnRight()
  156. forward(1)
  157. placeLandMarker()
  158. forward(width-1)
  159.  
  160. turtle.turnRight()
  161. -- turtle.forward(1)
  162.  
  163. end
  164.  
  165. function placeBlock()
  166. turtle.select(blockSlot)
  167. turtle.placeDown()
  168. end
  169.  
  170. function placeLandMarker()
  171. turtle.turnLeft()
  172. turtle.turnLeft()
  173. turtle.select(markerSlot)
  174. turtle.place()
  175. turtle.turnLeft()
  176. turtle.turnLeft()
  177. end
  178.  
  179. function prep()
  180. for i=1,height do
  181. turtle.up()
  182. end
  183.  
  184. placeLandMarker()
  185.  
  186. for i=1,length do
  187. turtle.dig()
  188. turtle.forward()
  189. x = x+1
  190. end
  191.  
  192. placeLandMarker()
  193. x = x-1
  194.  
  195. while x > 0 do
  196. turtle.back()
  197. x = x-1
  198. end
  199.  
  200. turtle.turnRight()
  201.  
  202. for i=1,width do
  203. turtle.dig()
  204. turtle.forward()
  205. z = z+1
  206. end
  207.  
  208. placeLandMarker()
  209. z = z-1
  210.  
  211. while z > 0 do
  212. turtle.back()
  213. z = z-1
  214. end
  215. end
  216.  
  217. function waitForQuarryBlock()
  218. turtle.turnLeft()
  219. turtle.turnLeft()
  220. forward(1)
  221. turtle.turnRight()
  222. turtle.dig()
  223. turtle.select(quarrySlot)
  224.  
  225. while not turtle.detect() do
  226. sleep(0)
  227. end
  228. turtle.turnRight()
  229. end
  230.  
  231. function waitForQuarryFrame()
  232. while not turtle.detect() do
  233. sleep(0)
  234. end
  235. end
  236.  
  237. if getArgs() == goodToGo then
  238. placeMarkers()
  239. print("Waiting for quarry block to be placed...")
  240. waitForQuarryBlock()
  241. print("Waiting for quarry frame to form...")
  242. waitForQuarryFrame()
  243. turtle.turnLeft()
  244. turtle.dig()
  245. turtle.turnRight()
  246. print("Quarry has been decommissioned.")
  247. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement