EpicMiningTurtle.lua

809 lines · 30.1 KB

Open raw

Updated Version by Silvamord]]-- --[[For questions and support go to https://discord.gg/thegrindspot]]-- --[[Copyright PrinceTommen - Script developed for Cyepicx (twitch.tv/cyepicx)]]-- --[[You are all allowed to use it as long as you don't pretend it's yours]]-- --[[Have fun !]]-- version =" 3.6" --[[ Release Note: 3.6: Updated to work with tweaked.cc os.pullEvent calls filtered to "keys" only key compares from pullEvent now use the keys enum instead of magic numbers. 3.5: Added: Multiple item slots system, including the items to throw (suggested by Portsanta and Cyepicx) Major interface enhancements to make the configuration faster in spite of the new options Enhanced item shortage security, supporting the multiple slots New functions to manage I/O in a more compact way (suggested by Niseg) 3.41: Fixed: Important glitch when the turtle returned to its starting position with a certain configuration Displaying issues 3.4: Added: Favorite configuration system Ability to choose the direction of the series of parallel tunnels (right or left) Support of execution without torches or chests (will not try to place them) Security that stops the turtle when it runs out of chests or torches (suggested by Cyepicx) Chests and torches status updated automatically Security that requires the user to press enter before the turtle starts (suggested by Cyepicx) The turtle now returns to its starting position after it finishes New rotation function as well a a specific torch placing function Fixed: The turtle will now properly finish the hub after mining an odd number of tunnels The torch placement has been modified to avoid conflicts with chests 3.3: Added: Enderchest Support (suggested by Niseg and Daniteh) Release note 3.2: Fixed: Very important chest placing issue (only appeared in 3.1)

Copy & run

wget https://perlytiara.github.io/turtles.tips/raw/programs/Silvamord/EpicMiningTurtle.lua
1--[[Updated Version by Silvamord]]--
2--[[For questions and support go to https://discord.gg/thegrindspot]]--
3--[[Copyright PrinceTommen - Script developed for Cyepicx (twitch.tv/cyepicx)]]--
4--[[You are all allowed to use it as long as you don't pretend it's yours]]--
5--[[Have fun !]]--
6version =" 3.6"
7--[[
8Release Note:
93.6: Updated to work with tweaked.cc
10 os.pullEvent calls filtered to "keys" only
11 key compares from pullEvent now use the keys enum instead of magic numbers.
123.5: Added: Multiple item slots system, including the items to throw (suggested by Portsanta and Cyepicx)
13 Major interface enhancements to make the configuration faster in spite of the new options
14 Enhanced item shortage security, supporting the multiple slots
15 New functions to manage I/O in a more compact way (suggested by Niseg)
163.41: Fixed: Important glitch when the turtle returned to its starting position with a certain configuration
17 Displaying issues
183.4: Added: Favorite configuration system
19 Ability to choose the direction of the series of parallel tunnels (right or left)
20 Support of execution without torches or chests (will not try to place them)
21 Security that stops the turtle when it runs out of chests or torches (suggested by Cyepicx)
22 Chests and torches status updated automatically
23 Security that requires the user to press enter before the turtle starts (suggested by Cyepicx)
24 The turtle now returns to its starting position after it finishes
25 New rotation function as well a a specific torch placing function
26 Fixed: The turtle will now properly finish the hub after mining an odd number of tunnels
27 The torch placement has been modified to avoid conflicts with chests
283.3: Added: Enderchest Support (suggested by Niseg and Daniteh)
29 Release note
303.2: Fixed: Very important chest placing issue (only appeared in 3.1)
313.1: Added: New mining pattern for more efficiency (suggested by Niseg)
32 Smarter fuel management: Will now consume the "stored" fuel before refueling
33 Can now consume any type of fuel supported by turtles (check the wiki)
34 Fuel type can be changed while the turtle is mining
35 Optimized the mining of 3 blocks high tunnels
36 Better interface, instructions remain visible and a line is dedicated to the fuel status (updated automatically)
37 Option to throw cobblestone automatically (suggested by Niseg)
38 Fixed: Refueling issue in certain circumstances (reported by Cyepicx)
39]]--
40function resetScreen()
41 term.clear()
42 term.setCursorPos(14,1)
43 write("Mining Turtle")
44 term.setCursorPos(5,2)
45 write("For CyanideEpic and his friends")
46 term.setCursorPos(1,13)
47 write("By PrinceTommen, version "..version)
48 term.setCursorPos(1,4)
49end
50function textOutput(output_message, x_screen_pos, z_screen_pos, clear_area)
51 term.setCursorPos(x_screen_pos,z_screen_pos)
52 if clear_area == 0 then
53 clear_area = string.len(output_message)
54 end
55 write(output_message..string.rep(" ", (clear_area - string.len(output_message))))
56end
57function securedInput(x_screen_pos, z_screen_pos, nature, lower_value, upper_value, example1, example2)
58 example = {example1, example2}
59 local function shortExample(example_int, example, boolStringPart)
60 tableShortExample = {}
61 tableShortExample[example_int] = example[example_int].." ("..string.sub(string.lower(example[example_int]), 1, 1)..") "
62 if boolStringPart then
63 return string.sub(string.lower(example[example_int]), 1, 1)
64 else
65 return tableShortExample[example_int]
66 end
67 end
68 incipit = shortExample(1, example, false).."/ "..shortExample(2, example, false)..": "
69 if nature == "text" then
70 repeat
71 textOutput(incipit, x_screen_pos, z_screen_pos, 39)
72 term.setCursorPos(string.len(incipit)+1,z_screen_pos)
73 user_input = string.sub(string.lower(read()), 1, 1)
74 until (user_input == shortExample(1, example, true) or user_input == shortExample(2, example, true))
75 elseif nature == "integer" then
76 repeat
77 textOutput(" ", x_screen_pos, z_screen_pos, (39 - x_screen_pos))
78 term.setCursorPos(x_screen_pos,z_screen_pos)
79 user_input = tonumber(read())
80 until (user_input >= lower_value and user_input <= upper_value)
81 end
82 return user_input
83end
84function clearLines(firstLine, lastLine)
85 a = 1
86 for a=1, (lastLine-firstLine+1) do
87 textOutput("", 1, (firstLine+a-1), 40)
88 end
89end
90function convertToBool(var, boolTrue)
91 if var == boolTrue then
92 var = true
93 else
94 var = false
95 end
96 return var
97end
98function turn(FacingAngle, Bool_rotation, Rotation_integer)
99 if Bool_rotation then
100 for u=1, Rotation_integer do
101 turtle.turnRight()
102 end
103 FacingAngle = FacingAngle + Rotation_integer
104 else
105 for u=1, Rotation_integer do
106 turtle.turnLeft()
107 end
108 FacingAngle = FacingAngle - Rotation_integer
109 end
110 FacingAngle = math.abs((FacingAngle - 1)%4+1)
111 return FacingAngle
112end
113local function refuel()
114 turtle.select(torches_slots+current_slot[2])
115 while not(turtle.refuel(1)) do
116 for f=1, fuel_slots do
117 current_slot[2], shortage[2] = rotateSlot(2, torches_slots+1, fuel_slots)
118 turtle.select(torches_slots+current_slot[2])
119 if turtle.refuel(1) then
120 boolRefuel = true
121 break
122 else
123 boolRefuel = false
124 end
125 end
126 if not(boolRefuel) then
127 textOutput("No Fuel -", 1, 11, 0)
128 current_slot[2], shortage[2] = manageShortage(2, torches_slots+1, torches_slots+fuel_slots)
129 end
130 end
131 refuel_count = 80 - turtle.getFuelLevel()
132 textOutput("Fuel OK -", 1, 11, 0)
133 return refuel_count
134end
135function moveForward(FacingAngle, Boolfb, moving_integer, digUpBool, digDownBool, refuel_count)
136 local moving_count = 1
137 for moving_count=1,moving_integer do
138 if (refuel_count == 80) then
139 refuel_count = refuel()
140 end
141 Bool1 = false
142 while not(Bool1) do
143 if (Boolfb) then
144 turtle.dig()
145 Bool1 = turtle.forward()
146 if (digUpBool) then
147 turtle.digUp()
148 end
149 if (digDownBool) then
150 turtle.digDown()
151 end
152 else
153 Bool1 = turtle.back()
154 if not(Bool1) then
155 turn(FacingAngle, true, 2)
156 turtle.dig()
157 turn(FacingAngle, false, 2)
158 end
159 end
160 end
161 moving_count = moving_count + 1
162 refuel_count = refuel_count + 1
163 end
164 return refuel_count
165end
166function moveUp(Boolud, moving_integer, refuel_count, Bool_DigFront)
167 local moving_count = 1
168 for moving_count=1, moving_integer do
169 if (refuel_count == 80) then
170 refuel_count = refuel()
171 end
172 Bool2 = false
173 if Bool_DigFront then
174 turtle.dig()
175 end
176 while not(Bool2) do
177 if (Boolud) then
178 turtle.digUp()
179 Bool2 = turtle.up()
180 else
181 turtle.digDown()
182 Bool2 = turtle.down()
183 end
184 end
185 moving_count = moving_count + 1
186 refuel_count = refuel_count + 1
187 end
188 return refuel_count
189end
190function manageShortage(managedItem, initial_item_slot, final_item_slot)
191 textOutput("The turtle has used all the "..(itemNames[managedItem+3]).." intitially given. Have you refilled all the "..(itemNames[managedItem+3]).." slots ?", 1, 4, 0)
192 textOutput("Press enter if all the "..(itemNames[managedItem+3]).." slots are refilled (slots "..(initial_item_slot).." to "..(final_item_slot)..").", 1, 7, 0)
193 repeat
194 turn(FacingAngle, true, 4)
195 os.startTimer(1)
196 press, key = os.pullEvent("key")
197 until (key == keys.enter)
198 clearLines(4,10)
199 current_slot[managedItem] = 1
200 shortage[managedItem] = false
201 return current_slot[managedItem], shortage[managedItem]
202end
203function rotateSlot(managedItem, control_slot, rotation_controler)
204 if (turtle.getItemCount(control_slot) == 0) or (managedItem == 2) then
205 if current_slot[managedItem]==rotation_controler and (managedItem ~= 2) then
206 shortage[managedItem] = true
207 else
208 current_slot[managedItem]=((current_slot[managedItem])%rotation_controler)+1
209 end
210 end
211 return current_slot[managedItem], shortage[managedItem]
212end
213function inventoryManagement(refuel_count,Right_or_Left,throw_cobble)
214 function fullInventory(n)
215 n = m + 1
216 repeat
217 item_count = turtle.getItemCount(n)
218 if (item_count ~= 0) then
219 boolSlotOccupied = true
220 n = n + 1
221 else
222 boolSlotOccupied = false
223 end
224 until (boolSlotOccupied == false) or (n == 17)
225 return n
226 end
227 if Chest_approval then
228 m = torches_slots + chests_slots + fuel_slots + garbage_slots
229 thrown_slots = 0
230 if (turtle.getItemCount(16) ~= 0) and (m~=16) then
231 if fullInventory(m)==17 then
232 if throw_stuff then
233 for k=1, garbage_slots do
234 for j=1, (16-m) do
235 turtle.select(m - garbage_slots + k)
236 Bool_match_stuff = turtle.compareTo(m+j)
237 if Bool_match_stuff then
238 thrown_slots = thrown_slots + 1
239 turtle.select(m+j)
240 turtle.drop()
241 end
242 end
243 turtle.select(m - garbage_slots + k)
244 turtle.drop(turtle.getItemCount(m - garbage_slots + k)-1)
245 end
246 for z = (m+1), 16 do
247 for u = (z+1), 16 do
248 if turtle.getItemCount(u)~=0 then
249 turtle.select(u)
250 turtle.transferTo(z)
251 end
252 end
253 end
254 end
255 if not(throw_stuff) or ((thrown_slots <= 2) and (fullInventory(n)>15)) then
256 if shortage[3] then
257 textOutput("No Chests", 24, 11, 0)
258 current_slot[3], shortage[3] = manageShortage(3, torches_slots+fuel_slots+1, torches_slots+fuel_slots+chests_slots)
259 end
260 textOutput("Chests OK", 24, 11, 0)
261 if (Right_or_Left == "left") then
262 FacingAngle = turn(FacingAngle, true, 1)
263 else
264 FacingAngle = turn(FacingAngle, false, 1)
265 end
266 refuel_count = moveForward(FacingAngle, true, 1, false, true, refuel_count)
267 turtle.select(torches_slots+fuel_slots+current_slot[3])
268 turtle.digDown()
269 turtle.placeDown()
270 for u=(m+1),16 do
271 if turtle.getItemCount(u)~=0 then
272 turtle.select(u)
273 turtle.dropDown()
274 end
275 end
276 if enderchest then
277 turtle.select(torches_slots+fuel_slots+1)
278 turtle.drop()
279 turtle.digDown()
280 end
281 current_slot[3], shortage[3] = rotateSlot(3, torches_slots+fuel_slots+current_slot[3], chests_slots)
282 refuel_count = moveForward(FacingAngle, false, 1, false, false, refuel_count)
283 if (Right_or_Left == "left") then
284 FacingAngle = turn(FacingAngle, false, 1)
285 else
286 FacingAngle = turn(FacingAngle, true, 1)
287 end
288 end
289 end
290 end
291 end
292 turtle.select(1)
293 return refuel_count
294end
295function placeTorch(Position)
296 if Torch_approval then
297 if shortage[1] then
298 textOutput("No Torches -", 11, 11, 0)
299 current_slot[1], shortage[1] = manageShortage(1, 1, torches_slots)
300 end
301 textOutput("Torches OK -", 11, 11, 0)
302 turtle.select(current_slot[1])
303 if Position == "front" then
304 turtle.dig()
305 turtle.place()
306 elseif Position == "below" then
307 turtle.digDown()
308 turtle.placeDown()
309 elseif Position == "up" then
310 turtle.digUp()
311 turtle.placeUp()
312 end
313 current_slot[1], shortage[1] = rotateSlot(1, current_slot[1], torches_slots)
314 end
315end
316function digVerticalLayer(refuel_count, FacingAngle, Width, Height, Height_Position, Bool_Torches, Right_or_Left)
317 if Right_or_Left then
318 Right_or_Left = "left"
319 else
320 Right_or_Left = "right"
321 end
322 done_columns = 0
323 if (Height_Position == "up") then
324 for columns=1, math.floor(Width/4) do
325 turtle.digUp()
326 if (Height > 3) then
327 refuel_count = moveUp(true, 1, refuel_count, false)
328 turtle.dig()
329 refuel_count = moveUp(false, (Height-2), refuel_count, true)
330 turtle.digDown()
331 end
332 refuel_count = moveForward(FacingAngle, true, 2, true, true, refuel_count)
333 refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
334 if (Height > 3) then
335 refuel_count = moveUp(false, 1, refuel_count, false)
336 turtle.dig()
337 refuel_count = moveUp(true, (Height-2), refuel_count, true)
338 turtle.digUp()
339 end
340 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
341 done_columns = done_columns + 1
342 if (Width - 4*done_columns ~= 0) then
343 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
344 end
345 end
346 if ((Width - 4*math.floor(Width/4)) == 0) then
347 Height_Position = "up"
348 elseif ((Width - 4*math.floor(Width/4)) == 1) then
349 turtle.digUp()
350 refuel_count = moveUp(false, (Height-3), refuel_count, false)
351 turtle.digDown()
352 refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
353 Height_Position = "down"
354 elseif ((Width - 4*math.floor(Width/4)) >= 2) then
355 if (Height > 3) then
356 refuel_count = moveUp(true, 1, refuel_count, false)
357 turtle.dig()
358 refuel_count = moveUp(false, (Height-2), refuel_count, true)
359 turtle.digDown()
360 end
361 turtle.digUp()
362 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
363 refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
364 Height_Position = "down"
365 if ((Width - 4*math.floor(Width/4)) == 3) then
366 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
367 refuel_count = moveUp(true, (Height - 3), refuel_count, false)
368 turtle.digUp()
369 Height_Position = "up"
370 end
371 end
372 elseif (Height_Position == "down") then
373 for columns=1, math.floor(Width/4) do
374 turtle.digDown()
375 if (Height > 3) then
376 refuel_count = moveUp(false, 1, refuel_count, false)
377 turtle.dig()
378 refuel_count = moveUp(true, (Height - 2), refuel_count, true)
379 turtle.digUp()
380 end
381 refuel_count = moveForward(FacingAngle, true, 2, true, true, refuel_count)
382 if (Height > 3) then
383 refuel_count = moveUp(true, 1, refuel_count, false)
384 turtle.dig()
385 refuel_count = moveUp(false, (Height - 2), refuel_count, true)
386 turtle.digDown()
387 end
388 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
389 done_columns = done_columns + 1
390 if (Width - 4*done_columns ~= 0) then
391 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
392 end
393 refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
394 if (done_columns%2 == 0) and Bool_Torches then
395 FacingAngle = turn(FacingAngle,true , 1)
396 placeTorch("front")
397 FacingAngle = turn(FacingAngle, false, 1)
398 end
399 end
400 if ((Width - 4*math.floor(Width/4)) == 0) then
401 Height_Position = "down"
402 elseif ((Width - 4*math.floor(Width/4)) == 1) then
403 turtle.digDown()
404 refuel_count = moveUp(true, (Height - 3), refuel_count, false)
405 turtle.digUp()
406 Height_Position = "up"
407 elseif ((Width - 4*math.floor(Width/4)) >= 2) then
408 if (Height > 3) then
409 refuel_count = moveUp(false, 1, refuel_count, false)
410 turtle.dig()
411 refuel_count = moveUp(true, (Height - 2), refuel_count, true)
412 turtle.digUp()
413 end
414 turtle.digDown()
415 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
416 Height_Position = "up"
417 if ((Width - 4*math.floor(Width/4)) == 3) then
418 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
419 refuel_count = moveUp(false, (Height - 3), refuel_count, false)
420 turtle.digDown()
421 refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
422 Height_Position = "down"
423 end
424 end
425 end
426 return refuel_count, Height_Position
427end
428
429enderchest, throw_stuff, Chest_approval, Torch_approval, Chest_mismatch, Torch_mismatch = false, false, false, false, false, false
430shortage, itemNames = {false, false, false}, {"torch", "fuel", "chest", "torches", "fuel", "chests"}
431
432resetScreen()
433if (io.open("favorite", "r") ~= nil) then
434 resetScreen()
435 textOutput("Do you wish to use your favorite configuration ?", 1, 4, 0)
436 Favorite_approval = securedInput(1, 6, "text", 0, 0, "Yes", "No")
437 if (Favorite_approval == "y") then
438 handle = fs.open("favorite", "r")
439 input = handle.readAll()
440 handle.close()
441 favorite = textutils.unserialize(input)
442 tunnels_integer = favorite.tunnels_integer
443 Width = favorite.Width
444 Height = favorite.Height
445 Length = favorite.Length
446 tunnels_separation = favorite.tunnels_separation
447 throw_stuff = favorite.throw_stuff
448 enderchest = favorite.enderchest
449 Torch_approval = favorite.Torch_approval
450 Chest_approval = favorite.Chest_approval
451 end
452end
453if (io.open("favorite", "r") == nil) or ((io.open("favorite", "r") ~= nil) and (Favorite_approval == "n")) then
454 resetScreen()
455 textOutput("Number of parallel tunnels ? ", 1, 4, 0)
456 tunnels_integer = securedInput(37, 4, "integer", 1, 1000, " ", " ")
457 textOutput("Width of the tunnels ? ", 1, 5, 0)
458 Width = securedInput(37, 5, "integer", 1, 1000, " ", " ")
459 term.setCursorPos(1,6)
460 textOutput("Height of the tunnels ? ", 1, 6, 0)
461 Height = securedInput(37, 6, "integer", 1, 200, " ", " ")
462 if (Height < 3) then
463 Height = 3
464 end
465 term.setCursorPos(1,7)
466 textOutput("Length of the tunnels ? ", 1, 7, 0)
467 Length = securedInput(37, 7, "integer", 1, 100000, " ", " ")
468 if (tunnels_integer > 1) then
469 term.setCursorPos(1,8)
470 textOutput("Separating blocks between tunnels ? ", 1, 8, 0)
471 tunnels_separation = securedInput(37, 8, "integer", 1, 1000, " ", " ")
472 else
473 tunnels_separation = 0
474 end
475
476 resetScreen()
477 textOutput("To use regular chests, press c", 1, 4, 0)
478 textOutput("To use an enderchest, press e", 1, 5, 0)
479 textOutput("To use torches, press t", 1, 6, 0)
480 textOutput("To throw away specific items, press p", 1, 7, 0)
481 textOutput("Press enter once you have chosen all the options you wanted to activate.", 1, 11, 0)
482 while true do
483 press, key = os.pullEvent("key")
484 if press == "key" and key == keys.enter then
485 break
486 elseif key == keys.c then
487 if Chest_approval then
488 Chest_approval = false
489 textOutput("", 10, 9, 11)
490 else
491 Chest_approval = true
492 textOutput("Chests,", 10, 9, 11)
493 end
494 elseif key == keys.e then
495 if enderchest then
496 enderchest = not(enderchest)
497 textOutput("", 10, 9, 11)
498 else
499 Chest_approval = true
500 enderchest = true
501 textOutput("Enderchest,", 10, 9, 11)
502 end
503 elseif key == keys.t then
504 if Torch_approval then
505 Torch_approval = false
506 textOutput("", 1, 9, 8)
507 else
508 Torch_approval = true
509 textOutput("Torches,", 1, 9, 8)
510 end
511 elseif key == keys.p then
512 if throw_stuff then
513 throw_stuff = not(throw_stuff)
514 textOutput("", 22, 9, 12)
515 else
516 throw_stuff = true
517 textOutput("Throw items.", 22, 9, 12)
518 end
519 end
520 end
521 resetScreen()
522
523 textOutput("Do you want to save this configuration as your favorite ?", 1, 4, 0)
524 New_favorite = securedInput(1, 6, "text", 0, 0, "Yes", "No")
525
526 if (New_favorite == "y") then
527 favorite = {}
528 favorite.tunnels_integer = tunnels_integer
529 favorite.Width = Width
530 favorite.Height = Height
531 favorite.Length = Length
532 favorite.tunnels_separation = tunnels_separation
533 favorite.Torch_approval = Torch_approval
534 favorite.Chest_approval = Chest_approval
535 favorite.throw_stuff = throw_stuff
536 favorite.enderchest = enderchest
537 output = textutils.serialize(favorite)
538 handle = fs.open("favorite", "w")
539 handle.write(output)
540 handle.close()
541 end
542end
543resetScreen()
544textOutput("To manage extra slots, press s", 1, 4, 0)
545textOutput("This option allows you to have several torches/fuel/chests slots, as well as different items to throw", 1, 6, 0)
546textOutput("Else, press enter to skip this step.", 1, 10, 0)
547torches_slots, chests_slots, garbage_slots = 0, 0, 0
548while true do
549 press, key = os.pullEvent("key")
550 if press == "key" and key == keys.enter then
551 fuel_slots = 1
552 break
553 elseif key == keys.s then
554 repeat
555 turtle.select(1)
556 resetScreen()
557 textOutput("Number of fuel slots ? ", 1, 4, 0)
558 fuel_slots = securedInput(29, 4, "integer", 1, 16, " ", " ")
559 slot_total = fuel_slots
560 if Torch_approval then
561 textOutput("Number of torches slots ? ", 1, 5, 0)
562 torches_slots = securedInput(29, 5, "integer", 1, 16, " ", " ")
563 slot_total = slot_total + torches_slots
564 end
565 if Chest_approval and not(enderchest) then
566 textOutput("Number of chests slots ? ", 1, 6, 0)
567 chests_slots = securedInput(29, 6, "integer", 1, 16, " ", " ")
568 slot_total = slot_total + chests_slots
569 end
570 if throw_stuff then
571 textOutput("Number of undesired items ? ", 1, 7, 0)
572 garbage_slots = securedInput(29, 7, "integer", 1, 16, " ", " ")
573 slot_total = slot_total + garbage_slots
574 end
575 until (slot_total < 16)
576 break
577 end
578end
579resetScreen()
580if (tunnels_integer > 1) then
581 textOutput("The first tunnel will be in front of the turtle. Do you want the tunnels to be dug on the right or on the left of the first tunnel (They will be parallel to the first one) ?", 1, 4, 0)
582 Bool_direction = securedInput(1, 9, "text", 0, 0, "Right", "Left")
583end
584if (tunnels_integer == 1) and (Width > 1) then
585 textOutput("In front of the turtle will be one side of the tunnel. Do you want it to mine the rest on the left or on the right ?", 1, 4, 0)
586 Bool_direction = securedInput(1, 9, "text", 0, 0, "Right", "Left")
587end
588resetScreen()
589if Torch_approval then
590 if torches_slots > 1 then
591 textOutput("Torches in the slots 1 to "..torches_slots, 1, 4, 0)
592 else
593 torches_slots = 1
594 textOutput("Torches in the slot 1", 1, 4, 0)
595 end
596end
597if fuel_slots > 1 then
598 textOutput("Fuel in the slots "..(torches_slots+1).." to "..(torches_slots+fuel_slots), 1, 5, 0)
599else
600 fuel_slots = 1
601 textOutput("Fuel in the slot "..(torches_slots+1), 1, 5, 0)
602end
603if Chest_approval and not(enderchest) then
604 if chests_slots > 1 then
605 textOutput("Chests in the slots "..(torches_slots+fuel_slots+1).." to "..(torches_slots+fuel_slots+chests_slots), 1, 6, 0)
606 else
607 chests_slots = 1
608 textOutput("Chests in the slot "..(torches_slots+fuel_slots+1), 1, 6, 0)
609 end
610end
611if enderchest then
612 textOutput("The enderchest in the slot "..(torches_slots+fuel_slots+1), 1, 6, 0)
613 chests_slots = 1
614end
615if throw_stuff then
616 if garbage_slots > 1 then
617 textOutput("Please make sure there are samples of the items to throw in the slots "..(torches_slots+fuel_slots+chests_slots+1).." to "..(torches_slots+fuel_slots+chests_slots+garbage_slots), 1, 8, 0)
618 else
619 garbage_slots = 1
620 textOutput("Please make sure there is a sample of the item to throw in the slot "..(torches_slots+fuel_slots+chests_slots+1), 1, 8, 0)
621 end
622end
623if (Bool_direction == "r") then
624 Bool_direction = true
625else
626 Bool_direction = false
627end
628textOutput("Press enter to start", 1, 11, 0)
629while true do
630 press, key = os.pullEvent("key")
631 if press == "key" and key == keys.enter then
632 break
633 end
634end
635resetScreen()
636textOutput("", 1, 11, 20)
637if Torch_approval and (turtle.getItemCount(1) == 0) then
638 textOutput("The torches slot is empty. Are you sure you want to use torches ?", 1, 4, 0)
639 Torch_approval = convertToBool(securedInput(1, 6, "text", 0, 0, "Yes", "No"), "y")
640elseif Torch_approval and (turtle.getItemCount(1) ~= 0) then
641 for u = 1, torches_slots-1 do
642 turtle.select(u+1)
643 if not(turtle.compareTo(1)) then
644 Torch_mismatch = true
645 end
646 end
647 if Torch_mismatch then
648 resetScreen()
649 textOutput("All the slots dedicated to the torches have not been set up correctly. Are you sure you want to use torches ?", 1, 4, 0)
650 Torch_approval = convertToBool(securedInput(1, 7, "text", 0, 0, "Yes", "No"), "y")
651 end
652end
653
654if Chest_approval and (turtle.getItemCount(torches_slots + fuel_slots + 1) == 0) then
655 resetScreen()
656 textOutput("The chests slot is empty. Are you sure you want to use chests ?", 1, 4, 0)
657 Chest_approval = convertToBool(securedInput(1, 6, "text", 0, 0, "Yes", "No"), "y")
658elseif Chest_approval and (turtle.getItemCount(torches_slots + fuel_slots + 1) ~= 0) then
659 for u = 1, chests_slots-1 do
660 turtle.select(torches_slots + fuel_slots + u + 1)
661 if not(turtle.compareTo(torches_slots + fuel_slots + 1)) then
662 Chest_mismatch = true
663 end
664 end
665 if Chest_mismatch then
666 resetScreen()
667 textOutput("All the slots dedicated to the chests have not been set up correctly. Are you sure you want to use chests ?", 1, 4, 0)
668 Chest_approval = convertToBool(securedInput(1, 7, "text", 0, 0, "Yes", "No"), "y")
669 end
670end
671if Torch_approval then
672 empty_torches_slots = 0
673 for u = 1, torches_slots do
674 if turtle.getItemCount(u) == 0 then
675 empty_torches_slots = empty_torches_slots + 1
676 end
677 end
678 if empty_torches_slots == torches_slots then
679 shortage[1] = true
680 end
681 textOutput("No Torches -", 11, 11, 0)
682end
683if Torch_approval and (turtle.getItemCount(1) ~= 0) then
684 shortage[1] = false
685 textOutput("Torches OK -", 11, 11, 0)
686end
687if Chest_approval then
688 empty_chests_slots = 0
689 for u = 1, chests_slots do
690 if turtle.getItemCount(torches_slots + fuel_slots + u) == 0 then
691 empty_chests_slots = empty_chests_slots + 1
692 end
693 end
694 if empty_chests_slots == chests_slots then
695 shortage[3] = true
696 end
697 textOutput("No Chests -", 24, 11, 0)
698end
699if Chest_approval and (turtle.getItemCount(torches_slots + fuel_slots + 1) ~= 0) then
700 shortage[3] = false
701 textOutput("Chests OK -", 24, 11, 0)
702end
703textOutput("Fuel OK -", 1, 11, 0)
704refuel_count = 80 - turtle.getFuelLevel()
705FacingAngle, tunnel_forth, current_slot= 0, true, {1, 1, 1}
706refuel_count = moveUp(true, 1, refuel_count, false)
707if (Width == 1) then
708 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
709end
710for done_tunnels=1, tunnels_integer do
711 if (Width >= 2) then
712 for done_layers=1, math.ceil(Length/2) do
713 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
714 FacingAngle = turn(FacingAngle, Bool_direction, 1)
715 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, Width, Height, "down", false, Bool_direction)
716 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
717 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
718 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
719 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, Width, Height, Height_Position, false, not(Bool_direction))
720 FacingAngle = turn(FacingAngle, Bool_direction, 1)
721 if (done_layers%4 == 0) then
722 refuel_count = moveUp(false, 1, refuel_count, false)
723 FacingAngle = turn(FacingAngle, Bool_direction, 1)
724 placeTorch("front")
725 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
726 refuel_count = moveUp(true, 1, refuel_count, false)
727 end
728 end
729 elseif (Width == 1) then
730 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, 2*math.ceil(Length/2), Height, "down", true, Bool_direction)
731 end
732 if (Height_Position == "up") then
733 refuel_count = moveUp(false, (Height - 3), refuel_count, false)
734 Height_Position = "down"
735 end
736 if tunnel_forth and (tunnels_integer - done_tunnels >= 1) then
737 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
738 FacingAngle = turn(FacingAngle, Bool_direction, 1)
739 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)+tunnels_separation), Height, "down", false, not(Bool_direction))
740 if (Height_Position == "up") then
741 refuel_count = moveUp(false, (Height - 3), refuel_count, false)
742 Height_Position = "down"
743 end
744 FacingAngle = turn(FacingAngle, Bool_direction, 1)
745 placeTorch("below")
746 elseif not(tunnel_forth) then
747 refuel_count = moveForward(FacingAngle, true, 1, true, false, refuel_count)
748 FacingAngle = turn(FacingAngle, Bool_direction, 1)
749 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)-1+tunnels_separation), Height, "down", false, Bool_direction)
750 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
751 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
752 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
753 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)-1+tunnels_separation), Height, Height_Position, false, not(Bool_direction))
754 if (Height_Position == "up") then
755 refuel_count = moveUp(false, (Height - 3), refuel_count, false)
756 Height_Position = "down"
757 end
758 FacingAngle = turn(FacingAngle, Bool_direction, 2)
759 refuel_count = moveForward(FacingAngle, true, (Width-2), true, true, refuel_count)
760 placeTorch("front")
761 FacingAngle = turn(FacingAngle, not(Bool_direction), 2)
762 refuel_count = moveForward(FacingAngle, true, (Width-2), true, true, refuel_count)
763 if (tunnels_integer - done_tunnels ~= 0) then
764 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
765 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (tunnels_separation+1), Height, Height_Position, false, Bool_direction)
766 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
767 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
768 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
769 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (tunnels_separation+1), Height, Height_Position, false, not(Bool_direction))
770 refuel_count = moveForward(FacingAngle, false, tunnels_separation, true, true, refuel_count)
771 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
772 placeTorch("front")
773 FacingAngle = turn(FacingAngle, not(Bool_direction), 2)
774 end
775 end
776 if tunnel_forth and (tunnels_integer - done_tunnels == 0) and (Width > 1) then
777 refuel_count = moveForward(FacingAngle, false, 2*math.ceil(Length/2), false, false, refuel_count)
778 FacingAngle = turn(FacingAngle, Bool_direction, 1)
779 refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
780 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (Width - 1), Height, Height_Position, false, Bool_direction)
781 FacingAngle = turn(FacingAngle, Bool_direction, 1)
782 refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
783 FacingAngle = turn(FacingAngle, Bool_direction, 1)
784 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (Width - 1), Height, Height_Position, false, not(Bool_direction))
785 if (Height_Position == "up") then
786 refuel_count = moveUp(false, (Height - 3), refuel_count, false)
787 Height_Position = "down"
788 end
789 refuel_count = moveForward(FacingAngle, false, (Width - 2), false, false, refuel_count)
790 FacingAngle = turn(FacingAngle, Bool_direction, 2)
791 end
792 if (Width == 1) and (tunnels_integer - done_tunnels ~= 0) then
793 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
794 elseif (Width == 1) and (tunnels_integer - done_tunnels == 0) and tunnel_forth then
795 refuel_count = moveForward(FacingAngle, false, (2*math.ceil(Length/2)), false, false, refuel_count)
796 end
797 tunnel_forth = not(tunnel_forth)
798end
799refuel_count = moveUp(false, 1, refuel_count, false)
800if (Width == 1) and not(tunnel_forth) then
801 refuel_count = moveForward(FacingAngle, false, 1, false, false, refuel_count)
802 turn(FacingAngle, Bool_direction, 1)
803end
804refuel_count = moveForward(FacingAngle, false, ((tunnels_integer*Width) - 1 + (tunnels_separation*(tunnels_integer - 1))), false, false, refuel_count)
805FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
806refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
807resetScreen()
808write("Done. I hope I worked well !")
809term.setCursorPos(1,8)