View difference between Paste ID: aCefYa99 and q354743w
SHOW: | | - or go back to the newest paste.
1
--pastebin get q354743w botminer
2-
--Last Update: 14.12.2025-11:00
2+
--Last Update: 03.04.2023-20:27
3
4
term.clear()
5
term.setCursorPos(1,1)
6
7
local ignore = {"minecraft:stone",
8
				"minecraft:dirt",
9
				"minecraft:andesite",
10
				"minecraft:granite",
11
				"minecraft:diorite",
12
				"minecraft:gravel",
13
				"minecraft:deepslate",
14
				"minecraft:cobbled_deepslate",
15
				"minecraft:tuff",
16
				"minecraft:calcite",
17
				"minecraft:smooth_basalt",
18
				"minecraft:amethyst_block",
19-
				"xycraft_world:kivi",
19+
				"soul_ice:lightstone",
20-
				"forbidden_arcanus:darkstone",
20+
				"quark:limestone",
21
				"create:weathered_limestone",
22
				"create:limestone",
23
				"create:dolomite",
24
				"create:gabbro",
25-
				"create:crimsite",
25+
26
				"create:dark_scoria",
27
				"create:scoria",
28
				"appliedenergistics2:charged_quartz_ore",
29-
				"create:asurine",
29+
30
				"minecraft:sand",
31
				"minecraft:cobblestone",	
32
				"minecraft:grass_block",
33
				"minecraft:bedrock",
34
				"minecraft:oak_planks",
35
				"minecraft:chest",
36
				"minecraft:torch",					
37-
				"minecraft:torch",
37+
38-
				"minecraft:ladder",
38+
				"computercraft:turtle_normal"}
39-
				"minecraft:netherrack",
39+
40
local backupignore = {"minecraft:stone",
41-
				"computercraft:turtle_normal",
41+
42-
				"minecraft:polished_andesite",
42+
43-
				"minecraft:cyan_terrracotta",
43+
44-
				"minecraft:smooth_stone",
44+
45-
				"minecraft:mossy_cobblestone",
45+
46-
				"minecraft:coarse_dirt",
46+
47-
				"minecraft:smooth_stone_slab",
47+
48-
				"minecraft:polished_andesite_stairs",
48+
49-
				"forbidden_arcanus:stella_arcanum",
49+
50-
				"lootr:lootr_chest",
50+
51-
				"lootr:lootr_barrel"}
51+
52
					"minecraft:bedrock",
53
					"computercraft:turtle_advanced",
54
					"computercraft:turtle_normal",
55
					"quark:marble",
56
					"quark:limestone",
57
					"quark:slate",
58
					"quark:deepslate",
59
					"forbidden_arcanus:dark_stone",
60
					"forbidden_arcanus:petrified_root",
61
					"silentgems:hardened_netherrack",
62
					"silentgems:hardened_end_stone",
63
					"create:weathered_limestone",
64
					"create:limestone",
65
					"create:dolomite",
66
					"create:gabbro",
67
					"create:natural_scoria",
68
					"create:dark_scoria",
69
					"create:scoria",
70
					"astralsorcery:marble_raw",
71
					"chisel:basalt2",
72
					"rustic:slate",
73
					"chisel:limestone2",
74
					"chisel:marble2",
75
					"chisel:stonebrick",
76
					"chisel:stonebrick1",
77
					"chisel:stonebrick2",
78
					"chisel:cobblestone"}
79
80
81
local modemFound = false
82
local programReset = false
83
local programInspect = false
84
local returnedStep = false
85
local skipShafts = false
86
local cancelProgram = false
87
local oreFound = false
88
local maxOreLimitHit = false
89
90
local posDforward = 0
91
local shaft = 0
92
local skipShaftsNum = 0
93-
local exclude = {"allthemodium:allthemodium_ore",
93+
94-
				"allthemodium:allthemodium_slate_ore",
94+
95-
				"irons_spellbooks:mithril_ore",
95+
96-
				"irons_spellbooks:deepslate_mithril_ore"}
96+
97-
				
97+
98-
local excludeAlways = {"forbidden_arcanus:stella_arcanum",
98+
99-
						"lootr:lootr_chest",
99+
100-
						"lootr:lootr_barrel"}
100+
101
102
local foundOre=""
103
local BotStatus = "Booting"
104
105
local monitorMessage =""
106
107
local posX = 0
108
local posY = 0
109
local posZ = 0
110
local posD = 0
111
112
local posXhome = 0
113
local posYhome = 0
114
local posZhome = 0
115
local posDhome = 0
116
117
local posXsave = {}
118
local posYsave = {}
119
local posZsave = {}
120
local posDsave = {}
121
122
local posXgps = 0
123
local posYgps = 0
124
local posZgps = 0
125
local posDgps = 0
126
127
local posXgps2 = 0
128
local posYgps2 = 0
129
local posZgps2 = 0
130
131
local posXgpshome = 0
132
local posYgpshome = 0
133
local posZgpshome = 0
134
local posDgpshome = 0
135
136
--Filnames: Config,DisplayID,GPS,DisplaySave
137
local filenames={"bmconfig","bmsave","bmgps","bmdispsave"}
138
139
local statusText = {"Running",  		--1
140
					"Need Fuel",		--2
141
					"Mining Vein", 		--3		+oreamount
142
					"Return Vein",		--4
143
					"Heading Home",		--5
144
					"Leaving Home", 	--6		after heading home
145
					"Deposit Stuff",	--7
146
					"Moved GPS-Home",	--8
147
					"At GPS-Home",		--9
148
					"No GPS!",			--10
149
					"Chest Full",		--11
150
					"Max Ore Limit",	--12
151
					"Chest Full"}		--13
