View difference between Paste ID: Fh6snQKU and bfeApc3K
SHOW: | | - or go back to the newest paste.
1-
function place(curSlot)
1+
sizeX = 1
2-
  if turtle.getItemCount(curSlot) == 0 then
2+
sizeY = 1
3-
    for curSlot=curSlot,16 do
3+
sizeZ = 1
4-
      if turtle.getItemCount(curSlot) > 0 then
4+
posX = 1
5-
        break
5+
posY = 1
6-
      end
6+
posZ = 0
7-
    end
7+
torchSpace = 0
8
torchCount = 0
9-
  turtle.place()
9+
reverse = false
10-
  
10+
finished = false
11-
  return curSlot
11+
function refreshDisplay()
12
shell.run("clear")
13
print("")
14-
function checkFuel(curSlot)
14+
print("Tunnel Size:   " .. sizeX .. "x" .. sizeY)
15-
  if turtle.getFuelLevel() < 1 then
15+
print("Target Depth:  " .. sizeZ)
16-
    turtle.select(1)
16+
if torchSpace > 0 then
17-
    turtle.refuel(1)
17+
  print("Torch Spacing: " .. torchSpace)
18-
    turtle.select(curSlot)
18+
else
19
  print("Torch Spacing: n/a")
20
end
21
print("")
22-
function down(curSlot)
22+
print("Current Depth: " .. posZ)sizeX = 1
23-
  checkFuel(curSlot)
23+
sizeY = 1
24-
  return turtle.down()
24+
sizeZ = 1
25
posX = 1
26
posY = 1
27-
function up(curSlot)
27+
posZ = 0
28-
  checkFuel(curSlot)
28+
torchSpace = 0
29-
  return turtle.up()
29+
torchCount = 0
30-
end  
30+
reverse = false
31
finished = false
32-
local depth = 0
32+
function refreshDisplay()
33
shell.run("clear")
34-
local curSlot = 2
34+
print("")
35-
turtle.select(2)
35+
print("Tunnel Size:   " .. sizeX .. "x" .. sizeY)
36
print("Target Depth:  " .. sizeZ)
37-
turtle.digDown()
37+
if torchSpace > 0 then
38-
while turtle.down() do
38+
  print("Torch Spacing: " .. torchSpace)
39-
  for turn=1,4 do
39+
else
40-
    curSlot = place(curSlot)
40+
  print("Torch Spacing: n/a")
41-
    turtle.turnRight()
41+
42
print("")
43-
  turtle.digDown()
43+
print("Current Depth: " .. posZ)
44-
  depth = depth + 1
44+
print("Fuel Level:      " .. turtle.getFuelLevel())
45
print("Torch Count:   " .. turtle.getItemCount(1))
46
print("")
47-
for u = 1,depth do
47+
print("Progress:          " .. getProgress() .. "%")
48-
  up()
48+
49
function round(n)
50
if n >= 0 then
51
  return math.floor(n + .5)
52
else
53
  return math.ceil(ns - .5)
54
end
55
end
56
function getProgress()
57
if finished then
58
  return 100
59
elseif posZ <= 0 then
60
  return 0
61
else
62
  return round(((posZ - 1) / sizeZ) * 100)
63
end
64
end
65
function init()
66
shell.run("clear")
67
-- Width
68
print("")
69
io.write("How wide do you want the tunnel? ")
70
sizeX = io.read()
71
if tonumber(sizeX) ~= nil then
72
  sizeX = tonumber(sizeX)
73
else
74
  print("")
75
  print("You have entered an invalid width.")
76
  print("Terminating")
77
  return false
78
end
79
-- Height
80
print("")
81
io.write("How tall do you want the tunnel? ")
82
sizeY = io.read()
83
if tonumber(sizeY) ~= nil then
84
  sizeY = tonumber(sizeY)
85
else
86
  print("")
87
  print("You have entered an invalid height.")
88
  print("Terminating")
89
  return false
90
end
91
-- Depth
92
print("")
93
io.write("How deep do you want the tunnel? ")
94
sizeZ = io.read()
95
if tonumber(sizeZ) ~= nil then
96
  sizeZ = tonumber(sizeZ)
97
else
98
  print("")
99
  print("You have entered an invalid depth.")
100
  print("Terminating")
101
  return false
