View difference between Paste ID: WbhTk2Gk and 0hUKaXKe
SHOW: | | - or go back to the newest paste.
1
--Announcement: In an attempt to add a tunnel boring feature to this, I ended up breaking it so auto refueling no longer works. Version 2.0 is in the works (K6HvcJmD) but many features do not function and I'm taking a break from fixing it, but feel free to edit it if you'd like.
2
3
--Note: Computer craft has an issue where turtles will break if left in unloaded chunks, keep near the turtle or use a worldspike.
4
5
--This is version 1.2.4, updates will replace the current pastebin with the newer version once they're done!
6
--Added a boring mode that mines a single layer, good for underground strip mining.
7
8
--How to use:
9
--Place a chest to the left of the turtle for fuel and a chest behind it for a place to drop off items.
10
--"Quarry or bore?" Type "quarry" for a quarry or "bore" to mine a single layer. Make sure you type in all lowercase.
11
--"Rows" If looking from above, this is how many blocks it will mine in the 'y' axis.
12
--"Columns" If looking from above, this is how many blocks it will mine in the 'x' axis.
13
--"Current 'y' level?" The 'y' level of the turtle.
14
--"Toss garbage blocks?" Type "yes" to toss out stone, gravel, dirt, etc. Make sure you type in all lowercase.
15
16
term.clear()
17
term.setCursorPos(1,1)
18
io.write("Quarry or bore? ")
19
quarrybore = io.read()
20
term.clear()
21
term.setCursorPos(1,1)
22
io.write("Rows: ")
23
rows = io.read()
24
io.write("Columns: ")
25
columns = io.read()
26
iniY = 2
27
if quarrybore == "quarry" then
28
	term.clear()
29
	term.setCursorPos(1,1)
30
	io.write("Current 'y' level: ")
31
	iniY = io.read()
32
end
33
term.clear()
34
term.setCursorPos(1,1)
35
io.write("Toss garbage blocks? ")
36
tossGarbage = io.read()
37
term.clear()
38
term.setCursorPos(1,1)
39
40
posX = 0
41
posY = 0
42
posZ = 0
43
44
rotation = 0
45
46
fullSlots = 0
47
48
function info()
49
	term.clear()
50
	term.setCursorPos(1,1)
51
	print("---------------------------------------")
52
	print("Mining size: " .. rows .. " by " .. columns)
53
--	print("Total distance: " .. posX + posY + posZ)
54
--	print("X: " .. posX)
55
--	print("Y: " .. posY)
56
--	print("Z: " .. posZ)
57
--	print("Orientation: " .. rotation)
58
	if tossGarbage == "yes" then
59
		print("Toss garbage: Yes")
60
	else
61
		print("Toss garbage: No")
62
	end
63
	print("")
64
	print("Fuel level: " .. turtle.getFuelLevel())
65
end
66
67
function rotate()
68
	if rotation == 0 then
69
		turtle.turnLeft()
70
	elseif rotation == 1 then
71
		turtle.turnLeft()
72
		turtle.turnLeft()
73
	elseif rotation == 2 then
74
		turtle.turnRight()
75
	end
76
end
77
78
function recover()
79
	rotate()
80
	local step = 0
81
	for step = posY - 1, 0, -1 do
82
		turtle.up()
83
	end
84
	for step = posX - 1, 0, -1 do
85
		turtle.forward()
86
	end
87
	turtle.turnLeft()
88
	for step = posZ - 1, 0, -1 do
89
		turtle.forward()
90
	end
91
end
92
93
function resume()
94
	turtle.turnLeft()
95
	turtle.turnLeft()
96
	local step = 0
97
	for step = 0, posZ - 1, 1 do
98
		turtle.forward()
99
	end
100
	turtle.turnRight()
101
	for step = 0, posX - 1, 1 do
102
		turtle.forward()
103
	end
104
	for step = 0, posY - 1, 1 do
105
		turtle.down()
106
	end
107
	if rotation == 0 then
108
		turtle.turnLeft()
109
	elseif rotation == 2 then
110
		turtle.turnRight()
111
	elseif rotation == 3 then
112
		turtle.turnRight()
113
		turtle.turnRight()
114
	end
115
end
116
117
function checkFuel()
118
	turtle.select(1)
119
	turtle.refuel()
120
	if turtle.getFuelLevel() <= posX + posY + posZ + 1 then
121
		refill = 1
122
		empty()
123
		refill = 0
124
	end
125
end
126
127
function empty()
128
	recover()
129
	if quarrybore == "bore" then
130
		turtle.down()
131
	end	
132
	local search = 0
133
	for search = 16, 1, -1 do
134
		turtle.select(search)
135
		turtle.drop()
136
	end
137
	if refill == 1 then
138
		turtle.turnRight()
139
		while turtle.getFuelLevel() <= posX + posY + posZ + 1 do
140
			if turtle.suck() == true then