152
local arg={...}
153
local saveTable = {}
154
local gpsTable = {}
155
156
157
local DisplayHeaderTable = {"BotID : ",
158
							"Fuel  : ",
159
							"PosX  : ",
160
							"PosY  : ",
161
							"PosZ  : ",
162
							"PosD  : ",
163
							"Shaft : ",
164
							"Status: "}
165
local DisplayDataTable = {}
166
local DisplayTable = {}
167
168
local configText = {"Length of Shafts",
169
					"Number of Shafts",
170
					"Slot for checking if full",
171
					"Minimum amount of Fuel",
172-
					"Excluded Block",	--13
172+
173-
					"Need Support"}		--14
173+
174-
					
174+
175
					"Use Charged Certus detection? 1=Yes 0=No"}
176
local config={}
177
--Default config for 5x5 chunks loaded starting in the middle of the edge chunck
178
config[1] = 60 		--length of shafts
179
config[2] = 22   	--num of shafts
180
config[3] = 13  	--checkslot for full
181
config[4] = 500 	--minFuel
182
config[5] = 1		--Shaft direction 1=Right 3=Left
183
config[6] = 0		--GPS
184
config[7] = 0		--EnderChestDrop
185
config[8] = 0		--Charged Ore
186
187
function useArgs()
188
	readParams = 0
189
	while readParams < #arg do
190
		if string.lower(arg[readParams+1]) == "-skip" then
191
			if not (readParams+1 < #arg) or tonumber(readParams+2) == nil  then
192
				print('Bad Argument! Type "botminer -help" for help!')
193
				return false
194
			else
195
				skipShafts = true
196
				skipShaftsNum = tonumber(arg[readParams+2])
197
				readParams=readParams+2
198-
					"Use Excluded Block detection? 1=Yes 0=No"}
198+
199
		elseif string.lower(arg[readParams+1]) == "-reset" then
200
			programReset = true
201
			readParams=readParams+1
202
		elseif string.lower(arg[readParams+1]) == "-inspect" then
203
			programInspect = true
204
			readParams=readParams+1
205
		elseif string.lower(arg[readParams+1]) == "-refuel" then
206
			firstDropSlot = 1
207
			while true do
208-
config[8] = 1		--Exclude
208+
209
			end
210
		elseif string.lower(arg[readParams+1]) == "-help" then
211
				print("Help-Page:")
212
				print("botminer -skip 3 -> Amount of shafts the bot will skip.")
213
				print("botminer -reset -> Will reset the config of the bot.")
214
				print("botminer -inspect -> Shows block name in front of bot.")
215
				return false
216
		else
217
			print('Bad Argument! Type "botminer -help" for help!')
218
			return false
219
		end
220
	end
221
	return true
222
end
223
224
function GPSfile()
225
	if not fs.exists(filenames[3]) then
226
		gpsTable = {posXgps, posYgps, posZgps, posDgps}
227
		f = fs.open(filenames[3], "w")
228
		f.write(textutils.serialize(gpsTable))
229
		f.close()
230
		createStartup(true)
231
		return false
232
	else
233
		f = fs.open(filenames[3], "r")
234
		gpsTable =textutils.unserialize(f.readAll())
235-
				print("botminer -skip #  -> Amount of shafts the bot will skip.")
235+
236-
				print("botminer -reset   -> Will reset the config of the bot.")
236+
237
		posYgpshome = gpsTable[2]
238-
				print("botminer -refuel  -> Starts refuel mode.")
238+
239
		posDgpshome = gpsTable[4]
240
		return true
241
	end
242
end
243
244
function DisplaySavefile()
245
	if not fs.exists(filenames[4]) then
246
		createStartup(true)
247
		return false
248
	else
249
		f = fs.open(filenames[4], "r")
250
		DisplayDataTable = textutils.unserialize(f.readAll())
251
		f.close()
252
		return true
253
	end
254
end
255
256
function bot_getGPSpos()
257
	posXgps, posYgps, posZgps = gps.locate()
258
	if not posXgps then return false end
259
	while turtle.forward() == false do
260
		turtle.dig()
261
		turtle.attack()
262
	end
263
	posXgps2, posYgps2, posZgps2 = gps.locate()
264
	if 	   posXgps < posXgps2 then 
265
		posDgps = 0 
266
	elseif posYgps < posYgps2 then 
267
		posDgps = 1 
268
	elseif posXgps > posXgps2 then 
269
		posDgps = 2 
270
	elseif posYgps > posYgps2 then 
271
		posDgps = 3 
272
	end
273
	while turtle.back() == false do 
274
		bot_turnRight()
275
		bot_turnRight()
276
		turtle.dig()
277
		turtle.attack()
278
		bot_turnRight()
279
		bot_turnRight()
280
	end
281
	return true
282
end
283
284-
		bot_dig()
284+
285
	if posXgps == posXgpshome then 
286
		if posYgps == posYgpshome then 
287
			if posZgps == posZgpshome then 
288
				if posDgps == posDgpshome then 
289
					return true
290
				else 
291
					return false
292
				end
293
			else 
294
				return false
295
			end
296
		else 
297
			return false
298
		end
299
	else 
300-
		bot_dig()
300+
301
	end
302
end
303
304
function bot_returnhomeGPS()
305
	
306
	posX = posXgps
307
	posY = posYgps
308
	posZ = posZgps
309
	posD = posDgps
310
	local calcXgps = posXgps - posXgpshome
311
	local calcYgps = posYgps - posYgpshome
312
313
	while posZ ~= posZgpshome do
314
		if posZ > posZgpshome then 
315
			bot_down()
316
		elseif posZ < posZgpshome then
317
			bot_up()
318
		end
319
	end
320
	if calcXgps <= calcYgps then
321
		if posX > posXgpshome then
322
			while posD ~= 2 do
323
				bot_turnRight()
324
			end
325
			while posX ~= posXgpshome do
326
				bot_forward()
327
			end
328
		elseif posX < posXgpshome then
329
			while posD ~= 0 do
