# Updated Quarry

a guest
Nov 3rd, 2012
2,756
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. --TO DO:
2. --Maybe rednet statistics tracker that fires after every row.
3. --Maybe put coal in slot 16 check after every row
4.
5. --Version 2.1.4
6. --Directions: If you want, place a chest right behind where you place the turtle. It will place things here when its done
7. --Also, if auto-empty is on, it will always eject the things it has into the place where a chest is supposed to be, it just dosen't check for a chest
8.
9. --This is how many (theoretical) slots it will fill with cobble. e.g. 13 allows 13 slots for cobble (or other stack) and 2 slots for other things.
10. --Maximum here is 15 because 16 is for fuel
11. maxslots = 13
12. --If your job is bigger than it can carry (as defined by max slots) it will default to auto-empty
13. --Note: For counting to work properly, cobble or stone must be the first block it mines, or put a cobble in slot 1
14.
15. --Defining things
16. function screen(xPos,yPos)
17. term.clear()
18. term.setCursorPos(xPos,yPos)
19. end
20. function mine()
21. while turtle.forward() == false do
22. if turtle.dig() == false then
23. turtle.attack()
24. mined = mined - 1
25. end
26. mined = mined + 1
27. end
28. if Cdouble == 1 then
29. if turtle.digDown() == true then
30. mined = mined + 1
31. end
32. end
33. if Cdouble == 0 then
34. moved = moved + 1
35. else
36. moved = moved + 2
37. end
38. display()
39. end
40. function mineRow()
41. if cRows ~= 0 then
42. for length=1, x do
43. mine()
44. end
45. else
46. for length=1, x-1 do
47. mine()
48. end
49. end
50. cRows = cRows + 1
51. end
52. function display() --Run in Mine(), display information to the screen in a certain place
53. percent = math.ceil((moved/volume)*100)
54. term.setCursorPos(1,2)
55. term.clearLine()
56. print(mined)
57. term.setCursorPos(1,4)
58. term.clearLine()
59. print(percent.."%")
60. end
61.
62.
63. function count() --Done after every row of auto-empty and at end
64. slot = {}        --Detection of blocks code is 1: Cobble 2: Other Raw 3:Other
65. for i=1, 16 do
66. slot[i] = {}
67. end
68. sandCh = 0
69. stacks = {} --These two reset which slots have dirt/sand
70. slot[1][1] = 1 --Slot 1 is always cobble for ease of use
71. for i=2, 15 do --Checks each slot for cobble
72. turtle.select(i)
73. Ccobble = turtle.compareTo(1)
74. if Ccobble == true then
75. slot[i][1] = 1
76. end
77. end
78. for i=2, 15 do --Checks each slot for stacks, assumes sand or dirt
79. Cnum = turtle.getItemCount(i)
80. if Cnum >= Rcheck and slot [i][1] ~= 1 then
81. slot[i][1] = 2
82. table.insert(stacks, i)
83. sandCh = 1
84. end
85. end
86. for i=2, 15 do --Checks if other slots have sand or dirt
87. turtle.select(i)
88. if sandCh == 1 then--Checks if there is any sand/dirt
89. for a=1, #stacks do --Compares it to all known sand/dirt slots
90. Csand = turtle.compareTo(stacks[a])
91. if Csand == true then --If it is the same as any dirt/sand
92. slot[i][1] = 2
93. a = 20 --Breaks the for
94. end
95. end
96. end
97. end
98. for i=2, 15 do --Labels all slots not dirt or sand as
99. if slot[i][1] ~= 1 and slot[i][1] ~= 2 then
100. slot[i][1] = 3
101. end
102. end
103. for i=1, 15 do
104. slot[i][2] = turtle.getItemCount(i)
105. end
106. for i=1, 15 do
107. if slot[i][1] == 1 then
108. cobble = cobble + slot[i][2]
109. end
110. if slot[i][1] == 2 then
111. sand = sand + slot[i][2]
112. end
113. if slot[i][1] == 3 then
114. other = other + slot[i][2]
115. end
116. end
117. if turtle.getItemCount(1) == 1 then
118. cobble = cobble - 1
119. end
120. end
121.
122.
123. fuel = turtle.getFuelLevel()
124. slot = {}
125. for i=1, 16 do
126. slot[i] = {}
127. end
128. cobble = 0 -- These three are counts for materials
129. sand = 0
130. other = 0
131.
132. --Input Phase
133. screen(1,1)
134. print("----- Welcome to Quarry! -----")
135. print("")
136. --Dimensions of Hole
137. print("What dimensions?")
138. print("")
139. term.write("Length: ")
141.
142. term.write("Width: ")
144.
145. term.write("Height: ")
147.
148. if not y or y == 0 then
149. y = 4
150. end
151. if not x or x == 0 then
152. x = 3
153. end
154. if not z or z == 0 then
155. z = 3
156. end
157.
158. Cdouble = 0
159. --Check for if it can do doubles
160. if math.ceil(y/2) == y/2 then
161. Cdouble = 1
162. end
163.
164. volume = x*y*z
165. area = x*z
166.
167. if maxslots > 15 then
168. maxslots = 15
169. end
170. maxsize = maxslots*64
171. if Cdouble == 1 then
172. maxsize = maxsize/2
173. end
174.
175. empty = 0
176.
177.
178. --Checks if bigger than inventory: 832 blocks theoretical Assuming at least 2 are non-cobble
179. if volume > maxsize then
180. print("Job very big")
181. print("Auto-emptying on")
182. empty = 1
183. sleep(2)
184. else
185. print("Turn on auto-emptying? (Y/N)")
187. if ans == "y" or ans == "1" then
188. empty = 1
189. end
190. end
191. if area > maxsize then
192. print("Area too Large, please restart program")
193. sleep(5)
194. os.reboot()
195. end
196.
197. if area > 256 then
198. Rcheck = 32
199. else
200. Rcheck = area/4
201. end
202. if empty == 0 and volume > 256 then
203. Rcheck = 32
204. else
205. Rcheck = area/4
206. end
207.
208. --Getting Fuel
209. while fuel < volume do
210. print("Fuel Needed")
211. print("Put Fuel in Bottom Right")
212. print("Press any key when placed")
213. os.pullEvent("char")
214. screen(1,1)
215. turtle.select(16)
216. Nfuel = turtle.getItemSpace(16)
217. for i = 1, Nfuel do
218. fuel = turtle.getFuelLevel()
219. if fuel < volume+100 then
220. turtle.refuel(1)
221. else
222. i = 65 --Breaks the for
223. end
224. end
225. end
226.
227. --Check Double changing the Depth y
228. if Cdouble == 1 then
229. Dy = y/2
230. else
231. Dy = y
232. end
233.
234. --Height Calculation
235. if Cdouble == 0 then
236. b = 1
237. else
238. b = 2
239. end
240.
241.
242. --Mining Phase
243.
244. turn = 1 --Turn right is 0, turn left is 1 opposite to start
245. mined = 0 -- Total Blocks Mined
246. moved = 0 -- Total Spaces Moved
247.
248. turtle.select(1)
249. screen(1,1)
250. print("Blocks Mined")
251. print("")
252. print("Percent Complete")
253. mine()
254. for depth=1, Dy do
255. for width = 1, z do
256. cRows = 0 -- Rows completed (z)
257. mineRow()
258. if turn == 1 then
259. turn = 0
260. else
261. turn = 1
262. end
263. if width ~= z then --Check if last row of set, will not turn if last
264. if turn == 0 then
265. turtle.turnRight()
266. mine()
267. turtle.turnRight()
268. else
269. turtle.turnLeft()
270. mine()
271. turtle.turnLeft()
272. end
273. end
274. end
275. if turn == 0 then --This If statement gets it back to the start of this layer
276. turtle.turnRight()
277. if Cdouble == 1 then
278. if turtle.digDown() == true then
279. mined = mined + 1
280. end
281. end
282. turtle.turnRight()
283. for i=1, x-1 do
284. while not turtle.forward() do
285. end
286. end
287. turtle.turnRight()
288. for i=1, z-1 do
289. while not turtle.forward() do
290. end
291. end
292. else
293. turtle.turnRight()
294. for i=1, z-1 do
295. while not turtle.forward() do
296. end
297. end
298. end
299. if empty == 1 and depth ~= Dy then --AutoEmptying at the end of every layer
300. if Cdouble == 1 then
301. AEup = depth*2
302. else
303. AEup = depth
304. end
305. for i=1, AEup-b do
306. while not turtle.up() do
307. end
308. end
309. turtle.turnLeft()
310. while not turtle.forward() do
311. end
312.
313. --Counting
314. count()
315.
316. turtle.select(1) --Dosen't drop 1 cobblestone for future counting purposes
317. avar = turtle.getItemCount(1)
318. turtle.drop(avar-1)
319.
320. for i=2, 15 do
321. turtle.select(i)
322. turtle.drop()
323. end
324. turtle.select(1)
325. turtle.turnLeft()
326. turtle.turnLeft()
327. while not turtle.forward() do
328. end
329. for i=1, AEup-b do
330. turtle.down()
331. end
332. turtle.turnLeft()
333. end
334. if depth ~= Dy then --This checks if it is the last layer of the run
335. for a=1, b do
336. while not turtle.down() do
337. turtle.digDown()
338. mined = mined+1
339. end
340. moved = moved + 1
341. end
342. turtle.turnRight()
343. if Cdouble == 1 then
344. if turtle.digDown() == true then
345. mined = mined + 1
346. end
347. end
348. turn = 1
349. end
350. end
351.
352. for i=1, y-b do --This gets the turtle back to the top layer
353. while not turtle.up() do
354. end
355. end
356. turtle.turnLeft()
357. while not turtle.forward() do
358. end
359.
360. --Counts all blocks at the end also
361. count()
362.
363. --Output to a chest or sit there
364. chest = turtle.detect()
365. if chest == true then
366. for i=1,15 do
367. turtle.select(i)
368. turtle.drop()
369. end
370. end
371. turtle.turnRight()
372. turtle.turnRight()
373. turtle.select(1)
374. --Display
375. screen(1,1)
376. print("Total Blocks Mined: "..mined)
377. print("Current Fuel Level: "..turtle.getFuelLevel())
378. print("Cobble: "..cobble)
379. print("Other Raw: "..sand)
380. print("Other: "..other)
RAW Paste Data