View difference between Paste ID: NYp3Tq4D and dVwySQdc
SHOW: | | - or go back to the newest paste.
1
--[[Copyright PrinceTommen - Script developed for CyanideEpic (twitch.tv/cyanideepic)]]--
2
--[[You are all allowed to use it as long as you don't pretend it's yours]]--
3
--[[Have fun !]]--
4
version =" 3.5"
5
--[[
6
Release Note:
7
3.5:	Added:	Multiple item slots system, including the items to throw (suggested by Portsanta and CyanideEpic)
8
		Major interface enhancements to make the configuration faster in spite of the new options
9
		Enhanced item shortage security, supporting the multiple slots
10
		New functions to manage I/O in a more compact way (suggested by Niseg)
11
3.41:	Fixed:	Important glitch when the turtle returned to its starting position with a certain configuration
12
		Displaying issues
13
3.4:	Added:	Favorite configuration system
14
		Ability to choose the direction of the series of parallel tunnels (right or left)
15
		Support of execution without torches or chests (will not try to place them)
16
		Security that stops the turtle when it runs out of chests or torches (suggested by CyanideEpic)
17
		Chests and torches status updated automatically
18
		Security that requires the user to press enter before the turtle starts (suggested by CyanideEpic)
19
		The turtle now returns to its starting position after it finishes
20
		New rotation function as well a a specific torch placing function
21
	Fixed:	The turtle will now properly finish the hub after mining an odd number of tunnels	
22
		The torch placement has been modified to avoid conflicts with chests
23
3.3:	Added:	Enderchest Support (suggested by Niseg and Daniteh)
24
		Release note
25
3.2:	Fixed:	Very important chest placing issue (only appeared in 3.1)
26
3.1:	Added:	New mining pattern for more efficiency (suggested by Niseg)
27
		Smarter fuel management:	Will now consume the "stored" fuel before refueling
28
						Can now consume any type of fuel supported by turtles (check the wiki)
29
						Fuel type can be changed while the turtle is mining
30
		Optimized the mining of 3 blocks high tunnels
31
		Better interface, instructions remain visible and a line is dedicated to the fuel status (updated automatically)
32
		Option to throw cobblestone automatically (suggested by Niseg)
33
	Fixed:	Refueling issue in certain circumstances (reported by CyanideEpic)			
34
]]--
35
function resetScreen()
36
	term.clear()
37
	term.setCursorPos(14,1)
38
	write("Mining Turtle")
39
	term.setCursorPos(5,2)
40
	write("For CyanideEpic and his friends")
41
	term.setCursorPos(1,13)
42
	write("By PrinceTommen, version "..version)
43
	term.setCursorPos(1,4)
44
end	  
45
function textOutput(output_message, x_screen_pos, z_screen_pos, clear_area)
46
	term.setCursorPos(x_screen_pos,z_screen_pos)
47
	if clear_area == 0 then
48
		clear_area = string.len(output_message)
49
	end	
50
	write(output_message..string.rep(" ", (clear_area - string.len(output_message))))
51
end
52
function securedInput(x_screen_pos, z_screen_pos, nature, lower_value, upper_value, example1, example2)
53
	example = {example1, example2}
54
	local function shortExample(example_int, example, boolStringPart)
55
		tableShortExample = {}
56
		tableShortExample[example_int] = example[example_int].." ("..string.sub(string.lower(example[example_int]), 1, 1)..") "
57
		if boolStringPart then
58
			return string.sub(string.lower(example[example_int]), 1, 1) 
59
		else
60
			return tableShortExample[example_int]
61
		end	
62
	end
63
	incipit = shortExample(1, example, false).."/ "..shortExample(2, example, false)..": "
64
	if nature == "text" then
65
		repeat
66
			textOutput(incipit, x_screen_pos, z_screen_pos, 39)
67
			term.setCursorPos(string.len(incipit)+1,z_screen_pos)	
68
			user_input = string.sub(string.lower(read()), 1, 1)
69
		until (user_input == shortExample(1, example, true) or user_input == shortExample(2, example, true))
70
	elseif nature == "integer" then
71
		repeat
72
			textOutput(" ", x_screen_pos, z_screen_pos, (39 - x_screen_pos))
73
			term.setCursorPos(x_screen_pos,z_screen_pos)
74
			user_input = tonumber(read())	
75
		until (user_input >= lower_value and user_input <= upper_value)
76
	end	
77
	return user_input
78
end
79
function clearLines(firstLine, lastLine)
80
	a = 1
81
	for a=1, (lastLine-firstLine+1) do
82
		textOutput("", 1, (firstLine+a-1), 40)
