View difference between Paste ID: fxus3JUM and eCKxztiV
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
local peripheralConnected = peripheral.getType("left")
49
if (peripheralConnected == "modem") then
50
  isWirelessTurtle = true
51
end
52-
	print("Mining size: " .. rows .. " by " .. columns)
52+
53-
--	print("Total distance: " .. posX + posY + posZ)
53+
if (isWirelessTurtle == true) then
54-
--	print("X: " .. posX)
54+
  turtleId = os.getComputerLabel()
55-
--	print("Y: " .. posY)
55+
  rednet.open("left")
56-
--	print("Z: " .. posZ)
56+
57-
--	print("Orientation: " .. rotation)
57+
58
function broadcast(message)
59-
		print("Toss garbage: Yes")
59+
    -- if(turtleId==nil) then
60
    --   http.post("http://rwind.tk:3000/print","msg=[no id] "..message)
61-
		print("Toss garbage: No")
61+
    -- else
62
    --   http.post("http://rwind.tk:3000/print","msg=".."[".. turtleId.."] "..message)
63-
	print("")
63+
    -- end
64-
	print("Fuel level: " .. turtle.getFuelLevel())
64+
65
    if (isWirelessTurtle == true) then
66
      if (turtleId == nil) then
67
        rednet.broadcast(message)
68
      else
