-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code
100 lines (88 loc) · 1.55 KB
/
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
local tArgs = { ... }
if #tArgs ~= 1 then
print( "Usage: tunnel <length>" )
return
end
-- Mine in a quarry pattern until we hit something we can't dig
local length = tonumber( tArgs[1] )
if length < 1 then
print( "Tunnel length must be positive" )
return
end
local depth = 0
local collected = 0
local function collect()
collected = collected + 1
if math.fmod(collected, 25) == 0 then
print( "Mined "..collected.." blocks." )
end
end
local function tryDig()
while turtle.dig() do
collect()
sleep(0.5)
if not turtle.detect() then
return true
end
end
return not turtle.detect()
end
local function tryDigUp()
while turtle.digUp() do
collect()
sleep(0.5)
if not turtle.detectUp() then
return true
end
end
return not turtle.detectUp()
end
print( "Tunnelling..." )
for n=1,length do
tryDig()
turtle.forward()
tryDigUp()
turtle.turnLeft()
tryDig()
turtle.up()
tryDig()
turtle.turnRight()
turtle.turnRight()
tryDig()
turtle.up()
turtle.turnleft()
tryDig()
turtle.turnRight()
turtle.turnRight()
tryDig()
turtle.down()
turtle.done()
tryDig()
turtle.turnLeft()
if n<length then
tryDig()
if not turtle.forward() then
print( "Aborting Tunnel." )
break
end
else
print( "Tunnel complete." )
end
end
--[[
print( "Returning to start..." )
-- Return to where we started
turtle.turnLeft()
turtle.turnLeft()
while depth > 0 do
if turtle.forward() then
depth = depth - 1
else
turtle.dig()
end
end
turtle.turnRight()
turtle.turnRight()
]]
print( "Tunnel complete." )
print( "Mined "..collected.." blocks total." )