330
				bot_turnRight()
331
			end
332
			while posX ~= posXgpshome do
333
				bot_forward()
334
			end
335
		end
336
		if posY > posYgpshome then
337
			while posD ~= 3 do
338
				bot_turnRight()
339
			end
340
			while posY ~= posYgpshome do
341
				bot_forward()
342
			end
343
		elseif posY < posYgpshome then
344
			while posD ~= 1 do
345
				bot_turnRight()
346
			end
347
			while posY ~= posYgpshome do
348
				bot_forward()
349
			end
350
		end
351
	elseif calcYgps <= calcXgps then
352
		if posY > posYgpshome then
353
			while posD ~= 3 do
354
				bot_turnRight()
355
			end
356
			while posY ~= posYgpshome do
357
				bot_forward()
358
			end
359
		elseif posY < posYgpshome then
360
			while posD ~= 1 do
361
				bot_turnRight()
362
			end
363
			while posY ~= posYgpshome do
364
				bot_forward()
365
			end
366
		end
367
		if posX > posXgpshome then
368
			while posD ~= 2 do
369
				bot_turnRight()
370
			end
371
			while posX ~= posXgpshome do
372
				bot_forward()
373
			end
374
		elseif posX < posXgpshome then
375
			while posD ~= 0 do
376
				bot_turnRight()
377
			end
378
			while posX ~= posXgpshome do
379
				bot_forward()
380
			end
381
		end	
382
	end
383
	while posD ~= posDgpshome do
384
		bot_turnRight()
385
	end
386
	
387
	posX = 0
388
	posY = 0
389
	posZ = 0
390
	posD = 0
391
end
392
393
function configFile()
394
	if not fs.exists(filenames[1]) then
395
		configInput()
396
		f = fs.open(filenames[1], "w")
397
		f.write(textutils.serialize(config))
398
		f.close()
399
	else
400
		f = fs.open(filenames[1], "r")
401
		config = textutils.unserialize(f.readAll())
402
		f.close()
403
	end
404
	for i=1, #config do
405
		config[i] = tonumber(config[i])
406
	end
407
end
408
409
function configInput()
410
	for i=1, #config do
411
		local IOinput = ""
412
		term.clear()
413
		term.setCursorPos(1,1)
414
		print("Default is for 5x5 chunks loaded;")
415
		print("starting at middle of edge chunk.")
416
		print(configText[i].." - Default: "..config[i])
417
		IOinput = tonumber(io.read())
418
		if type( IOinput ) == "number" then
419
			config[i] = IOinput
420
			print("Used input: "..config[i])
421
		else
422
			print("Used default value!")
423
		end
424
		sleep(1)
425
	end
426
	configCheck()
427
end
428
429
function configCheck()
430
	term.clear()
431
	term.setCursorPos(1,1)
432
	if config[1] < 1 then									--length
433
		print("Wrong Input at: "..configText[1].." Press ENTER!")
434
		io.read()
435
		configInput()
436
	elseif config[2] < 1 or config[2] > 99 then   			--shafts
437
		print("Wrong Input at: "..configText[2].." Press ENTER!")
438
		io.read()
439
		configInput()
440
	elseif config[3] < 1 or config[3] > 16 then 			--checkslot
441
		print("Wrong Input at: "..configText[3].." Press ENTER!")
442
		io.read()
443
		configInput()
444
	elseif config[4] < 1 then 								--minFuel
445
		print("Wrong Input at: "..configText[4].." Press ENTER!")
446
		io.read()
447
		configInput()
448-
		sleep(0.5)
448+
449
		print("Wrong Input at: "..configText[5].." Press ENTER!")
450
		io.read()
451
		configInput()
452
	elseif config[6] ~= 0 and config[6] ~= 1 then			--GPS
453
		print("Wrong Input at: "..configText[6].." Press ENTER!")
454
		io.read()
455
		configInput()
456
	end
457
end
458
459
function wlanDisplay()
460
	for _,side in ipairs({"left", "right"}) do
461
		if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
462
			rednet.open(side)
463
			modemFound = true
464
			-- if not fs.exists(filenames[2]) then
465
				-- print("WLAN-Display-ID?")
466
				-- saveTable[1] = tonumber(io.read())
467
				-- f = fs.open(filenames[2], "w")
468
				-- f.write(textutils.serialize(saveTable))
469
				-- f.close()
470
			-- else
471
				-- f = fs.open(filenames[2], "r")
472
				-- saveTable =textutils.unserialize(f.readAll())
473
				-- f.close()
474
			-- end
475
			break
476
		end
477
	end
478
end
479
480-
	elseif config[7] ~= 0 and config[7] ~= 1 then			--EnderChestDrop
480+
481-
		print("Wrong Input at: "..configText[7].." Press ENTER!")
481+
482
	-- DisplayHeaderTable[1] = "BotID : "
483
	-- DisplayHeaderTable[2] = "Fuel  : "
484-
	elseif config[8] ~= 0 and config[8] ~= 1 then			--Exclude
484+
485-
		print("Wrong Input at: "..configText[8].." Press ENTER!")
485+
486
	-- DisplayHeaderTable[5] = "PosZ  : "
487
	-- DisplayHeaderTable[6] = "PosD  : "
488
	-- DisplayHeaderTable[7] = "Shaft : "
489
	-- DisplayHeaderTable[8] = "Status: "
490
	
491-
function checkwlan()
491+
492
	if reboot == false then 
493
		DisplayDataTable[1] =  os.getComputerID()
494
		DisplayDataTable[2] =  turtle.getFuelLevel()
495
		DisplayDataTable[3] =  posX
496
		DisplayDataTable[4] =  posY
497
		DisplayDataTable[5] =  posZ
498
		DisplayDataTable[6] =  posD
499
		DisplayDataTable[7] =  shaft
500
		DisplayDataTable[8] =  BotStatus