83
	end
84
end
85
function convertToBool(var, boolTrue)
86
	if var == boolTrue then
87
		var = true
88
	else
89
		var = false
90
	end
91
	return var
92
end
93
function turn(FacingAngle, Bool_rotation, Rotation_integer)
94
	if Bool_rotation then
95
		for u=1, Rotation_integer do
96
			turtle.turnRight()
97
		end
98
		FacingAngle = FacingAngle + Rotation_integer
99
	else
100
		for u=1, Rotation_integer do
101
			turtle.turnLeft()
102
		end
103
		FacingAngle = FacingAngle - Rotation_integer
104
	end
105
	FacingAngle = math.abs((FacingAngle - 1)%4+1)
106
	return FacingAngle
107
end
108
local function refuel()
109
	turtle.select(torches_slots+current_slot[2])
110
	while not(turtle.refuel(1)) do
111
		for f=1, fuel_slots do
112
			current_slot[2], shortage[2] = rotateSlot(2, torches_slots+1, fuel_slots)
113
			turtle.select(torches_slots+current_slot[2])
114
			if turtle.refuel(1) then
115
				boolRefuel = true
116
				break
117
			else
118
				boolRefuel = false
119
			end
120
		end
121
		if not(boolRefuel) then
122
			textOutput("No Fuel -", 1, 11, 0)
123
			current_slot[2], shortage[2] = manageShortage(2, torches_slots+1, torches_slots+fuel_slots) 
124
		end
125
	end
126
	refuel_count = 80 - turtle.getFuelLevel()
127
	textOutput("Fuel OK -", 1, 11, 0)
128
	return refuel_count  
129
end
130
function moveForward(FacingAngle, Boolfb, moving_integer, digUpBool, digDownBool, refuel_count)
131
	local moving_count = 1
132
	for moving_count=1,moving_integer do
133
		if (refuel_count == 80) then
134
			refuel_count = refuel()
135
		end
136
		Bool1 = false
137
		while not(Bool1) do
138
			if (Boolfb) then
139
				turtle.dig()
140
				Bool1 = turtle.forward()
141
				if (digUpBool) then
142
					turtle.digUp()
143
				end
144
				if (digDownBool) then
145
					turtle.digDown()
146
				end  
147
			else
148
				Bool1 = turtle.back()
149
				if not(Bool1) then
150
					turn(FacingAngle, true, 2)
151
					turtle.dig()
152
					turn(FacingAngle, false, 2)
153
				end
154
			end    
155
		end
156
		moving_count = moving_count + 1
157
		refuel_count = refuel_count + 1
158
	end 
159
	return refuel_count  
160
end
161
function moveUp(Boolud, moving_integer, refuel_count, Bool_DigFront)
162
	local moving_count = 1
163
	for moving_count=1, moving_integer do
164
		if (refuel_count == 80) then
165
			refuel_count = refuel()
166
		end
167
		Bool2 = false
168
		if Bool_DigFront then
169
			turtle.dig()
170
		end
171
		while not(Bool2) do
172
			if (Boolud) then
173
				turtle.digUp()   
174
				Bool2 = turtle.up()
175
			else
176
				turtle.digDown()
177
				Bool2 = turtle.down()
178
			end
179
		end
180
		moving_count = moving_count + 1
181
		refuel_count = refuel_count + 1
182
	end
183
	return refuel_count
184
end
185
function manageShortage(managedItem, initial_item_slot, final_item_slot)
186
	textOutput("The turtle has used all the "..(itemNames[managedItem+3]).." intitially given. Have you refilled all the "..(itemNames[managedItem+3]).." slots ?", 1, 4, 0)
187
	textOutput("Press enter if all the "..(itemNames[managedItem+3]).." slots are refilled (slots "..(initial_item_slot).." to "..(final_item_slot)..").", 1, 7, 0)
188
	repeat
189
		turn(FacingAngle, true, 4)
190
		os.startTimer(1)
191
		press, key = os.pullEvent()
192
	until (key == 257)
193
	clearLines(4,10)
194
	current_slot[managedItem] = 1
195
	shortage[managedItem] = false
196
	return current_slot[managedItem], shortage[managedItem]
197
end
198
function rotateSlot(managedItem, control_slot, rotation_controler)
199
	if (turtle.getItemCount(control_slot) == 0) or (managedItem == 2) then			
200
		if current_slot[managedItem]==rotation_controler and (managedItem ~= 2) then
201
			shortage[managedItem] = true
202
		else
203
			current_slot[managedItem]=((current_slot[managedItem])%rotation_controler)+1
204
		end
