-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminer.lua
More file actions
337 lines (290 loc) · 5.84 KB
/
miner.lua
File metadata and controls
337 lines (290 loc) · 5.84 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
function shaft(depth)
turtle.forward()
suc = true
count = depth
count2 = 0
while count > 0 and suc do
turtle.digDown()
suc = turtle.down()
count = count - 1
count2 = count2 + 1
end
while count2 > 0 do
turtle.up()
end
turtle.back()
turtle.turnRight()
emptyInventory()
turtle.turnLeft()
end
function emptyInventory()
for i = 1, 16 do
turtle.select(i)
if not turtle.drop() then
print("External Drop Off inverntory full")
return false
end
end
return true
end
function shortTunnel(length)
count = length
mvDigFUD(length)
tr()
tr()
turtle.down()
turtle.select(1)
while count > 0 do
while turtle.detect() do
turtle.dig()
os.sleep(0.5)
end
if not turtle.detectDown() then
turtle.placeDown()
end
turtle.forward()
count = count - 1
end
end
function invFull()
for i = 1,16 do
if turtle.getItemCount(i) == 0 then
return false
end
end
return true
end
function cleanMove(tx,ty,tz,rot)
--target coords in followed by optional rotation 1=x+aligned 2=z+aligned 3=x- 4=z-
local x, y, z = gps.locate()
rot = rot or getRotation()
local dx = tx - x
local dy = ty - y
local dz = tz - z
if dz > 0 then
for i = 1, dz do
turtle.up()
end
elseif dz < 0 then
for i = 1, Math.abs(dz) do
turtle.down()
end
end
if dx > 0 then
turnTo(1)
mvF(dx)
elseif dx < 0 then
turnTo(3)
mvF(Math.abs(dx))
end
if dy > 0 then
turnTo(2)
mvF(dy)
elseif dy < 0 then
turnTo(4)
mvF(Math.abs(dy))
end
turnTo(rot)
--move success check
x, y, z = gps.locate()
if x == tx and y == ty and z == tz then
return true
else
print("Clean move failed")
return false
end
end
function getRotation()
x,y,z = gps.locate()
turtle.forward()
x2,y2,z2 = gps.locate()
os.sleep(0.5)
xf = x2 - x
yf = y2 - y
turtle.back()
if(xf == 1) then
return 1
end
if(xf == -1) then
return 3
end
if(yf == 1) then
return 2
end
if(yf == -1) then
return 4
end
print("Rotation calculation error")
return 0
end
function turnTo(trot, rot)
rot = rot or mastrot
m = trot - rot
if m > 0 then
if m == 3 then
tl()
else
while m ~= 0 do
tr()
m = m - 1
end
end
elseif m < 0 then
if m == 3 then
tr()
else
while m ~= 0 do
tl()
m = m + 1
end
end
end
end
function mvF(count)
count = count or 1
for i=1,count do
turtle.forward()
end
end
function mvB(count)
count = count or 1
for i=1,count do
turtle.back()
end
end
function mvDigF(count)
count = count or 1
for i=1,count do
while turtle.detect() do
turtle.dig()
os.sleep(.2)
end
turtle.forward()
end
end
function mvDigFUD(count)
count = count or 1
for i=1,count do
while turtle.detect() do
turtle.dig()
os.sleep(.1)
end
turtle.forward()
while turtle.detectUp() do
turtle.digUp()
os.sleep(.1)
end
while turtle.detectDown() do
turtle.digDown()
os.sleep(.1)
end
end
end
function descendDig(count)
count = count or 1
for i=1,count do
turtle.digDown()
os.sleep(.1)
turtle.down()
end
end
function rev()
tr()
tr()
end
function tl()
turtle.turnLeft()
mastrot = mastrot - 1
if mastrot == 0 then
mastrot = 4
end
end
function tr()
turtle.turnRight()
mastrot = mastrot + 1
if mastrot == 5 then
mastrot = 1
end
end
function qInvControl()
if invFull() then
local crot = mastrot
local cx, cy, cz = gps.locate()
turtle.up()
turtle.up()
cleanMove(dropx,dropy,dropz,droprot)
emptyInventory()
cleanMove(cx,cy,cz,crot)
turtle.down()
turtle.down()
end
end
function quarry(l,w,d)
local sx, sy, sz = gps.locate()
local srot = mastrot()
--set target y and make sure its 2 above bedrock
fy = sy - d
if fy < 2 then
fy = 2
end
--establish dropoff
turtle.forward()
tr()
turtle.forward()
tr()
dropx, dropy, dropz = gps.locate()
droprot = mastrot
tr()
turtle.forward()
tr()
turtle.back()
rev()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.down()
local cx, cy, cz = gps.locate()
while cy > fy do
descendDig(2)
cx, cy, cz = gps.locate()
if cy < 2 then
turtle.up()
end
lw = w
alt = 1
for i=0,w do
if alt == 1 then
mvDigFUD(l-1)
tr()
mvDigFUD()
tr()
alt = 2
qInvControl()
cx, cy, cz = gps.locate()
elseif alt == 2 then
mvDigFUD(l-1)
tl()
mvDigFUD()
tl()
alt = 1
qInvControl()
cx, cy, cz = gps.locate()
end
end
end
cleanMove(sx,sy+1,sz,srot)
end
function nav(x, y, z, rot)
--path finding/exploration....Someday
end
function slaveMiner()
end
function mineNav()
end
function mineInvControl()
end
droprot = 0
dropx = 0
dropy = 0
dropz = 0
mastrot = getRotation()