501
		DisplayDataTable[9] =  turtle.getFuelLimit()
502
		DisplayDataTable[10] = config[2] --num of shafts
503
	
504
		if fs.exists(filenames[4]) then fs.delete(filenames[4]) end
505
		f = fs.open(filenames[4], "w")
506
		f.write(textutils.serialize(DisplayDataTable))
507
		f.close()
508
	end
509
	
510
	
511
	--Display Info in Bot Terminal
512
	DisplayTable[1] = DisplayHeaderTable[1]..DisplayDataTable[1]
513
	DisplayTable[2] = DisplayHeaderTable[2]..DisplayDataTable[2].." / "..DisplayDataTable[9]
514
	DisplayTable[3] = DisplayHeaderTable[3]..DisplayDataTable[3]
515
	DisplayTable[4] = DisplayHeaderTable[4]..DisplayDataTable[4]
516
	DisplayTable[5] = DisplayHeaderTable[5]..DisplayDataTable[5]
517
	DisplayTable[6] = DisplayHeaderTable[6]..DisplayDataTable[6]
518
	DisplayTable[7] = DisplayHeaderTable[7]..DisplayDataTable[7].."/"..DisplayDataTable[10]
519
	DisplayTable[8] = DisplayHeaderTable[8]..DisplayDataTable[8] 
520
	
521
	term.clear()
522
	term.setCursorPos(1,1)
523
	for i=1, #DisplayTable do
524
		print(DisplayTable[i])
525
	end
526
	
527
	if modemFound then
528
		modemSend()
529
		-- modemReceive()
530
	end
531
end
532
533
function modemSend()
534
	local dataTable = {	tostring(DisplayDataTable[1]),
535
						tostring(DisplayDataTable[2]),
536
						tostring(DisplayDataTable[3]),
537
						tostring(DisplayDataTable[4]),
538
						tostring(DisplayDataTable[5]),
539
						tostring(DisplayDataTable[6]),
540
						tostring(DisplayDataTable[8]),
541
						tostring(DisplayDataTable[7]),
542
						tostring(DisplayDataTable[10])}
543
	
544
	--rednet.send(tonumber(saveTable[1]),textutils.serialize(dataTable),"BOT")
545
	rednet.broadcast(textutils.serialize(dataTable),"BOT")
546
end
547
548
-- function modemReceive()
549
	-- local senderId, message, protocol = rednet.receive("BOT",0.01)
550
	-- if senderId == saveTable[1] then
551
		-- monitorMessage = message
552
		-- if message == "cancel" then
553
			-- cancelProgram = true
554
		-- end
555
	-- else
556
		-- monitorMessage = ""
557
	-- end
558
-- end
559
560
function bot_digTunnel()
561
	while turtle.forward() == false do
562
		turtle.dig()
563
		turtle.attack()
564
	end
565
	if posD == 0 then 
566
		posX = posX+1
567
	elseif posD == 1 then 
568
		posY = posY+1
569
	elseif posD == 2 then 
570
		posX = posX-1
571
	elseif posD == 3 then 
572
		posY = posY-1
573
	end	
574
	displayUpdate(false)
575
	turtle.digUp()
576
end
577
578
function bot_returnTunnel() --WHY!!!!!!!!!!!!!!!!!!!
579
	while turtle.forward() == false do
580-
function oldstuff()
580+
		turtle.dig()
581
		turtle.attack()
582
	end
583
	posX = posX-1
584
	displayUpdate(false)
585
end
586
587
function bot_forward()
588
	while turtle.forward() == false do
589
		turtle.dig()
590
		turtle.attack()
591
	end
592
	if posD == 0 then 
593
		posX = posX+1
594
	elseif posD == 1 then 
595
		posY = posY+1
596-
		bot_dig()
596+
597
		posX = posX-1
598
	elseif posD == 3 then 
599
		posY = posY-1
600
	end	
601
	displayUpdate(false)
602
end
603
604
function bot_back()
605
	while turtle.back() == false do 
606
		bot_turnRight()
607
		bot_turnRight()
608
		turtle.dig()
609-
	bot_digUp()
609+
610
		bot_turnRight()
611
		bot_turnRight()
612
	end
613
	if posD == 0 then 
614-
		bot_dig()
614+
615
	elseif posD == 1 then 
616
		posY = posY-1
617
	elseif posD == 2 then 
618
		posX = posX+1
619
	elseif posD == 3 then 
620
		posY = posY+1
621
	end	
622
	displayUpdate(false)
623-
		bot_dig()
623+
624
625
function bot_up()
626
	while turtle.up() == false do
627
		turtle.digUp()
628
		turtle.attackUp()
629
	end
630
	posZ = posZ+1
631
	displayUpdate(false)
632
end
633
634
function bot_down()
635
	while turtle.down() == false do
636
		turtle.digDown()
637
		turtle.attackDown()
638
	end
639
	posZ = posZ-1
640
	displayUpdate(false)
641
end
642-
		bot_dig()
642+
643
function bot_turnRight()
644
	if turtle.turnRight() then
645
		posD = posD + 1
646
		if posD > 3 then 
647
			posD = 0
648
		end
649
	end
650
end
651
652
function bot_turnLeft()
653
	if turtle.turnLeft() then
654
		posD = posD - 1
655
		if posD < 0 then 
656
			posD = 3
657
		end
658
	end
659
end
660
661-
		bot_digUp()
661+
662
	if turtle.detectUp() then
663
		local successUp, dataUp = turtle.inspectUp()
664
		if successUp then
665
			for i=1,#ignore do
666
				if dataUp.name == ignore[i] then
667
					if dataUp.name == "appliedenergistics2:charged_quartz_ore" then
668
						chargedOre()
669
					end
670-
		bot_digDown()
670+
671
				end
672
			end
673
			foundOre = "Up"
674
			return true
675
		end