205
	end
206
	return current_slot[managedItem], shortage[managedItem]
207
end					
208
function inventoryManagement(refuel_count,Right_or_Left,throw_cobble)
209
	function fullInventory(n)
210
		n = m + 1
211
		repeat
212
			item_count = turtle.getItemCount(n)
213
			if (item_count ~= 0) then          
214
				boolSlotOccupied = true
215
				n = n + 1  
216
			else
217
				boolSlotOccupied = false  
218
			end  
219
		until (boolSlotOccupied == false) or (n == 17)
220
		return n
221
	end
222
	if Chest_approval then
223
		m = torches_slots + chests_slots + fuel_slots + garbage_slots
224
		thrown_slots = 0
225
		if (turtle.getItemCount(16) ~= 0) and (m~=16) then
226
			if fullInventory(m)==17 then
227
				if throw_stuff then
228
					for k=1, garbage_slots do
229
						for j=1, (16-m) do
230
							turtle.select(m - garbage_slots + k)
231
							Bool_match_stuff = turtle.compareTo(m+j)
232
							if Bool_match_stuff then
233
								thrown_slots = thrown_slots + 1
234
								turtle.select(m+j)
235
								turtle.drop()	 
236
							end
237
						end
238
						turtle.select(m - garbage_slots + k)
239
						turtle.drop(turtle.getItemCount(m - garbage_slots + k)-1)
240
					end	
241
					for z = (m+1), 16 do
242
						for u = (z+1), 16 do
243
							if turtle.getItemCount(u)~=0 then
244
								turtle.select(u)
245
								turtle.transferTo(z)
246
							end
247
						end
248
					end
249
				end
250
				if not(throw_stuff) or ((thrown_slots <= 2) and (fullInventory(n)>15)) then
251
					if shortage[3] then
252
						textOutput("No Chests", 24, 11, 0)
253
						current_slot[3], shortage[3] = manageShortage(3, torches_slots+fuel_slots+1, torches_slots+fuel_slots+chests_slots)
254
					end
255
					textOutput("Chests OK", 24, 11, 0)
256
					if (Right_or_Left == "left") then
257
						FacingAngle = turn(FacingAngle, true, 1)
258
					else
259
						FacingAngle = turn(FacingAngle, false, 1)
260
					end  
261
					refuel_count = moveForward(FacingAngle, true, 1, false, true, refuel_count)
262
					turtle.select(torches_slots+fuel_slots+current_slot[3])
263
					turtle.digDown()
264
					turtle.placeDown()
265
					for u=(m+1),16 do
266
						if turtle.getItemCount(u)~=0 then
267
							turtle.select(u)
268
							turtle.dropDown()
269
						end
270
					end
271
					if enderchest then
272
						turtle.select(torches_slots+fuel_slots+1)
273
						turtle.drop()
274
						turtle.digDown()
275
					end
276
					current_slot[3], shortage[3] = rotateSlot(3, torches_slots+fuel_slots+current_slot[3], chests_slots)
277
					refuel_count = moveForward(FacingAngle, false, 1, false, false, refuel_count)
278
					if (Right_or_Left == "left") then
279
						FacingAngle = turn(FacingAngle, false, 1)
280
					else
281
						FacingAngle = turn(FacingAngle, true, 1)
282
					end
283
				end	  
284
			end
285
		end
286
	end
287
	turtle.select(1)
288
	return refuel_count  
289
end
290
function placeTorch(Position)
291
	if Torch_approval then
292
		if shortage[1] then
293
			textOutput("No Torches -", 11, 11, 0)
294
			current_slot[1], shortage[1] = manageShortage(1, 1, torches_slots) 
295
		end
296
		textOutput("Torches OK -", 11, 11, 0)
297
		turtle.select(current_slot[1])
298
		if Position == "front" then
299
			turtle.dig()
300
			turtle.place()
301
		elseif Position ==	"below" then
302
			turtle.digDown()
303
			turtle.placeDown()
304
		elseif Position == "up" then
305
			turtle.digUp()
306
			turtle.placeUp()
307
		end
308
		current_slot[1], shortage[1] = rotateSlot(1, current_slot[1], torches_slots)
309
	end
310
end
311
function digVerticalLayer(refuel_count, FacingAngle, Width, Height, Height_Position, Bool_Torches, Right_or_Left)
312
	if Right_or_Left then
313
		Right_or_Left = "left"
314
	else
315
		Right_or_Left = "right"
316
	end	
317
	done_columns = 0
318
	if (Height_Position == "up") then
319
		for columns=1, math.floor(Width/4) do
320
			turtle.digUp()
