• API
• FAQ
• Tools
• Archive
daily pastebin goal
64%
SHARE
TWEET

# Variable Dimension Quarry Program

a guest Nov 2nd, 2012 280 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.0.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.
14. --Defining things
15. function screen(xPos,yPos)
16. term.clear()
17. term.setCursorPos(xPos,yPos)
18. end
19. function mine()
20. while turtle.forward() == false do
21. turtle.dig()
22. mined = mined + 1
23. term.setCursorPos(1,2)
24. term.clearLine()
25. end
26. moved = moved + 1
27. display()
28. end
29. function mineRow()
30. if cRows ~= 0 then
31. for length=1, x do
32. mine()
33. end
34. else
35. for length=1, x-1 do
36. mine()
37. end
38. end
39. cRows = cRows + 1
40. end
41. function display() --Run in Mine(), display information to the screen in a certain place
42. percent = math.ceil((moved/volume)*100)
43. term.setCursorPos(1,2)
44. term.clearLine()
45. print(mined)
46. term.setCursorPos(1,4)
47. term.clearLine()
48. print(percent.."%")
49. end
50. fuel = turtle.getFuelLevel()
51. slot = {}
52. for i=1, 16 do
53. slot[i] = {}
54. end
55. sandCh = 0
56. stacks = {}
57. cobble = 0
58. sand = 0
59. other = 0
60.
61. --Input Phase
62. screen(1,1)
63. print("----- Welcome to Quarry! -----")
64. print("")
65. --Dimensions of Hole
66. print("What dimensions?")
67. print("")
68. term.write("Length: ")
70.
71. term.write("Width: ")
73.
74. term.write("Height: ")
76.
77. if not y or y == 0 then
78. y = 3
79. end
80. if not x or x == 0 then
81. x = 3
82. end
83. if not z or z == 0 then
84. z = 3
85. end
86.
87. volume = x*y*z
88. area = x*z
89. if maxslots > 15 then
90. maxslots = 15
91. end
92. maxsize = maxslots*64
93.
94. empty = 0
95.
96.
97. --Checks if bigger than inventory: 832 blocks theoretical Assuming at least 2 are non-cobble
98. if volume > maxsize then
99. print("Job very big")
100. print("Auto-emptying on")
101. empty = 1
102. sleep(2)
103. else
104. print("Turn on auto-emptying? (Y/N)")
106. if ans == "y" or ans == "1" then
107. empty = 1
108. end
109. end
110. if area > maxsize then
111. print("Area too Large, please restart program")
112. sleep(5)
113. os.reboot()
114. end
115.
116.
117. --Getting Fuel
118. while fuel < volume do
119. print("Fuel Needed")
120. print("Put Fuel in Bottom Right")
121. print("Press any key when placed")
122. os.pullEvent("char")
123. screen(1,1)
124. turtle.select(16)
125. Nfuel = turtle.getItemSpace(16)
126. for i = 1, Nfuel do
127. fuel = turtle.getFuelLevel()
128. if fuel < volume+50 then
129. turtle.refuel(1)
130. else
131. i = 65 --Breaks the for
132. end
133. end
134. end
135.
136.
137. --Mining Phase
138.
139. turn = 1 --Turn right is 0, turn left is 1 opposite to start
140. mined = 0 -- Total Blocks Mined
141. moved = 0 -- Total Spaces Moved
142.
143. turtle.select(1)
144. screen(1,1)
145. print("Blocks Mined")
146. print("")
147. print("Percent Complete")
148. mine()
149. for depth=1, y do
150. for width = 1, z do
151. cRows = 0 -- Rows completed (z)
152. mineRow()
153. if turn == 1 then
154. turn = 0
155. else
156. turn = 1
157. end
158. if width ~= z then --Check if last row of set, will not turn if last
159. if turn == 0 then
160. turtle.turnRight()
161. mine()
162. turtle.turnRight()
163. else
164. turtle.turnLeft()
165. mine()
166. turtle.turnLeft()
167. end
168. end
169. end
170. if --This If statement gets it back to the start of this layer
171. turn == 0 then
172. turtle.turnRight()
173. turtle.turnRight()
174. for i=1, x-1 do
175. while not turtle.forward() do
176. end
177. end
178. turtle.turnRight()
179. for i=1, z-1 do
180. while not turtle.forward() do
181. end
182. end
183. else
184. turtle.turnRight()
185. for i=1, z-1 do
186. while not turtle.forward() do
187. end
188. end
189. end
190. if empty == 1 and depth ~= y then --AutoEmptying at the end of every layer
191. for i=1, depth-1 do
192. while not turtle.up() do
193. end
194. end
195. turtle.turnLeft()
196. while not turtle.forward() do
197. end
198. for i=1, 15 do
199. turtle.select(i)
200. turtle.drop()
201. end
202. turtle.select(1)
203. turtle.turnLeft()
204. turtle.turnLeft()
205. while not turtle.forward() do
206. end
207. for i=1, depth-1 do
208. turtle.down()
209. end
210. turtle.turnLeft()
211. end
212. if depth ~= y then --This checks if it is the last layer of the run
213. if turtle.down() == false then
214. turtle.digDown()
215. mined = mined+1
216. turtle.down()
217. end
218. moved = moved + 1
219. turtle.turnRight()
220. turn = 1
221. end
222. end
223. for i=1, y-1 do --This gets the turtle back to the top layer
224. while not turtle.up() do
225. end
226. end
227. turtle.turnLeft()
228. while not turtle.forward() do
229. end
230.
231. --Detection of blocks code is 1: Cobble 2: Other Raw 3:Other
232. if empty == 0 then
233. slot[1][1] = 1
234. for i=2, 15 do --Checks each slot for cobble
235. turtle.select(i)
236. Ccobble = turtle.compareTo(1)
237. if Ccobble == true then
238. slot[i][1] = 1
239. end
240. end
241. for i=2, 15 do --Checks each slot for stacks, assumes sand or dirt
242. Cnum = turtle.getItemCount(i)
243. if Cnum == 64 and slot [i][1] ~= 1 then
244. slot[i][1] = 2
245. table.insert(stacks, i)
246. sandCh = 1
247. end
248. end
249. for i=2, 15 do --Checks if other slots have sand or dirt
250. turtle.select(i)
251. if sandCh == 1 then--Checks if there is any sand/dirt
252. for a=1, #stacks do --Compares it to all known sand/dirt slots
253. Csand = turtle.compareTo(stacks[a])
254. if Csand == true then --If it is the same as any dirt/sand
255. slot[i][1] = 2
256. a = 20 --Breaks the for
257. end
258. end
259. end
260. end
261. for i=2, 15 do
262. if slot[i][1] ~= 1 and slot[i][1] ~= 2 then
263. slot[i][1] = 3
264. end
265. end
266. for i=1, 15 do
267. slot[i][2] = turtle.getItemCount(i)
268. end
269. for i=1, 15 do
270. if slot[i][1] == 1 then
271. cobble = cobble + slot[i][2]
272. end
273. if slot[i][1] == 2 then
274. sand = sand + slot[i][2]
275. end
276. if slot[i][1] == 3 then
277. other = other + slot[i][2]
278. end
279. end
280. end
281.
282. --Output to a chest or sit there
283. chest = turtle.detect()
284. if chest == true then
285. for i=1,15 do
286. turtle.select(i)
287. turtle.drop()
288. end
289. turtle.turnRight()
290. turtle.turnRight()
291. end
292. --Display
293. screen(1,1)
294. print("Total Blocks Mined: "..mined)
295. print("Current Fuel Level: "..turtle.getFuelLevel())
296. if empty == 0 then
297. print("Cobble: "..cobble)
298. print("Other Raw: "..sand)
299. print("Other: "..other)
300. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top