-
Notifications
You must be signed in to change notification settings - Fork 3
/
stripmine.cc.lua
263 lines (228 loc) · 5.01 KB
/
stripmine.cc.lua
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
local tArgs = { ... }
if #tArgs ~= 2 and #tArgs ~= 3 then
print( "Usage: stripmine <length> <lanes> [direction]" )
return
end
local len = tonumber( tArgs[1] )
local lanes = tonumber( tArgs[2] )
local direction = 0
if #tArgs == 3 then
direction = tonumber( tArgs[3] )
if direction < 1 then
direction = 0
else
direction = 1
end
end
if len < 1 then
print( "Strip mine length must be positive!" )
return
end
if lanes < 1 then
print( "Strip mine lanes must be positive!" )
return
end
local depth = 0
local unloaded = 0
local collected = 0
local xPos,zPos = 0,0
local xDir,zDir = 0,1
local stripMine -- Filled in further down
local checkForVein
local function turnLeft()
turtle.turnLeft()
xDir, zDir = -zDir, xDir
end
local function turnRight()
turtle.turnRight()
xDir, zDir = zDir, -xDir
end
local function compareValuableFront()
turtle.select(1)
local bValuable1 = not turtle.compare()
turtle.select(2)
local bValuable2 = not turtle.compare()
turtle.select(3)
local bValuable3 = not turtle.compare()
turtle.select(4)
local bValuable4 = not turtle.compare()
turtle.select(5)
local bValuable5 = not turtle.compare()
turtle.select(6)
local bValuable6 = not turtle.compare()
turtle.select(7)
local bValuable7 = not turtle.compare()
turtle.select(8)
local bValuable8 = not turtle.compare()
return bValuable1 and bValuable2 and bValuable3 and bValuable4 and bValuable5 and bValuable6 and bValuable7 and bValuable8
end
local function compareValuableTop()
turtle.select(1)
local bValuable1 = not turtle.compareUp()
turtle.select(2)
local bValuable2 = not turtle.compareUp()
turtle.select(3)
local bValuable3 = not turtle.compareUp()
turtle.select(4)
local bValuable4 = not turtle.compareUp()
turtle.select(5)
local bValuable5 = not turtle.compareUp()
turtle.select(6)
local bValuable6 = not turtle.compareUp()
turtle.select(7)
local bValuable7 = not turtle.compareUp()
turtle.select(8)
local bValuable8 = not turtle.compareUp()
return bValuable1 and bValuable2 and bValuable3 and bValuable4 and bValuable5 and bValuable6 and bValuable7 and bValuable8
end
local function compareValuableBottom()
turtle.select(1)
local bValuable1 = not turtle.compareDown()
turtle.select(2)
local bValuable2 = not turtle.compareDown()
turtle.select(3)
local bValuable3 = not turtle.compareDown()
turtle.select(4)
local bValuable4 = not turtle.compareDown()
turtle.select(5)
local bValuable5 = not turtle.compareDown()
turtle.select(6)
local bValuable6 = not turtle.compareDown()
turtle.select(7)
local bValuable7 = not turtle.compareDown()
turtle.select(8)
local bValuable8 = not turtle.compareDown()
return bValuable1 and bValuable2 and bValuable3 and bValuable4 and bValuable5 and bValuable6 and bValuable7 and bValuable8
end
local function checkForVein(mode)
if mode ~= 4 then
turnLeft()
if turtle.detect() then
if compareValuableFront() then
if turtle.dig() then
while not turtle.forward() do
turtle.dig()
end
checkForVein(1)
end
end
end
turnRight()
if turtle.detect() then
if compareValuableFront() then
if turtle.dig() then
while not turtle.forward() do
turtle.dig()
end
checkForVein(1)
end
end
end
end
if turtle.detectUp() then
if compareValuableTop() then
if turtle.digUp() then
while not turtle.up() do
turtle.digUp()
end
checkForVein(2)
end
end
end
if turtle.detectDown() then
if compareValuableBottom() then
if turtle.digDown() then
turtle.down()
checkForVein(3)
end
end
end
if mode ~= 4 then
turnRight()
if turtle.detect() then
if compareValuableFront() then
if turtle.dig() then
while not turtle.forward() do
turtle.dig()
end
checkForVein(1)
end
end
end
turnLeft()
if mode == 1 then
turtle.back()
elseif mode == 2 then
turtle.down()
elseif mode == 3 then
while not turtle.up() do
turtle.digUp()
end
end
end
end
local function unloadItems()
for i = 9, 16 do
turtle.select(i)
turtle.drop()
end
end
local function returnToStart(curPos, direction)
print ( "Returning to unload" )
for n = 1, len do
turtle.back()
end
if direction == 0 then
turnLeft()
else
turnRight()
end
for n = 1, curPos do
turtle.forward()
end
unloadItems()
if direction == 0 then
turnRight()
else
turnLeft()
end
end
local function shiftStrip(curPos, direction)
if curPos > 0 then
if direction == 0 then
turnRight()
else
turnLeft()
end
for n = 1, curPos do
while not turtle.forward() do
turtle.dig()
end
if n > curPos - 3 and n <= curPos then
checkForVein(4)
end
end
if direction == 0 then
turnLeft()
else
turnRight()
end
end
end
local function stripMine(len, lanes, direction)
local curPos = 0
for i = 1, lanes do
print(direction)
shiftStrip(curPos, direction)
for j = 1, len do
while not turtle.forward() do
turtle.dig()
end
checkForVein(0)
end
returnToStart(curPos, direction)
curPos = curPos + 3
end
print( "Done mining." )
end
stripMine(len, lanes, direction)