321
			if (Height > 3) then
322
				refuel_count = moveUp(true, 1, refuel_count, false)
323
				turtle.dig()
324
				refuel_count = moveUp(false, (Height-2), refuel_count, true)
325
				turtle.digDown()
326
			end
327
			refuel_count = moveForward(FacingAngle, true, 2, true, true, refuel_count)
328
			refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
329
			if (Height > 3) then
330
				refuel_count = moveUp(false, 1, refuel_count, false)
331
				turtle.dig()
332
				refuel_count = moveUp(true, (Height-2), refuel_count, true)
333
				turtle.digUp()
334
			end
335
			refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
336
			done_columns = done_columns + 1
337
			if (Width - 4*done_columns ~= 0) then
338
				refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
339
			end
340
		end  
341
		if ((Width - 4*math.floor(Width/4)) == 0) then
342
			Height_Position = "up"
343
		elseif ((Width - 4*math.floor(Width/4)) == 1) then
344
			turtle.digUp()
345
			refuel_count = moveUp(false, (Height-3), refuel_count, false)
346
			turtle.digDown()
347
			refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
348
			Height_Position = "down"
349
		elseif ((Width - 4*math.floor(Width/4)) >= 2) then
350
			if (Height > 3) then
351
				refuel_count = moveUp(true, 1, refuel_count, false)
352
				turtle.dig()
353
				refuel_count = moveUp(false, (Height-2), refuel_count, true)
354
				turtle.digDown()
355
			end
356
			turtle.digUp()
357
			refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
358
			refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
359
			Height_Position = "down"
360
			if ((Width - 4*math.floor(Width/4)) == 3) then
361
				refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
362
				refuel_count = moveUp(true, (Height - 3), refuel_count, false)
363
				turtle.digUp()
364
				Height_Position = "up"
365
			end
366
		end	
367
	elseif (Height_Position == "down") then
368
		for columns=1, math.floor(Width/4) do
369
			turtle.digDown()
370
			if (Height > 3) then
371
				refuel_count = moveUp(false, 1, refuel_count, false)
372
				turtle.dig()
373
				refuel_count = moveUp(true, (Height - 2), refuel_count, true)
374
				turtle.digUp()
375
			end
376
			refuel_count = moveForward(FacingAngle, true, 2, true, true, refuel_count)
377
			if (Height > 3) then
378
				refuel_count = moveUp(true, 1, refuel_count, false)
379
				turtle.dig()
380
				refuel_count = moveUp(false, (Height - 2), refuel_count, true)
381
				turtle.digDown()
382
			end
383
			refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
384
			done_columns = done_columns + 1
385
			if (Width - 4*done_columns ~= 0) then
386
				refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
387
			end
388
			refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
389
			if (done_columns%2 == 0) and Bool_Torches then
390
				FacingAngle = turn(FacingAngle,true , 1)
391
				placeTorch("front")
392
				FacingAngle = turn(FacingAngle, false, 1)
393
			end
394
		end
395
		if ((Width - 4*math.floor(Width/4)) == 0) then
396
			Height_Position = "down"
397
		elseif ((Width - 4*math.floor(Width/4)) == 1) then
398
			turtle.digDown()	  
399
			refuel_count = moveUp(true, (Height - 3), refuel_count, false)
400
			turtle.digUp()
401
			Height_Position = "up"
402
		elseif ((Width - 4*math.floor(Width/4)) >= 2) then
403
			if (Height > 3) then
404
				refuel_count = moveUp(false, 1, refuel_count, false)
405
				turtle.dig()	  
406
				refuel_count = moveUp(true, (Height - 2), refuel_count, true)
407
				turtle.digUp()
408
			end
409
			turtle.digDown()
410
			refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
411
			Height_Position = "up"
412
			if ((Width - 4*math.floor(Width/4)) == 3) then
413
				refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
414
				refuel_count = moveUp(false, (Height - 3), refuel_count, false)
415
				turtle.digDown()
416
				refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
417
				Height_Position = "down"
418
			end		
419
		end  	  
420
	end
421
	return refuel_count, Height_Position	  
422
end
423
424-
enderchest, throw_stuff, Chest_approval, Torch_approval, Chest_mismatch, Torch_mismatch = false, false, true, true, false, false
424+
enderchest, throw_stuff, Chest_approval, Torch_approval, Chest_mismatch, Torch_mismatch = true, false, true, true, false, false
425
shortage, itemNames = {false, false, false}, {"torch", "fuel", "chest", "torches", "fuel", "chests"}
426
427
resetScreen()
428
if (io.open("favorite", "r") ~= nil) then
429
		resetScreen()