676
	end
677
end
678
679
function bot_checkoresDown()
680
	if turtle.detectDown() then
681
		local successDown, dataDown = turtle.inspectDown()
682
		if successDown then
683
			for i=1,#ignore do
684
				if dataDown.name == ignore[i] then
685
					if dataDown.name == "appliedenergistics2:charged_quartz_ore" then
686
						chargedOre()
687
					end
688
					return false
689
				end
690
			end
691
			foundOre = "Down"
692
			return true
693
		end
694
	end
695
end
696
697
function bot_checkoresRight()
698
	bot_turnRight()
699
	if turtle.detect() then
700
		local successRight, dataRight = turtle.inspect()
701-
					if dataUp.name == exclude then
701+
702-
						excludeOre()
702+
703
				if dataRight.name == ignore[i] then
704
					if dataRight.name == "appliedenergistics2:charged_quartz_ore" then
705
						chargedOre()
706
					end
707
					bot_turnLeft()
708
					return false				
709
				end
710
			end
711
			foundOre = "Right"
712
			bot_turnLeft()
713
			return true
714
		end	
715
	end
716
	bot_turnLeft()
717
end
718
719-
					if dataDown.name == exclude then
719+
720-
						excludeOre()
720+
721
	if turtle.detect() then
722
		local successLeft, dataLeft = turtle.inspect()
723
		if successLeft then
724
			for i=1,#ignore do
725
				if dataLeft.name == ignore[i] then
726
					if dataLeft.name == "appliedenergistics2:charged_quartz_ore" then
727
						chargedOre()
728
					end
729
					bot_turnRight()
730
					return false				
731
				end
732
			end
733
			foundOre = "Left"
734
			bot_turnRight()
735
			return true
736
		end
737
	end
738-
					if dataRight.name == exclude then
738+
739-
						excludeOre()
739+
740
741
function bot_checkoresBack()
742
	bot_turnLeft()
743
	bot_turnLeft()
744
	if turtle.detect() then
745
		local successBack, dataBack = turtle.inspect()
746
		if successBack then
747
			for i=1,#ignore do
748
				if dataBack.name == ignore[i] then
749
					if dataBack.name == "appliedenergistics2:charged_quartz_ore" then
750
						chargedOre()
751
					end
752
					bot_turnRight()
753
					bot_turnRight()
754
					return false				
755
				end
756
			end
757
			foundOre = "Back"
758
			bot_turnRight()
759
			bot_turnRight()
760-
					if dataLeft.name == exclude then
760+
761-
						excludeOre()
761+
762
	end
763
	bot_turnRight()
764
	bot_turnRight()
765
end
766
767
function bot_checkoresFornt()
768
	if turtle.detect() then
769
		local successFront, dataFront = turtle.inspect()
770
		if successFront then
771
			for i=1,#ignore do
772
				if dataFront.name == ignore[i] then
773
					if dataFront.name == "appliedenergistics2:charged_quartz_ore" then
774
						chargedOre()
775
					end
776
					return false				
777
				end
778
			end
779
			foundOre = "Front"
780
			return true
781
		end
782
	end
783-
					if dataBack.name == exclude then
783+
784-
						excludeOre()
784+
785
function chargedOre()
786
	if config[8] == 1 then
787
		BotStatus = statusText[13]
788
		term.clear()
789
		term.setCursorPos(1,1)
790
		print("Found Charged Certus Quartz! Press ENTER.")
791
		io.read()
792
		BotStatus = statusText[1]
793
	end
794
end
795
796
function bot_savePos()
797
	table.insert(posXsave,posX)
798
	table.insert(posYsave,posY)
799
	table.insert(posZsave,posZ)
800
	table.insert(posDsave,posD)
801
end
802
803
function bot_turntoOre()
804
	if foundOre == "Right" then
805
		bot_turnRight()
806
	elseif foundOre == "Left" then
807-
					if dataFront.name == exclude then
807+
808-
						excludeOre()
808+
809
		bot_turnLeft()
810
		bot_turnLeft()
811
	end
812
end
813
814
function bot_digOre()
815
	if foundOre == "Up" then
816
		bot_up()
817
	elseif foundOre == "Down" then
818
		bot_down()
819-
function bot_dig()
819+
820-
	bot_checkExcludeFront()
820+
821
	elseif foundOre == "Left" then
822
		bot_forward()
823
	elseif foundOre == "Front" then
824-
function bot_digUp()
824+
825-
	bot_checkExcludeUp()
825+
826
end
827
828
function mineOresCheck()
829-
function bot_digDown()
829+
830-
	bot_checkExcludeDown()
830+
831-
	turtle.digDown()
831+
832
			oreFound = true
833
			return true
834-
function bot_checkExcludeFront()
834+
835
			oreFound = false
836
			return false	
837
		end
838-
			if config[8] == 1 then
838+
839-
				for i=1,#exclude do
839+
840-
					if dataFront.name == exclude[i] then
840+
841-
						excludeOre()
841+
842
		else
843
			oreFound = false
844
			return false	
845-
			for i=1,#excludeAlways do
845+
846-
				if dataFront.name == excludeAlways[i] then
846+
847-
					excludeAlwaysOre()
847+
848
849
function bot_returnStep()
850
	--while posX ~= posXsave or posY ~= posYsave or posZ ~= posZsave or posD ~= posDsave do
851
		local x = #posXsave
852
		if posZ > posZsave[x] then bot_down() end
853
		if posZ < posZsave[x] then bot_up() end
854-
function bot_checkExcludeUp()
854+
855
			if posX > posXsave[x] then bot_back() end
856
			if posX < posXsave[x] then bot_forward() end
857
		elseif posD == 1 then
858-
			if config[8] == 1 then
858+
859-
				for i=1,#exclude do
859+
860-
					if dataUp.name == exclude[i] then
860+
861-
						excludeOre()