141
				turtle.suck()
142
				turtle.select(1)
143
				turtle.refuel()
144
			elseif turtle.suck() == false then
145
				turtle.select(1)
146
				turtle.refuel()
147
				term.clear()
148
				term.setCursorPos(1,1)
149
				io.write("Please add more fuel to slot '1' or fuel chest.")
150
			end
151
		end
152
		turtle.turnLeft()
153
		resume()
154
	end
155
	if done ~= 1 then
156
		if quarrybore == "bore" then
157
			turtle.up()
158
		end	
159
		resume()
160
	end
161
end
162
163
function checkFull()
164
	fullSlots = 0
165
	local search = 0
166
	for search = 16, 1, -1 do
167
		turtle.select(search)
168
		if turtle.getItemCount() > 0 then
169
			if tossGarbage == "yes" then
170
				if turtle.getItemDetail().name == "minecraft:cobblestone" then
171
					turtle.drop()
172
				elseif turtle.getItemDetail().name == "minecraft:stone" then
173
					turtle.drop()
174
				elseif turtle.getItemDetail().name == "minecraft:dirt" then
175
					turtle.drop()
176
				elseif turtle.getItemDetail().name == "minecraft:gravel" then
177
					turtle.drop()
178
				elseif turtle.getItemDetail().name == "chisel:marble2" then
179
					turtle.drop()
180
				elseif turtle.getItemDetail().name == "chisel:limestone2" then
181
					turtle.drop()
182
				elseif turtle.getItemDetail().name == "minecraft:netherrack" then
183
					turtle.drop()
184
				elseif turtle.getItemDetail().name == "natura:nether_tainted_soil" then
185
					turtle.drop()
186
				end
187
			end
188
		end
189
		if turtle.getItemCount() > 0 then
190
			fullSlots = fullSlots + 1
191
		end
192
	end
193
	if fullSlots == 16 then
194
		empty()
195
	end
196
end
197
198
function nextRow()
199
	if turn == 0 then
200
		turtle.turnRight()
201
		rotation = 1
202
		digStraight()
203
		turtle.turnRight()
204
		rotation = 2
205
		turn = 1
206
	elseif turn == 1 then
207
		turtle.turnLeft()
208
		rotation = 1
209
		digStraight()
210
		turtle.turnLeft()
211
		rotation = 0
212
		turn = 0 
213
	elseif turn == 2 then
214
		turtle.turnRight()
215
		rotation = 3
216
		digStraight()
217
		turtle.turnRight()
218
		rotation = 0
219
		turn = 3
220
	elseif turn == 3 then
221
		turtle.turnLeft()
222
		rotation = 3
223
		digStraight()
224
		turtle.turnLeft()
225
		rotation = 2
226
		turn = 2
227
	end
228
end
229
230
function digDown()
231
	checkFuel()
232
	local step = 0
233
	for step = 2, 0, -1 do
234
		turtle.digDown()
235
		if turtle.down() == true then
236
			posY = posY + 1
237
		end
238
		info()
239
	end
240
end
241
242
function digStraight()
243
	checkFuel()
244
	turtle.digDown()
245
	turtle.dig()
246
	turtle.dig()
247
	turtle.forward()
248
	if rotation == 0 then
249
		posZ = posZ + 1
250
	elseif rotation == 1 then
251
		posX = posX + 1
252
	elseif rotation == 2 then
253
		posZ = posZ - 1
254
	elseif rotation == 3 then
255
		posX = posX - 1
256
	end
257
	turtle.digUp()
258
	info()
259
end
260
261
function quarry()
262
	turn = 0
263
	done = 0
264
	iniY = tonumber (iniY)
265
	checkFuel()
266
	turtle.digUp()
267
	turtle.up()
268
	posY = posY - 1
269
	while posY < iniY - 2 do
270
		if quarrybore == "quarry" then
271
			digDown()
272
		end
273
		for c = columns, 1, -1 do
274
			for r = rows, 2, -1 do
275
				digStraight()
276
			end
277
			checkFull()
278
			if c == 1 then
279
				turtle.turnRight()
280
				turtle.turnRight()
281
				if rotation == 0 then
282
					rotation = 2
283
				elseif rotation == 2 then
284
					rotation = 0
285
				end
286
				if turn == 0 then
287
					turn = 2
288
				elseif turn == 1 then
289
					turn = 3
290
				elseif turn == 2 then
291
					turn = 0
292
				elseif turn == 3 then
293
					turn = 1
294
				end
295
			elseif c > 1 then
296
				nextRow()
297
			end
298
		end
299
		if quarrybore == "bore" then
300
			posY = posY + 1
301
		end
302
	end
303
	turtle.digDown()
304
	done = 1
305
	empty()
306
	term.clear()
307
	term.setCursorPos(1,1)
308
	print("Thank you for using Gambit's quarry program!")
309
	print("---------------------------------------")
310
end
311
312
quarry()