430
		textOutput("Do you wish to use your favorite configuration ?", 1, 4, 0)
431
		Favorite_approval = securedInput(1, 6, "text", 0, 0, "Yes", "No")
432
	if (Favorite_approval == "y") then
433
		handle = fs.open("favorite", "r")
434
		input = handle.readAll()
435
		handle.close()
436
		favorite = textutils.unserialize(input)
437
		tunnels_integer = favorite.tunnels_integer
438
		Width = favorite.Width
439
		Height = favorite.Height
440
		Length = favorite.Length
441
		tunnels_separation = favorite.tunnels_separation
442
		throw_stuff = favorite.throw_stuff
443
		enderchest = favorite.enderchest
444
		Torch_approval = favorite.Torch_approval
445
		Chest_approval = favorite.Chest_approval
446
	end
447
end	
448
if (io.open("favorite", "r") == nil) or ((io.open("favorite", "r") ~= nil) and (Favorite_approval == "n")) then
449
	resetScreen()
450
	textOutput("Number of parallel tunnels ? ", 1, 4, 0)
451
	tunnels_integer = securedInput(37, 4, "integer", 1, 1000, " ", " ")
452
	textOutput("Width of the tunnels ? ", 1, 5, 0)
453
	Width = securedInput(37, 5, "integer", 1, 1000, " ", " ")
454
	term.setCursorPos(1,6)
455
	textOutput("Height of the tunnels ? ", 1, 6, 0)
456
	Height = securedInput(37, 6, "integer", 1, 200, " ", " ")
457
	if (Height < 3) then
458
		Height = 3
459
	end
460
	term.setCursorPos(1,7)
461
	textOutput("Length of the tunnels ? ", 1, 7, 0)
462
	Length = securedInput(37, 7, "integer", 1, 100000, " ", " ")
463
	if (tunnels_integer > 1) then
464
		term.setCursorPos(1,8)
465
		textOutput("Separating blocks between tunnels ? ", 1, 8, 0)
466
		tunnels_separation = securedInput(37, 8, "integer", 1, 1000, " ", " ")
467
	else
468
		tunnels_separation = 0
469
	end	
470
	
471
	resetScreen()
472
	textOutput("To use regular chests, press c", 1, 4, 0)
473
	textOutput("To use an enderchest, press e", 1, 5, 0)
474
	textOutput("To use torches, press t", 1, 6, 0)
475
	textOutput("To throw away specific items, press p", 1, 7, 0)
476
	textOutput("Press enter once you have chosen all the options you wanted to activate.", 1, 11, 0)
477
	while true do
478
		press, key = os.pullEvent()
479
		if press == "key" and key == 257 then
480
			break
481-
		elseif key == 67 then
481+
		elseif press == "key" and key == 67 then
482
			if Chest_approval then
483
				Chest_approval = false
484
				textOutput("", 10, 9, 11)
485
			else	
486
				Chest_approval = true
487
				textOutput("Chests,", 10, 9, 11)
488
			end
489-
		elseif key == 69 then
489+
		elseif press == "key" and key == 69 then
490
			if enderchest then
491
				enderchest = not(enderchest)
492
				textOutput("", 10, 9, 11)
493
			else
494
				Chest_approval = true
495
				enderchest = true
496
				textOutput("Enderchest,", 10, 9, 11)
497
			end
498-
		elseif key == 84 then
498+
		elseif press == "key" and key == 84 then
499
			if Torch_approval then
500
				Torch_approval = false
501
				textOutput("", 1, 9, 8)
502
			else
503
				Torch_approval = true
504
				textOutput("Torches,", 1, 9, 8)
505
			end
506-
		elseif key == 80 then
506+
		elseif press == "key" and key == 80 then
507
			if throw_stuff then
508
				throw_stuff = not(throw_stuff)
509
				textOutput("", 22, 9, 12)			
510
			else	
511
				throw_stuff = true
512
				textOutput("Throw items.", 22, 9, 12)
513
			end	
514
		end	
515
	end
516
	resetScreen()
517
	
518
	textOutput("Do you want to save this configuration as your favorite ?", 1, 4, 0)
519
	New_favorite = securedInput(1, 6, "text", 0, 0, "Yes", "No")
520
	
521
	if (New_favorite == "y") then
522
		favorite = {}
523
		favorite.tunnels_integer = tunnels_integer
524
		favorite.Width = Width
525
		favorite.Height = Height
526
		favorite.Length = Length 
527
		favorite.tunnels_separation = tunnels_separation
528
		favorite.Torch_approval = Torch_approval