861+
862
			if posX > posXsave[x] then bot_forward() end	
863
		elseif posD == 3 then
864
			if posY < posYsave[x] then bot_back() end
865-
			for i=1,#excludeAlways do
865+
866-
				if dataUp.name == excludeAlways[i] then
866+
867-
					excludeAlwaysOre()
867+
868
			bot_turnRight()
869
		end
870
		if posD == 0 then
871
			if posX > posXsave[x] then bot_back() end
872
			if posX < posXsave[x] then bot_forward() end
873
		elseif posD == 1 then
874-
function bot_checkExcludeDown()
874+
875
			if posY < posYsave[x] then bot_forward() end
876
		elseif posD == 2 then
877
			if posX < posXsave[x] then bot_back() end
878-
			if config[8] == 1 then
878+
879-
				for i=1,#exclude do
879+
880-
					if dataDown.name == exclude[i] then
880+
881-
						excludeOre()
881+
882
		end
883
	--end
884
	table.remove(posXsave,x)
885-
			for i=1,#excludeAlways do
885+
886-
				if dataDown.name == excludeAlways[i] then
886+
887-
					excludeAlwaysOre()
887+
888
end
889
890
function bot_mineOres()
891
	local mineores = true
892
	local amountOreVein = 0
893
	while mineores do
894-
function excludeOre()
894+
895-
	BotStatus = statusText[13]
895+
896
				bot_dropStuffEnder()
897
			end
898
		end
899-
	print("Found excluded Block! Press ENTER to resume.")
899+
900
		displayUpdate(false)
901
		if amountOreVein < maxOres then
902
			bot_turntoOre()
903
			bot_savePos()
904-
function excludeAlwaysOre()
904+
905-
	BotStatus = statusText[14]
905+
906
			displayUpdate(false)
907
			while mineOresCheck() == false and #posXsave > 0 do
908
				bot_returnStep()
909-
	print("Found always excluded Block! Please Help! Press ENTER to resume.")
909+
910
				BotStatus = statusText[4]..": "..amountOreVein
911
			end
912
		else
913
			while #posXsave > 0 do
914
				bot_returnStep()
915
				returnedStep = true
916
				BotStatus = statusText[4]..": "..amountOreVein
917
			end
918
			oreFound = false
919
			maxOreLimitHit = true
920
		end
921
		if #posXsave == 0 and oreFound == false then
922
			mineores = false
923
			amountOreTotal = amountOreTotal + amountOreVein
924
			BotStatus = statusText[1]
925
			turnDforward(posDforward)
926
			-- if bot_checkoresRight() or bot_checkoresLeft() then
927
				-- bot_mineOres() 
928
			-- end
929
		end
930
	end
931
end
932
933
function bot_returnhome()
934
	BotStatus = statusText[5]
935
	posXhome = posX
936
	posYhome = posY
937
	posZhome = posZ
938
	posDhome = posD
939
	
940
	while posZ ~= 1 do
941
		if posZ > 1 then 
942
			bot_down()
943
		elseif posZ < 1 then
944
			bot_up()
945
		end
946
	end
947
	while posD ~= 2 do
948
		bot_turnRight()
949
	end
950
	while posX ~= 0 do
951
		bot_forward()
952
	end
953
	if posY ~= 0 then
954
		if config[5] == 1 then
955
			while posD ~= 3 do
956
				bot_turnRight()
957
			end
958
		elseif config[5] == 3 then
959
			while posD ~= 1 do
960
				bot_turnRight()
961
			end
962
		end
963
		while posY ~= 0 do
964
			bot_forward()
965
		end
966
		while posD ~= 2 do
967
			bot_turnRight()
968
		end
969
	end
970
	bot_down()
971
end
972
973
function bot_leavehome()
974
	BotStatus = statusText[6]
975
	bot_up()
976
	if posYhome ~= 0 then
977
		while posD ~= config[5] do
978
			bot_turnRight()
979
		end
980
		while posY ~= posYhome do
981
			bot_forward()
982
		end
983
	end
984
	while posD ~= 0 do
985
		bot_turnRight()
986
	end
987
	
988
	while posX ~= posXhome do
989
		bot_forward()
990
	end
991
	while posZ ~= posZhome do
992
		if posZ > posZhome then 
993
			bot_down()
994
		elseif posZ < posZhome then
995
			bot_up()
996
		end
997
	end
998
	while posD ~= posDhome do
999
		bot_turnRight()
1000
	end
1001
	posXhome = 0
1002
	posYhome = 0
1003
	posZhome = 0
1004
	posDhome = 0
1005
	BotStatus = statusText[1]
1006
end
1007
1008
function bot_StatusFuel()
1009
	if 	turtle.getFuelLevel() < config[4] then
1010
		return true
1011
	else 
1012
		return false
1013
	end	
1014
end
1015
1016
function bot_StatusInventory()
1017
	if turtle.getItemCount(config[3]) > 0 then
1018
		return true
1019
	else 
1020
		return false
1021
	end	
1022
end
1023
1024
function bot_checkStatus()
1025
	if bot_StatusFuel() then
1026
		bot_home("Fuel")
1027
	elseif bot_StatusInventory() then
1028
		bot_home("Inv")
1029
	elseif cancelProgram then
1030
		bot_returnhome()
1031
		bot_dropStuff()
1032
		programEnd()
1033
	end
1034
end
1035
1036
function bot_dropStuffHome()
1037
	bot_checkMaxOreLimitHit()
1038
	BotStatus = statusText[7]
1039
	displayUpdate(false)
1040
	for i=firstDropSlot,16 do
1041
		turtle.select(i)
1042
		if turtle.getItemCount() > 0 then
1043
			while not turtle.drop() do
1044
				BotStatus = statusText[11]
1045
				displayUpdate(false)
1046
				term.clear()
1047
				term.setCursorPos(1,1)