102
end
103
-- Torch Spacing
104
print("")
105
io.write("How often would you like to place torches? ")
106
torchSpace = io.read()
107
if tonumber(torchSpace) ~= nil then
108
  torchSpace = tonumber(torchSpace)
109
  torchCount = 1
110
else
111
  torchSpace = 0
112
end
113
return true
114
end
115
function refuel(turns)
116
if turtle.getFuelLevel() < turns then
117
  for p = 1, 16, 1 do
118
   if turtle.getItemCount(p) > 0 then
119
        turtle.select(p)
120
        if turtle.refuel(1) then
121
         break
122
        end
123
   end
124
  end
125
end
126
end
127
function returnHome()
128
if posY > 1 then
129
  refuel(posY - 1)
130
  for p = posY - 1, 1, -1 do
131
   if turtle.detectUp() then
132
        turtle.digUp()
133
   end
134
   turtle.up()
135
  end
136
end
137
if posX > 1 then
138
  refuel(posX - 1)
139
  turtle.turnLeft()
140
  for p = posX - 1, 1, -1 do
141
   if turtle.detect() then
142
        turtle.dig()
143
   end
144
   turtle.forward()
145
  end
146
  turtle.turnRight()
147
end
148
for p = posZ, 1, -1 do
149
  turtle.back()
150
end
151
end
152
function shiftPos()
153
refuel(1)
154
if posX == 1 and sizeX > 1 then
155
  turtle.turnRight()
156
elseif posX == sizeX and sizeX > 1 then
157
  turtle.turnLeft()
158
end
159
if posZ < sizeZ or (posX > 1 and posX < sizeX) or (posX == 1 and not reverse and sizeX > 1) or (posX == sizeX and reverse and sizeX > 1) then
160
  if turtle.detect() then
161
   turtle.dig()
162
  end
163
  turtle.forward()
164
  if reverse then
165
   posX = posX - 1
166
   if posX == 0 then
167
        posX = 1
168
        posZ = posZ + 1
169
        if torchSpace > 0 and torchCount == torchSpace then
170
         torchCount = 1
171
        elseif torchSpace > 0 then
172
         torchCount = torchCount + 1
173
        end
174
        reverse = false
175
   end
176
  else
177
   posX = posX + 1
178
   if posX > sizeX then
179
        posX = sizeX
180
        posZ = posZ + 1
181
        if torchSpace > 0 and torchCount == torchSpace then
182
         torchCount = 1
183
        elseif torchSpace > 0 then
184
         torchCount = torchCount + 1
185
        end
186
        reverse = true
187
   end
188
  end
189
end
190
end
191
function sliver()
192
if posY == 1 then
193
  refuel(sizeY - posY)
194
  while posY < sizeY do
195
   if turtle.detectDown() then
196
        turtle.digDown()
197
   end
198
   turtle.down()
199
   posY = posY + 1
200
  end
201
  shiftPos()
202
elseif posY == sizeY then
203
  refuel(posY - 1)
204
  while posY > 1 do
205
   if turtle.detectUp() then
206
        turtle.digUp()
207
   end
208
   turtle.up()
209
   posY = posY - 1
210
   if torchCount == 1 then
211
        if posY == sizeY - 1 and ((not reverse and posX == 2) or (reverse and posX == 1)) then
212
         turtle.select(1)
213
         turtle.placeDown()
214
        end
215
   end
216
  end
217
218
  shiftPos()
219
else
220
  print("Unexpected position (X=" .. posX .. ", Y=" .. posY .. ", Z=" .. posZ .. ")")
221
  returnHome()
222
end
223
end
224
function slice()
225
for p = 1, sizeX, 1 do
226
  sliver()
227
  refreshDisplay()
228
end
229
end
230
if init() then
231
refuel(1)
232
refreshDisplay()
233
if turtle.detect() then
234
  turtle.dig()
235
end
236
turtle.forward()
237
posZ = 1
238
refreshDisplay()
239
for p = 1, sizeZ, 1 do
240
  slice()
241
end
242
finished = true
243
refreshDisplay()
244
returnHome()
245
end
246
sizeY = io.read()
247
if tonumber(sizeY) ~= nil then
248
  sizeY = tonumber(sizeY)
249
else
250
  print("")
251
  print("You have entered an invalid height.")
252
  print("Terminating")
253
  return false