529
		favorite.Chest_approval = Chest_approval
530
		favorite.throw_stuff = throw_stuff
531
		favorite.enderchest = enderchest
532
		output = textutils.serialize(favorite)
533
		handle = fs.open("favorite", "w")
534
		handle.write(output)
535
		handle.close()
536
	end
537
end
538
resetScreen()
539
textOutput("To manage extra slots, press s", 1, 4, 0)
540
textOutput("This option allows you to have several torches/fuel/chests slots, as well as different items to throw", 1, 6, 0)
541
textOutput("Else, press enter to skip this step.", 1, 10, 0)
542
torches_slots, chests_slots, garbage_slots = 0, 0, 0	
543
while true do
544
	press, key = os.pullEvent()
545
	if press == "key" and key == 257 then
546
		fuel_slots = 1
547
		break
548
	elseif key == 83 then
549
		repeat
550
			turtle.select(1)
551
			resetScreen()
552
			textOutput("Number of fuel slots ? ", 1, 4, 0)
553
			fuel_slots = securedInput(29, 4, "integer", 1, 16, " ", " ")	
554
			slot_total = fuel_slots
555
			if Torch_approval then	
556
				textOutput("Number of torches slots ? ", 1, 5, 0)
557
				torches_slots = securedInput(29, 5, "integer", 1, 16, " ", " ")
558
				slot_total = slot_total + torches_slots
559
			end	
560
			if Chest_approval  and not(enderchest) then	
561
				textOutput("Number of chests slots ? ", 1, 6, 0)
562
				chests_slots = securedInput(29, 6, "integer", 1, 16, " ", " ")
563
				slot_total = slot_total + chests_slots
564
			end	
565
			if throw_stuff then	
566
				textOutput("Number of undesired items ? ", 1, 7, 0)
567
				garbage_slots = securedInput(29, 7, "integer", 1, 16, " ", " ")
568
				slot_total = slot_total + garbage_slots
569
			end
570
		until (slot_total < 16)
571
		break
572
	end
573
end
574
resetScreen()
575
if (tunnels_integer > 1) then
576
	textOutput("The first tunnel will be in front of the turtle. Do you want the tunnels to be dug on the right or on the left of the first tunnel (They will be parallel to the first one) ?", 1, 4, 0)
577
	Bool_direction = securedInput(1, 9, "text", 0, 0, "Right", "Left")
578
end
579
if (tunnels_integer == 1) and (Width > 1) then
580
	textOutput("In front of the turtle will be one side of the tunnel. Do you want it to mine the rest on the left or on the right ?", 1, 4, 0)
581
	Bool_direction = securedInput(1, 9, "text", 0, 0, "Right", "Left")
582
end
583
resetScreen()
584
if Torch_approval then
585
	if torches_slots > 1 then
586
		textOutput("Torches in the slots 1 to "..torches_slots, 1, 4, 0) 
587
	else
588
		torches_slots = 1
589
		textOutput("Torches in the slot 1", 1, 4, 0)
590
	end
591
end
592
if fuel_slots > 1 then
593
	textOutput("Fuel in the slots "..(torches_slots+1).." to "..(torches_slots+fuel_slots), 1, 5, 0)
594
else
595
	fuel_slots = 1
596
	textOutput("Fuel in the slot "..(torches_slots+1), 1, 5, 0)
597
end
598
if Chest_approval  and not(enderchest) then
599
	if chests_slots > 1 then
600
		textOutput("Chests in the slots "..(torches_slots+fuel_slots+1).." to "..(torches_slots+fuel_slots+chests_slots), 1, 6, 0)
601
	else
602
		chests_slots = 1
603
		textOutput("Chests in the slot "..(torches_slots+fuel_slots+1), 1, 6, 0)
604
	end
605
end		
606
if enderchest then
607
	textOutput("The enderchest in the slot "..(torches_slots+fuel_slots+1), 1, 6, 0)
608
	chests_slots = 1
609
end
610
if throw_stuff then
611
	if garbage_slots > 1 then
612
		textOutput("Please make sure there are samples of the items to throw in the slots "..(torches_slots+fuel_slots+chests_slots+1).." to "..(torches_slots+fuel_slots+chests_slots+garbage_slots), 1, 8, 0)
613
	else
614
		garbage_slots = 1
615
		textOutput("Please make sure there is a sample of the item to throw in the slot "..(torches_slots+fuel_slots+chests_slots+1), 1, 8, 0)
616
	end 
617
end  
618
if (Bool_direction == "r") then
619
	Bool_direction = true
620
else
621
	Bool_direction = false