1048
				print("Empty chest and press ENTER.")
1049
				io.read()
1050
				BotStatus = statusText[7]
1051
				displayUpdate(false)
1052
			end
1053
		end
1054
	end
1055
	turtle.select(firstDropSlot)
1056
	BotStatus = statusText[1]
1057
end
1058
1059
function bot_dropStuffEnder()
1060
	bot_checkMaxOreLimitHit()
1061
	BotStatus = statusText[7]
1062
	displayUpdate(false)
1063
	turtle.dig()
1064
	turtle.select(1)
1065
	turtle.place()
1066
	for i=firstDropSlot,16 do
1067
		turtle.select(i)
1068
		if turtle.getItemCount() > 0 then
1069
			while not turtle.drop() do
1070
				BotStatus = statusText[11]
1071
				displayUpdate(false)
1072
				term.clear()
1073
				term.setCursorPos(1,1)
1074
				print("Empty chest!")
1075
			end
1076
			BotStatus = statusText[7]
1077
			displayUpdate(false)
1078
		end
1079
	end	
1080
	turtle.select(1)
1081
	turtle.dig()
1082
	BotStatus = statusText[1]
1083
end
1084
1085
function bot_checkMaxOreLimitHit()
1086
	if maxOreLimitHit == true then
1087
		BotStatus = statusText[12]
1088
		displayUpdate(false)
1089
		term.clear()
1090
		term.setCursorPos(1,1)
1091
		print("Bot hit max Ore Limit("..maxOres.."Ores) for one vein, maybe there is a new material which needs to be added to the ignore list?")
1092
		print("Press ENTER to resume")
1093
		io.read()
1094
		maxOreLimitHit = false
1095
	end
1096
end
1097
1098
function bot_refuel(minimum)
1099
	BotStatus = statusText[2]
1100
	displayUpdate(false)
1101
	while turtle.getFuelLevel() < minimum do
1102
		advRefuel()
1103
	end
1104
	turtle.select(firstDropSlot)
1105
	BotStatus = statusText[1]
1106
end
1107
1108
function bot_home(reason)
1109
	if config[7] == 0 then
1110
		bot_returnhome()
1111
		bot_dropStuffHome()
1112
		bot_refuel(config[4])
1113
		bot_leavehome()
1114
	else
1115
		if reason == "Fuel" then
1116
			bot_returnhome()
1117
			bot_refuel(config[4])
1118
			bot_leavehome()
1119
		elseif reason == "Inv" then
1120
			bot_dropStuffEnder()
1121
		end
1122
	end
1123
end
1124
1125
function nextShaft()
1126
	bot_up()
1127
	posDforward = config[5]
1128
	turnDforward(posDforward)
1129
	for i=1,3 do
1130
		bot_digTunnel()
1131
		turtle.digDown()
1132
	end
1133
	posDforward = 0
1134
	turnDforward(posDforward)
1135
	bot_down()
1136
end
1137
1138
function skipShaft()
1139
	bot_up()
1140
	posDforward = config[5]
1141
	turnDforward(posDforward)
1142
	for i=1, skipShaftsNum do
1143
		for i=1,3 do
1144
			bot_digTunnel()
1145
			turtle.digDown()
1146
		end
1147
	end
1148
	posDforward = 0
1149
	turnDforward(posDforward)
1150
	bot_down()
1151
end
1152
1153
function programEnd()
1154
	endTime = os.clock()
1155
	differenceTime = endTime - startTime
1156
	differenceTime = math.floor (differenceTime)
1157
	BotStatus = differenceTime.."s / "..amountOreTotal.." Ores"
1158
	if fs.exists(filenames[3]) then fs.delete(filenames[3]) end
1159
	displayUpdate(false)
1160
	print("END")
1161
end
1162
1163
function programStop()
1164
	while true do
1165
		displayUpdate(false)
1166
		print("STOP")
1167
		sleep(5)
1168
	end
1169
end
1170
1171
function programTerminate()
1172
	print("Terminated")
1173
	sleep(1)
1174
	os.reboot()
1175
end
1176
1177
function turnDforward(pos)
1178
	while posD ~= pos do
1179
		if posD == 0 and pos == 1 then 
1180
			bot_turnRight()
1181-
	bot_dig()
1181+
1182
			bot_turnLeft()
1183
		elseif posD == 1 and pos == 0 then 
1184
			bot_turnLeft()
1185
		elseif posD == 1 and pos == 2 then 
1186
			bot_turnRight()
1187
		elseif posD == 2 and pos == 1 then 
1188
			bot_turnLeft()
1189
		elseif posD == 2 and pos == 3 then 
1190
			bot_turnRight()
1191
		elseif posD == 3 and pos == 2 then 
1192
			bot_turnLeft()
1193
		elseif posD == 3 and pos == 0 then 
1194
			bot_turnRight()
1195
		else
1196
			bot_turnRight()
1197
		end
1198
	end
1199-
	bot_dig()
1199+
1200
1201
function bot_GPSreboot()
1202
	if bot_getGPSpos() then	
1203
		if GPSfile() then
1204
			if not bot_checkGPShome() then 
1205
				bot_returnhomeGPS()
1206
				createStartup(false)
1207
				if fs.exists(filenames[3]) then fs.delete(filenames[3]) end
1208
				BotStatus = statusText[8]
1209
				programStop()
1210
			end
1211
			createStartup(false)
1212
			if fs.exists(filenames[3]) then fs.delete(filenames[3]) end
1213
			BotStatus = statusText[9]
1214
			programStop()
1215
		else
1216
			main()
1217
		end
1218
	else
1219
		BotStatus = statusText[10]
1220
		print("No GPS found!")
1221
		print("To start without GPS press ENTER.")
1222
		io.read()
1223
		createStartup(false)
1224
		if fs.exists(filenames[3]) then fs.delete(filenames[3]) end
