SHOW:
|
|
- or go back to the newest paste.
1 | - | local tArgs = { ... } |
1 | + | local depth = ll |
2 | - | if #tArgs ~= 1 then |
2 | + | |
3 | - | print( "Usage: tunnel <length>" ) |
3 | + | |
4 | - | return |
4 | + | |
5 | collected = collected + 1 | |
6 | if math.fmod(collected, 25) == 0 then | |
7 | - | -- Mine in a quarry pattern until we hit something we can't dig |
7 | + | |
8 | - | local length = tonumber( tArgs[1] ) |
8 | + | |
9 | - | if length < 1 then |
9 | + | |
10 | - | print( "Tunnel length must be positive" ) |
10 | + | |
11 | - | return |
11 | + | |
12 | while turtle.detect() do | |
13 | if turtle.dig() then | |
14 | - | local depth = length |
14 | + | |
15 | sleep(0.5) | |
16 | else | |
17 | return false | |
18 | end | |
19 | end | |
20 | return true | |
21 | end | |
22 | ||
23 | local function tryDigUp() | |
24 | while turtle.detectUp() do | |
25 | if turtle.digUp() then | |
26 | collect() | |
27 | sleep(0.5) | |
28 | else | |
29 | return false | |
30 | end | |
31 | end | |
32 | return true | |
33 | end | |
34 | ||
35 | local function tryDigDown() | |
36 | while turtle.detectDown() do | |
37 | if turtle.digDown() then | |
38 | collect() | |
39 | sleep(0.5) | |
40 | else | |
41 | return false | |
42 | end | |
43 | end | |
44 | return true | |
45 | end | |
46 | ||
47 | local function refuel() | |
48 | local fuelLevel = turtle.getFuelLevel() | |
49 | if fuelLevel == "unlimited" or fuelLevel > 0 then | |
50 | return | |
51 | end | |
52 | ||
53 | local function tryRefuel() | |
54 | for n=1,16 do | |
55 | if turtle.getItemCount(n) > 0 then | |
56 | turtle.select(n) | |
57 | if turtle.refuel(1) then | |
58 | turtle.select(1) | |
59 | return true | |
60 | end | |
61 | end | |
62 | end | |
63 | turtle.select(1) | |
64 | return false | |
65 | end | |
66 | ||
67 | if not tryRefuel() then | |
68 | print( "Add more fuel to continue." ) | |
69 | while not tryRefuel() do | |
70 | sleep(1) | |
71 | end | |
72 | print( "Resuming Tunnel." ) | |
73 | end | |
74 | end | |
75 | ||
76 | local function tryUp() | |
77 | refuel() | |
78 | while not turtle.up() do | |
79 | if turtle.detectUp() then | |
80 | if not tryDigUp() then | |
81 | return false | |
82 | end | |
83 | elseif turtle.attackUp() then | |
84 | collect() | |
85 | else | |
86 | sleep( 0.5 ) | |
87 | end | |
88 | end | |
89 | return true | |
90 | end | |
91 | ||
92 | local function tryBack() | |
93 | refuel() | |
94 | while not turtle.back() do | |
95 | if turtle.detect() then | |
96 | if not tryDig() then | |
97 | return false | |
98 | end | |
99 | elseif turtle.attack() then | |
100 | collect() | |
101 | else | |
102 | sleep( 0.5 ) | |
103 | end | |
104 | end | |
105 | return true | |
106 | end | |
107 | ||
108 | local function tryDown() | |
109 | refuel() | |
110 | while not turtle.down() do | |
111 | if turtle.detectDown() then | |
112 | if not turtle.digDown() then | |
113 | return false | |
114 | end | |
115 | elseif turtle.attackDown() then | |
116 | collect() | |
117 | else | |
118 | sleep( 0.5 ) | |
119 | end | |
120 | end | |
121 | return true | |
122 | end | |
123 | ||
124 | local function tryForward() | |
125 | refuel() | |
126 | while not turtle.forward() do | |
127 | if turtle.detect() then | |
128 | if not tryDig() then | |
129 | return false | |
130 | end | |
131 | elseif turtle.attack() then | |
132 | collect() | |
133 | else | |
134 | sleep( 0.5 ) | |
135 | end | |
136 | end | |
137 | return true | |
138 | end | |
139 | print("Wie lang ist der Bereich?") | |
140 | ll=io.read() | |
141 | print("Wie tief ist der Bereich") | |
142 | tt=io.read() | |
143 | - | for n=1,length do |
143 | + | tt=tt-1 |
144 | - | tryDigUp() |
144 | + | |
145 | print( "Tunnelling..." ) | |
146 | - | for x1=1,7 do |
146 | + | |
147 | - | tryDig() |
147 | + | for n=1,ll do |
148 | for x1=1,tt do | |
149 | tryDigDown() | |
150 | tryDown() | |
151 | end | |
152 | - | tryForward() |
152 | + | |
153 | - | for x2=1,7 do |
153 | + | tryDig() |
154 | - | tryDig() |
154 | + | tryForward() |
155 | for x2=1,tt do | |
156 | tryDigUp() | |
157 | - | tryBack() |
157 | + | |
158 | end | |
159 | tryBack() | |
160 | - | if n<length then |
160 | + | |
161 | - | tryDig() |
161 | + | tryDig() |
162 | - | if not tryForward() then |
162 | + | tryForward() |
163 | - | print( "Aborting Tunnel." ) |
163 | + | |
164 | - | break |
164 | + | -- if n < ll then |
165 | -- tryDig() | |
166 | - | else |
166 | + | -- if not tryForward() then |
167 | - | print( "Tunnel complete." ) |
167 | + | -- print( "Aborting Tunnel." ) |
168 | -- break | |
169 | -- end | |
170 | -- else | |
171 | -- print( "Tunnel complete." ) | |
172 | -- end | |
173 | ||
174 | end | |
175 | ||
176 | ||
177 | print( "Returning to start..." ) | |
178 | - | tryUp() |
178 | + | |
179 | - | j = 0 |
179 | + | |
180 | turtle.turnLeft() | |
181 | turtle.turnLeft() | |
182 | while depth > 1 do | |
183 | - | j = j+1 |
183 | + | |
184 | - | if j == 5 then |
184 | + | |
185 | - | turtle.select(15) |
185 | + | else |
186 | - | turtle.placeDown() |
186 | + | |
187 | - | end |
187 | + | |
188 | - | else |
188 | + | |
189 | turtle.turnRight() | |
190 | turtle.turnRight() | |
191 | ||
192 | - | tryDown() |
192 | + | |
193 | print( "Tunnel complete." ) | |
194 | print( "Mined "..collected.." items total." ) |