622
end
623
textOutput("Press enter to start", 1, 11, 0)
624
while true do
625
	press, key = os.pullEvent()
626
	if press == "key" and key == 257 then
627
		break
628
	end	
629
end
630
resetScreen()
631
textOutput("", 1, 11, 20)
632
if Torch_approval and (turtle.getItemCount(1) == 0) then
633
	textOutput("The torches slot is empty. Are you sure you want to use torches ?", 1, 4, 0)
634
	Torch_approval = convertToBool(securedInput(1, 6, "text", 0, 0, "Yes", "No"), "y")
635
elseif Torch_approval and (turtle.getItemCount(1) ~= 0) then
636
	for u = 1, torches_slots-1 do
637
		turtle.select(u+1)
638
		if  not(turtle.compareTo(1)) then
639
			Torch_mismatch = true
640
		end
641
	end
642
	if Torch_mismatch then
643
		resetScreen()
644
		textOutput("All the slots dedicated to the torches have not been set up correctly. Are you sure you want to use torches ?", 1, 4, 0)
645
		Torch_approval = convertToBool(securedInput(1, 7, "text", 0, 0, "Yes", "No"), "y")
646
	end
647
end
648
649
if Chest_approval and (turtle.getItemCount(torches_slots + fuel_slots + 1) == 0) then
650
	resetScreen()
651
	textOutput("The chests slot is empty. Are you sure you want to use chests ?", 1, 4, 0)
652
	Chest_approval = convertToBool(securedInput(1, 6, "text", 0, 0, "Yes", "No"), "y")
653
elseif Chest_approval and (turtle.getItemCount(torches_slots + fuel_slots + 1) ~= 0) then
654
	for u = 1, chests_slots-1 do
655
		turtle.select(torches_slots + fuel_slots + u + 1)
656
		if  not(turtle.compareTo(torches_slots + fuel_slots + 1)) then
657
			Chest_mismatch = true
658
		end
659
	end	
660
	if Chest_mismatch then
661
		resetScreen()
662
		textOutput("All the slots dedicated to the chests have not been set up correctly. Are you sure you want to use chests ?", 1, 4, 0)
663
		Chest_approval = convertToBool(securedInput(1, 7, "text", 0, 0, "Yes", "No"), "y")
664
	end
665
end
666
if Torch_approval then
667
	empty_torches_slots = 0
668
	for u = 1, torches_slots do
669
		if turtle.getItemCount(u) == 0 then
670
		    empty_torches_slots = empty_torches_slots + 1
671
		end
672
	end
673
	if empty_torches_slots == torches_slots then
674
		shortage[1] = true
675
	end
676
	textOutput("No Torches -", 11, 11, 0)
677
end	
678
if Torch_approval and (turtle.getItemCount(1) ~= 0) then
679
	shortage[1] = false
680
	textOutput("Torches OK -", 11, 11, 0)
681
end
682
if Chest_approval then
683
	empty_chests_slots = 0
684
	for u = 1, chests_slots do
685
		if turtle.getItemCount(torches_slots + fuel_slots + u) == 0 then
686
		    empty_chests_slots = empty_chests_slots + 1
687
		end
688
	end
689
	if empty_chests_slots == chests_slots then
690
		shortage[3] = true
691
	end
692
	textOutput("No Chests -", 24, 11, 0)
693
end	
694
if Chest_approval and (turtle.getItemCount(torches_slots + fuel_slots + 1) ~= 0) then
695
	shortage[3] = false
696
	textOutput("Chests OK -", 24, 11, 0)
697
end
698
textOutput("Fuel OK -", 1, 11, 0)
699
refuel_count = 80 - turtle.getFuelLevel()
700
FacingAngle, tunnel_forth, current_slot= 0, true, {1, 1, 1}
701
refuel_count = moveUp(true, 1, refuel_count, false)
702
if (Width == 1) then
703
	refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
704
end
705
for done_tunnels=1, tunnels_integer do
706
	if (Width >= 2) then
707
		for done_layers=1, math.ceil(Length/2) do
708
			refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
709
			FacingAngle = turn(FacingAngle, Bool_direction, 1)
710
			refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, Width, Height, "down", false, Bool_direction)
711
			FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
712
			refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
713
			FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
714
			refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, Width, Height, Height_Position, false, not(Bool_direction))
715
			FacingAngle = turn(FacingAngle, Bool_direction, 1)
716
			if (done_layers%4 == 0) then
717
				refuel_count = moveUp(false, 1, refuel_count, false)
718
				FacingAngle = turn(FacingAngle, Bool_direction, 1)
719
				placeTorch("front")
