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