69
        -- Broadcast the message (prefixed with the turtle's id)
70
        rednet.broadcast("[".. turtleId.."] "..message)
71
      end
72
    end
73
end
74
75
function info()
76
	term.clear()
77
	term.setCursorPos(1,1)
78
    message = "---------------------------------------" .. "\n"
79
	message = message .. "Mining size: " .. rows .. " by " .. columns .. "\n"
80
    message = message .. "Total distance: " .. posX + posY + posZ .. "\n"
81
	message = message .. "X: " .. posX .. "\n"
82
	message = message .. "Y: " .. posY .. "\n"
83
    message = message .. "Z: " .. posZ .. "\n"
84
    message = message .. "Orientation: " .. rotation .. "\n"
85
	if tossGarbage == "yes" then
86
		message = message .. "Toss garbage: Yes" .. "\n"
87
	else
88
		message = message .. "Toss garbage: No" .. "\n"
89
	end
90
	message = message .. "Fuel level: " .. turtle.getFuelLevel() .. "\n"
91
    broadcast(message)
92
    print(message)
93
end
94
95
function rotate()
96
	if rotation == 0 then
97
		turtle.turnLeft()
98
	elseif rotation == 1 then
99
		turtle.turnLeft()
100
		turtle.turnLeft()
101
	elseif rotation == 2 then
102
		turtle.turnRight()
103
	end
104
end
105
106
function recover()
107
	rotate()
108
	local step = 0
109
	for step = posY - 1, 0, -1 do
110
		turtle.up()
111
	end
112
	for step = posX - 1, 0, -1 do
113
		turtle.forward()
114
	end
115
	turtle.turnLeft()
116
	for step = posZ - 1, 0, -1 do
117
		turtle.forward()
118
	end
119
end
120
121
function resume()
122
	turtle.turnLeft()
123
	turtle.turnLeft()
124
	local step = 0
125
	for step = 0, posZ - 1, 1 do
126
		turtle.forward()
127
	end
128
	turtle.turnRight()
129
	for step = 0, posX - 1, 1 do
130
		turtle.forward()
131
	end
132
	for step = 0, posY - 1, 1 do
133
		turtle.down()
134
	end
135
	if rotation == 0 then
136
		turtle.turnLeft()
137
	elseif rotation == 2 then
138
		turtle.turnRight()
139
	elseif rotation == 3 then
140
		turtle.turnRight()
141
		turtle.turnRight()
142
	end
143
end
144
145
function checkFuel()
146
	turtle.select(1)
147
	turtle.refuel()
148
	if turtle.getFuelLevel() <= posX + posY + posZ + 1 then
149
		refill = 1
150
		empty()
151
		refill = 0
152
	end
153
end
154
155
function empty()
156
	recover()
157
	if quarrybore == "bore" then
158
		turtle.down()
159
	end	
160
	local search = 0
161
	for search = 16, 1, -1 do
162
		turtle.select(search)
163
		turtle.drop()
164
	end
165
	if refill == 1 then
166
		turtle.turnRight()
167
		while turtle.getFuelLevel() <= posX + posY + posZ + 1 do
168
			if turtle.suck() == true then
169
				turtle.suck()
170
				turtle.select(1)
171
				turtle.refuel()
172
			elseif turtle.suck() == false then
173
				turtle.select(1)
174
				turtle.refuel()
175
				term.clear()
176
				term.setCursorPos(1,1)
177
				io.write("Please add more fuel to slot '1' or fuel chest.")
178
			end
179
		end
180
		turtle.turnLeft()
181
		resume()
182
	end
183
	if done ~= 1 then
184
		if quarrybore == "bore" then
185
			turtle.up()
186
		end	
187
		resume()
188
	end
189
end
190
191
function checkFull()
192
	fullSlots = 0
193
	local search = 0
194
	for search = 16, 1, -1 do
195
		turtle.select(search)
196
		if turtle.getItemCount() > 0 then
197
			if tossGarbage == "yes" then
198
				if turtle.getItemDetail().name == "minecraft:cobblestone" then
199
					turtle.drop()
200
				elseif turtle.getItemDetail().name == "minecraft:stone" then
201
					turtle.drop()
202
				elseif turtle.getItemDetail().name == "minecraft:dirt" then
203
					turtle.drop()
204
				elseif turtle.getItemDetail().name == "minecraft:gravel" then
205
					turtle.drop()
206
				elseif turtle.getItemDetail().name == "chisel:marble2" then
207
					turtle.drop()
208
				elseif turtle.getItemDetail().name == "chisel:limestone2" then
209
					turtle.drop()
210
				elseif turtle.getItemDetail().name == "minecraft:netherrack" then
211
					turtle.drop()
212
				elseif turtle.getItemDetail().name == "natura:nether_tainted_soil" then
213
					turtle.drop()
214
				end
215
			end
216
		end
217
		if turtle.getItemCount() > 0 then
218
			fullSlots = fullSlots + 1
219
		end
220
	end
221
	if fullSlots == 16 then
222
		empty()
223
	end
224
end
225
226
function nextRow()
227
	if turn == 0 then
228
		turtle.turnRight()
229
		rotation = 1
230
		digStraight()
231
		turtle.turnRight()
232
		rotation = 2
233
		turn = 1
234
	elseif turn == 1 then
235
		turtle.turnLeft()
236
		rotation = 1
237
		digStraight()
238
		turtle.turnLeft()
239
		rotation = 0
240
		turn = 0 
241
	elseif turn == 2 then
242
		turtle.turnRight()
243
		rotation = 3
244
		digStraight()
245
		turtle.turnRight()
246
		rotation = 0
247
		turn = 3
248
	elseif turn == 3 then
249
		turtle.turnLeft()
250
		rotation = 3
251
		digStraight()
252
		turtle.turnLeft()
253
		rotation = 2
254
		turn = 2
255
	end
256
end
257
258
function digDown()
259
	checkFuel()
260
	local step = 0
261
	for step = 2, 0, -1 do
262
		turtle.digDown()
263
		if turtle.down() == true then
264
			posY = posY + 1
265
		end
266
		info()
267
	end
268
end
269-
	while posY < iniY - 2 do
269+
270
function digStraight()
271
	checkFuel()
272
	turtle.digDown()
273
	turtle.dig()
274
	turtle.dig()
275
	turtle.forward()
276
	if rotation == 0 then
277
		posZ = posZ + 1
278
	elseif rotation == 1 then
279
		posX = posX + 1
280
	elseif rotation == 2 then
281
		posZ = posZ - 1
282
	elseif rotation == 3 then
283
		posX = posX - 1
284
	end
285
	turtle.digUp()
286
	info()
287
end
288
289
function quarry()
290
	turn = 0
291
	done = 0
292
	iniY = tonumber (iniY)
293
	checkFuel()
294
	turtle.digUp()
295
	turtle.up()
296
	posY = posY - 1
297
	while posY < iniY + 64 do
298
		if quarrybore == "quarry" then
299
			digDown()
300
		end
301
		for c = columns, 1, -1 do
302
			for r = rows, 2, -1 do
303
				digStraight()
304
			end
305
			checkFull()
306
			if c == 1 then
307
				turtle.turnRight()
308
				turtle.turnRight()
309
				if rotation == 0 then
310
					rotation = 2
311
				elseif rotation == 2 then
312
					rotation = 0
313
				end
314
				if turn == 0 then
315
					turn = 2
316
				elseif turn == 1 then
317
					turn = 3
318
				elseif turn == 2 then
319
					turn = 0
320
				elseif turn == 3 then
321
					turn = 1
322
				end
323
			elseif c > 1 then
324
				nextRow()
325
			end
326
		end
327
		if quarrybore == "bore" then
328
			posY = posY + 1
329
		end
330
	end
331
	turtle.digDown()
332
	done = 1
333
	empty()
334
	term.clear()
335
	term.setCursorPos(1,1)
336
	print("Thank you for using Gambit's quarry program!")
337
	print("---------------------------------------")
338
end
339
340
quarry()