720
				FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
721
				refuel_count = moveUp(true, 1, refuel_count, false)
722
			end
723
		end
724
	elseif (Width == 1) then
725
		refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, 2*math.ceil(Length/2), Height, "down", true, Bool_direction) 
726
	end
727
	if (Height_Position == "up") then
728
		refuel_count = moveUp(false, (Height - 3), refuel_count, false)
729
		Height_Position = "down"
730
	end
731
	if tunnel_forth and (tunnels_integer - done_tunnels >= 1) then
732
		refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
733
		FacingAngle = turn(FacingAngle, Bool_direction, 1)
734
		refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)+tunnels_separation), Height, "down", false, not(Bool_direction))
735
		if (Height_Position == "up") then
736
			refuel_count = moveUp(false, (Height - 3), refuel_count, false)
737
			Height_Position = "down"
738
		end
739
		FacingAngle = turn(FacingAngle, Bool_direction, 1)
740
		placeTorch("below")
741
	elseif not(tunnel_forth) then
742
		refuel_count = moveForward(FacingAngle, true, 1, true, false, refuel_count)
743
		FacingAngle = turn(FacingAngle, Bool_direction, 1)
744
		refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)-1+tunnels_separation), Height, "down", false, Bool_direction)
745
		FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
746
		refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
747
		FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
748
		refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)-1+tunnels_separation), Height, Height_Position, false, not(Bool_direction))
749
		if (Height_Position == "up") then
750
			refuel_count = moveUp(false, (Height - 3), refuel_count, false)
751
			Height_Position = "down"
752
		end
753
		FacingAngle = turn(FacingAngle, Bool_direction, 2)
754
		refuel_count = moveForward(FacingAngle, true, (Width-2), true, true, refuel_count)
755
		placeTorch("front")
756
		FacingAngle = turn(FacingAngle, not(Bool_direction), 2)
757
		refuel_count = moveForward(FacingAngle, true, (Width-2), true, true, refuel_count)
758
		if (tunnels_integer - done_tunnels ~= 0) then
759
			refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
760
			refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (tunnels_separation+1), Height, Height_Position, false, Bool_direction)
761
			FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
762
			refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
763
			FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
764
			refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (tunnels_separation+1), Height, Height_Position, false, not(Bool_direction))
765
			refuel_count = moveForward(FacingAngle, false, tunnels_separation, true, true, refuel_count)
766
			FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
767
			placeTorch("front")
768
			FacingAngle = turn(FacingAngle, not(Bool_direction), 2)
769
		end	
770
	end
771
	if tunnel_forth and (tunnels_integer - done_tunnels == 0) and (Width > 1) then
772
		refuel_count = moveForward(FacingAngle, false, 2*math.ceil(Length/2), false, false, refuel_count)
773
		FacingAngle = turn(FacingAngle, Bool_direction, 1)
774
		refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
775
		refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (Width - 1), Height, Height_Position, false, Bool_direction)
776
		FacingAngle = turn(FacingAngle, Bool_direction, 1)
777
		refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
778
		FacingAngle = turn(FacingAngle, Bool_direction, 1)
779
		refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (Width - 1), Height, Height_Position, false, not(Bool_direction))
780
		if (Height_Position == "up") then
781
			refuel_count = moveUp(false, (Height - 3), refuel_count, false)
782
			Height_Position = "down"
783
		end
784
		refuel_count = moveForward(FacingAngle, false, (Width - 2), false, false, refuel_count)
785
		FacingAngle = turn(FacingAngle, Bool_direction, 2)
786
	end
787
	if (Width == 1) and (tunnels_integer - done_tunnels ~= 0) then
788
		refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
789
	elseif (Width == 1) and (tunnels_integer - done_tunnels == 0) and tunnel_forth then
790
		refuel_count = moveForward(FacingAngle, false, (2*math.ceil(Length/2)), false, false, refuel_count)
791
	end
792
	tunnel_forth = not(tunnel_forth)
793
end
794
refuel_count = moveUp(false, 1, refuel_count, false)
795
if (Width == 1) and not(tunnel_forth) then
796
	refuel_count = moveForward(FacingAngle, false, 1, false, false, refuel_count)
797
	turn(FacingAngle, Bool_direction, 1)
798
end
799
refuel_count = moveForward(FacingAngle, false, ((tunnels_integer*Width) - 1 + (tunnels_separation*(tunnels_integer - 1))), false, false, refuel_count)
800
FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
801
refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
802
resetScreen()
803
write("Done. I hope I worked well !")
804
term.setCursorPos(1,8)