254
end
255
-- Depth
256
print("")
257
io.write("How deep do you want the tunnel? ")
258
sizeZ = io.read()
259
if tonumber(sizeZ) ~= nil then
260
  sizeZ = tonumber(sizeZ)
261
else
262
  print("")
263
  print("You have entered an invalid depth.")
264
  print("Terminating")
265
  return false
266
end
267
-- Torch Spacing
268
print("")
269
io.write("How often would you like to place torches? ")
270
torchSpace = io.read()
271
if tonumber(torchSpace) ~= nil then
272
  torchSpace = tonumber(torchSpace)
273
  torchCount = 1
274
else
275
  torchSpace = 0
276
end
277
return true
278
end
279
function refuel(turns)
280
if turtle.getFuelLevel() < turns then
281
  for p = 1, 16, 1 do
282
   if turtle.getItemCount(p) > 0 then
283
        turtle.select(p)
284
        if turtle.refuel(1) then
285
         break
286
        end
287
   end
288
  end
289
end
290
end
291
function returnHome()
292
if posY > 1 then
293
  refuel(posY - 1)
294
  for p = posY - 1, 1, -1 do
295
   if turtle.detectUp() then
296
        turtle.digUp()
297
   end
298
   turtle.up()
299
  end
300
end
301
if posX > 1 then
302
  refuel(posX - 1)
303
  turtle.turnLeft()
304
  for p = posX - 1, 1, -1 do
305
   if turtle.detect() then
306
        turtle.dig()
307
   end
308
   turtle.forward()
309
  end
310
  turtle.turnRight()
311
end
312
for p = posZ, 1, -1 do
313
  turtle.back()
314
end
315
end
316
function shiftPos()
317
refuel(1)
318
if posX == 1 and sizeX > 1 then
319
  turtle.turnRight()
320
elseif posX == sizeX and sizeX > 1 then
321
  turtle.turnLeft()
322
end
323
if posZ < sizeZ or (posX > 1 and posX < sizeX) or (posX == 1 and not reverse and sizeX > 1) or (posX == sizeX and reverse and sizeX > 1) then
324
  if turtle.detect() then
325
   turtle.dig()
326
  end
327
  turtle.forward()
328
  if reverse then
329
   posX = posX - 1
330
   if posX == 0 then
331
        posX = 1
332
        posZ = posZ + 1
333
        if torchSpace > 0 and torchCount == torchSpace then
334
         torchCount = 1
335
        elseif torchSpace > 0 then
336
         torchCount = torchCount + 1
337
        end
338
        reverse = false
339
   end
340
  else
341
   posX = posX + 1
342
   if posX > sizeX then
343
        posX = sizeX
344
        posZ = posZ + 1
345
        if torchSpace > 0 and torchCount == torchSpace then
346
         torchCount = 1
347
        elseif torchSpace > 0 then
348
         torchCount = torchCount + 1
349
        end
350
        reverse = true
351
   end
352
  end
353
end
354
end
355
function sliver()
356
if posY == 1 then
357
  refuel(sizeY - posY)
358
  while posY < sizeY do
359
   if turtle.detectDown() then
360
        turtle.digDown()
361
   end
362
   turtle.down()
363
   posY = posY + 1
364
  end
365
  shiftPos()
366
elseif posY == sizeY then
367
  refuel(posY - 1)
368
  while posY > 1 do
369
   if turtle.detectUp() then
370
        turtle.digUp()
371
   end
372
   turtle.up()
373
   posY = posY - 1
374
   if torchCount == 1 then
375
        if posY == sizeY - 1 and ((not reverse and posX == 2) or (reverse and posX == 1)) then
376
         turtle.select(1)
377
         turtle.placeDown()
378
        end
379
   end
380
  end
381
382
  shiftPos()
383
else
384
  print("Unexpected position (X=" .. posX .. ", Y=" .. posY .. ", Z=" .. posZ .. ")")
385
  returnHome()
386
end
387
end
388
function slice()
389
for p = 1, sizeX, 1 do
390
  sliver()
391
  refreshDisplay()
392
end
393
end
394
if init() then
395
refuel(1)
396
refreshDisplay()
397
if turtle.detect() then
398
  turtle.dig()
399
end
400
turtle.forward()
401
posZ = 1
402
refreshDisplay()
403
for p = 1, sizeZ, 1 do
404
  slice()
405
end
406
finished = true
407
refreshDisplay()
408
returnHome()
409
end