1225
		main()
1226
	end
1227
end
1228
1229
function createStartup(autostart)
1230
	if fs.exists("startup") then fs.delete("startup") end
1231
	L1 = "fs.delete('botminer')"
1232
	L2 = "shell.run('pastebin','get','q354743w','botminer')"
1233
	L3 = "shell.run('botminer')"
1234
1235
	startup = fs.open("startup", "w")
1236
	startup.writeLine(L1)
1237
	startup.writeLine(L2)
1238
	if autostart then
1239
		startup.writeLine(L3)
1240
	end
1241
	startup.close()
1242
end
1243
1244
function advRefuel()
1245
	local neededLavaBuckets = (turtle.getFuelLimit() - turtle.getFuelLevel()) / 1000
1246
	local neededCoal		= (turtle.getFuelLimit() - turtle.getFuelLevel()) / 80
1247
	local neededCoalStacks  = neededCoal / 64
1248
	turtle.select(firstDropSlot)
1249-
		bot_digDown()
1249+
1250
	term.setCursorPos(1,1)
1251
	print("Refuel Overview")
1252
	print("Fuel Level: "..turtle.getFuelLevel().." / "..turtle.getFuelLimit())
1253
	print("-------------------------------------")
1254
	print("Needed Material for full refuel:     ")
1255
	print("Lava Buckets   : ".. neededLavaBuckets)
1256
	print("Coal / Charcoal: ".. neededCoal.." ("..neededCoalStacks.." Stacks)")
1257
	print("-------------------------------------")
1258
	print("Put fuel in any slot and press ENTER.")
1259
	io.read()
1260
	for i=firstDropSlot, 16 do
1261
		if turtle.getFuelLevel() >= turtle.getFuelLimit() then
1262
			break
1263-
			bot_digDown()
1263+
1264
		turtle.select(i)
1265
		turtle.refuel()
1266
		term.clear()
1267
		term.setCursorPos(1,1)
1268
		print("Fuel: "..turtle.getFuelLevel().." / "..turtle.getFuelLimit())
1269
	end
1270
	print("Remove Buckets and Press ENTER.")
1271
	io.read()
1272
end
1273
1274
function bot_EnderChest()
1275
	while turtle.getItemCount(1) ~= 1 do
1276
		term.clear()
1277
		term.setCursorPos(1,1)
1278
		print("Put EnderChest in first slot and press ENTER.")
1279
		io.read()
1280
	end
1281
	firstDropSlot = 2
1282
end
1283
1284
function main()
1285
	if config[7] == 1 then bot_EnderChest() end
1286
	advRefuel()
1287
	bot_refuel(config[4])
1288
	startTime = os.clock()
1289
	if skipShafts then
1290
		skipShaft()
1291
		skipShafts = false
1292
		startShaft = skipShaftsNum + 1
1293
	end
1294
	for x=startShaft, config[2] do
1295
		shaft = x
1296
		if shaft > skipShaftsNum then
1297
			for i=1, config[1] do
1298
				displayUpdate(false)
1299
				bot_checkStatus()
1300
				bot_digTunnel()
1301
				if bot_checkoresUp() or bot_checkoresDown() or bot_checkoresRight() or bot_checkoresLeft() then
1302
					bot_mineOres() 
1303
				end
1304
			end
1305
			if bot_checkoresFornt() then
1306
				bot_mineOres() 
1307
			end
1308
			posDforward = 2
1309
			bot_up()
1310
			if bot_checkoresFornt() or bot_checkoresRight() or bot_checkoresLeft() then
1311
				bot_mineOres() 
1312
			end
1313
			turnDforward(posDforward)
1314
			while posX > 0 do
1315
				displayUpdate(false)
1316
				bot_checkStatus()
1317
				bot_returnTunnel()
1318
				if bot_checkoresUp() or bot_checkoresDown() or bot_checkoresRight() or bot_checkoresLeft() then
1319
					bot_mineOres() 
1320
				end
1321
			end
1322
			bot_down()
1323
			displayUpdate(false)
1324
		end
1325
		if shaft < config[2] then
1326
			nextShaft()
1327
		end
1328
	end
1329
	if config[7] == 1 then bot_dropStuffEnder() end
1330
	bot_returnhome()
1331
	if config[7] == 0 then bot_dropStuffHome() end	
1332
	programEnd()
1333
end
1334
1335
function detectENTER()
1336
        local sEvent, param = os.pullEvent("key")
1337
        if sEvent == "key" then
1338
            if param == 28 then
1339
                print("Enter detected")
1340
            end
1341
        end
1342
end
1343
1344
function RebootDisplayUpdate()
1345
	while true do
1346
		displayUpdate(true)
1347
		print("Press ENTER.")
1348
		sleep(2)
1349
	end
1350
end
1351
1352
if useArgs() then
1353
	if programInspect then
1354
		while true do 
1355
			local has_block, data = turtle.inspect()
1356
			if has_block then
1357
				print(data.name)
1358
			else
1359
				print("No block")
1360
			end
1361
			sleep(0.5)
1362
		end
1363
	end
1364
	if programReset then
1365
		for i=1, #filenames do
1366
			if fs.exists(filenames[i]) then fs.delete(filenames[i]) end
1367
		end
1368
	end
1369
	wlanDisplay()
1370
	configFile()
1371
	if config[6] == 1 and fs.exists(filenames[3]) then
1372
		bot_GPSreboot() --reboot script if GPS is used
1373
	else 
1374
		if DisplaySavefile() then
1375
			DisplayDataTable[8] =  "X-"..DisplayDataTable[8]
1376
			parallel.waitForAny(RebootDisplayUpdate,detectENTER)
1377
			createStartup(false)
1378
			if fs.exists(filenames[4]) then fs.delete(filenames[4]) end
1379
			programTerminate()
1380
		end
1381
		main()
1382
	end
1383
end