EpicMiningTurtle_remote.lua

923 lines · 33.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/perlytiara/EpicMiningTurtle/EpicMiningTurtle_remote.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]]--
40
41-- Networking helpers (CC:Tweaked rednet)
42local EMT_PROTOCOL = "EMT"
43local emt_has_modem = false
44local emt_monitor_id = nil
45local total_tunnels, total_layers_per_tunnel = 0, 0
46local current_tunnel, current_layer = 0, 0
47local steps_since_status = 0
48
49local function emt_open_modem()
50 if peripheral and rednet then
51 peripheral.find("modem", function(side, modem)
52 if modem.isWireless and modem.isWireless() then
53 if not rednet.isOpen(side) then rednet.open(side) end
54 emt_has_modem = true
55 end
56 end)
57 -- Fallback: open any modem if wireless check not available
58 if not emt_has_modem then
59 peripheral.find("modem", function(side)
60 if not rednet.isOpen(side) then rednet.open(side) end
61 emt_has_modem = true
62 end)
63 end
64 end
65end
66
67local function emt_get_pos()
68 local x,y,z = nil,nil,nil
69 if gps and gps.locate then
70 x,y,z = gps.locate(0.5)
71 end
72 if x and y and z then
73 return {x=x,y=y,z=z}
74 else
75 return nil
76 end
77end
78
79local function emt_build_inventory()
80 local inv = {}
81 for slot=1,16 do
82 local detail = turtle.getItemDetail(slot)
83 if detail then
84 inv[#inv+1] = {slot=slot, name=detail.name, count=detail.count}
85 end
86 end
87 return inv
88end
89
90local function emt_send(kind, extra)
91 if not emt_has_modem then return end
92 local msg = {
93 kind = kind or "status",
94 sender_id = os.getComputerID(),
95 label = os.getComputerLabel(),
96 fuel = turtle.getFuelLevel(),
97 progress = {
98 current_tunnel = current_tunnel,
99 total_tunnels = total_tunnels,
100 current_layer = current_layer,
101 total_layers = total_layers_per_tunnel,
102 },
103 pos = emt_get_pos(),
104 inventory = emt_build_inventory(),
105 }
106 if extra then
107 for k,v in pairs(extra) do msg[k]=v end
108 end
109 rednet.broadcast(msg, EMT_PROTOCOL)
110 if emt_monitor_id then
111 rednet.send(emt_monitor_id, msg, EMT_PROTOCOL)
112 end
113end
114
115local function emt_poll()
116 if not emt_has_modem then return end
117 local sender, msg, proto = rednet.receive(EMT_PROTOCOL, 0)
118 while sender do
119 if type(msg) == "table" and msg.command then
120 if msg.command == "request_status" then
121 emt_send("status", {requested=true})
122 elseif msg.command == "set_monitor" then
123 emt_monitor_id = sender
124 rednet.send(sender, {kind="ack", action="set_monitor"}, EMT_PROTOCOL)
125 elseif msg.command == "request_pickup" then
126 emt_send("pickup", {pickup=true})
127 end
128 end
129 sender, msg, proto = rednet.receive(EMT_PROTOCOL, 0)
130 end
131end
132function resetScreen()
133 term.clear()
134 term.setCursorPos(14,1)
135 write("Mining Turtle")
136 term.setCursorPos(5,2)
137 write("For CyanideEpic and his friends")
138 term.setCursorPos(1,13)
139 write("By PrinceTommen, version "..version)
140 term.setCursorPos(1,4)
141end
142function textOutput(output_message, x_screen_pos, z_screen_pos, clear_area)
143 term.setCursorPos(x_screen_pos,z_screen_pos)
144 if clear_area == 0 then
145 clear_area = string.len(output_message)
146 end
147 write(output_message..string.rep(" ", (clear_area - string.len(output_message))))
148end
149function securedInput(x_screen_pos, z_screen_pos, nature, lower_value, upper_value, example1, example2)
150 example = {example1, example2}
151 local function shortExample(example_int, example, boolStringPart)
152 tableShortExample = {}
153 tableShortExample[example_int] = example[example_int].." ("..string.sub(string.lower(example[example_int]), 1, 1)..") "
154 if boolStringPart then
155 return string.sub(string.lower(example[example_int]), 1, 1)
156 else
157 return tableShortExample[example_int]
158 end
159 end
160 incipit = shortExample(1, example, false).."/ "..shortExample(2, example, false)..": "
161 if nature == "text" then
162 repeat
163 textOutput(incipit, x_screen_pos, z_screen_pos, 39)
164 term.setCursorPos(string.len(incipit)+1,z_screen_pos)
165 user_input = string.sub(string.lower(read()), 1, 1)
166 until (user_input == shortExample(1, example, true) or user_input == shortExample(2, example, true))
167 elseif nature == "integer" then
168 repeat
169 textOutput(" ", x_screen_pos, z_screen_pos, (39 - x_screen_pos))
170 term.setCursorPos(x_screen_pos,z_screen_pos)
171 user_input = tonumber(read())
172 until (user_input >= lower_value and user_input <= upper_value)
173 end
174 return user_input
175end
176function clearLines(firstLine, lastLine)
177 a = 1
178 for a=1, (lastLine-firstLine+1) do
179 textOutput("", 1, (firstLine+a-1), 40)
180 end
181end
182function convertToBool(var, boolTrue)
183 if var == boolTrue then
184 var = true
185 else
186 var = false
187 end
188 return var
189end
190function turn(FacingAngle, Bool_rotation, Rotation_integer)
191 if Bool_rotation then
192 for u=1, Rotation_integer do
193 turtle.turnRight()
194 end
195 FacingAngle = FacingAngle + Rotation_integer
196 else
197 for u=1, Rotation_integer do
198 turtle.turnLeft()
199 end
200 FacingAngle = FacingAngle - Rotation_integer
201 end
202 FacingAngle = math.abs((FacingAngle - 1)%4+1)
203 return FacingAngle
204end
205local function refuel()
206 turtle.select(torches_slots+current_slot[2])
207 while not(turtle.refuel(1)) do
208 for f=1, fuel_slots do
209 current_slot[2], shortage[2] = rotateSlot(2, torches_slots+1, fuel_slots)
210 turtle.select(torches_slots+current_slot[2])
211 if turtle.refuel(1) then
212 boolRefuel = true
213 break
214 else
215 boolRefuel = false
216 end
217 end
218 if not(boolRefuel) then
219 textOutput("No Fuel -", 1, 11, 0)
220 current_slot[2], shortage[2] = manageShortage(2, torches_slots+1, torches_slots+fuel_slots)
221 end
222 end
223 refuel_count = 80 - turtle.getFuelLevel()
224 textOutput("Fuel OK -", 1, 11, 0)
225 return refuel_count
226end
227function moveForward(FacingAngle, Boolfb, moving_integer, digUpBool, digDownBool, refuel_count)
228 local moving_count = 1
229 for moving_count=1,moving_integer do
230 if (refuel_count == 80) then
231 refuel_count = refuel()
232 end
233 Bool1 = false
234 while not(Bool1) do
235 if (Boolfb) then
236 turtle.dig()
237 Bool1 = turtle.forward()
238 if (digUpBool) then
239 turtle.digUp()
240 end
241 if (digDownBool) then
242 turtle.digDown()
243 end
244 else
245 Bool1 = turtle.back()
246 if not(Bool1) then
247 turn(FacingAngle, true, 2)
248 turtle.dig()
249 turn(FacingAngle, false, 2)
250 end
251 end
252 end
253 moving_count = moving_count + 1
254 refuel_count = refuel_count + 1
255 steps_since_status = steps_since_status + 1
256 if (steps_since_status % 10 == 0) then emt_send("heartbeat") end
257 emt_poll()
258 end
259 return refuel_count
260end
261function moveUp(Boolud, moving_integer, refuel_count, Bool_DigFront)
262 local moving_count = 1
263 for moving_count=1, moving_integer do
264 if (refuel_count == 80) then
265 refuel_count = refuel()
266 end
267 Bool2 = false
268 if Bool_DigFront then
269 turtle.dig()
270 end
271 while not(Bool2) do
272 if (Boolud) then
273 turtle.digUp()
274 Bool2 = turtle.up()
275 else
276 turtle.digDown()
277 Bool2 = turtle.down()
278 end
279 end
280 moving_count = moving_count + 1
281 refuel_count = refuel_count + 1
282 steps_since_status = steps_since_status + 1
283 if (steps_since_status % 10 == 0) then emt_send("heartbeat") end
284 emt_poll()
285 end
286 return refuel_count
287end
288function manageShortage(managedItem, initial_item_slot, final_item_slot)
289 textOutput("The turtle has used all the "..(itemNames[managedItem+3]).." intitially given. Have you refilled all the "..(itemNames[managedItem+3]).." slots ?", 1, 4, 0)
290 textOutput("Press enter if all the "..(itemNames[managedItem+3]).." slots are refilled (slots "..(initial_item_slot).." to "..(final_item_slot)..").", 1, 7, 0)
291 repeat
292 turn(FacingAngle, true, 4)
293 os.startTimer(1)
294 press, key = os.pullEvent("key")
295 until (key == keys.enter)
296 clearLines(4,10)
297 current_slot[managedItem] = 1
298 shortage[managedItem] = false
299 return current_slot[managedItem], shortage[managedItem]
300end
301function rotateSlot(managedItem, control_slot, rotation_controler)
302 if (turtle.getItemCount(control_slot) == 0) or (managedItem == 2) then
303 if current_slot[managedItem]==rotation_controler and (managedItem ~= 2) then
304 shortage[managedItem] = true
305 else
306 current_slot[managedItem]=((current_slot[managedItem])%rotation_controler)+1
307 end
308 end
309 return current_slot[managedItem], shortage[managedItem]
310end
311function inventoryManagement(refuel_count,Right_or_Left,throw_cobble)
312 function fullInventory(n)
313 n = m + 1
314 repeat
315 item_count = turtle.getItemCount(n)
316 if (item_count ~= 0) then
317 boolSlotOccupied = true
318 n = n + 1
319 else
320 boolSlotOccupied = false
321 end
322 until (boolSlotOccupied == false) or (n == 17)
323 return n
324 end
325 if Chest_approval then
326 m = torches_slots + chests_slots + fuel_slots + garbage_slots
327 thrown_slots = 0
328 if (turtle.getItemCount(16) ~= 0) and (m~=16) then
329 if fullInventory(m)==17 then
330 if throw_stuff then
331 for k=1, garbage_slots do
332 for j=1, (16-m) do
333 turtle.select(m - garbage_slots + k)
334 Bool_match_stuff = turtle.compareTo(m+j)
335 if Bool_match_stuff then
336 thrown_slots = thrown_slots + 1
337 turtle.select(m+j)
338 turtle.drop()
339 end
340 end
341 turtle.select(m - garbage_slots + k)
342 turtle.drop(turtle.getItemCount(m - garbage_slots + k)-1)
343 end
344 for z = (m+1), 16 do
345 for u = (z+1), 16 do
346 if turtle.getItemCount(u)~=0 then
347 turtle.select(u)
348 turtle.transferTo(z)
349 end
350 end
351 end
352 end
353 if not(throw_stuff) or ((thrown_slots <= 2) and (fullInventory(n)>15)) then
354 if shortage[3] then
355 textOutput("No Chests", 24, 11, 0)
356 current_slot[3], shortage[3] = manageShortage(3, torches_slots+fuel_slots+1, torches_slots+fuel_slots+chests_slots)
357 end
358 textOutput("Chests OK", 24, 11, 0)
359 if (Right_or_Left == "left") then
360 FacingAngle = turn(FacingAngle, true, 1)
361 else
362 FacingAngle = turn(FacingAngle, false, 1)
363 end
364 refuel_count = moveForward(FacingAngle, true, 1, false, true, refuel_count)
365 turtle.select(torches_slots+fuel_slots+current_slot[3])
366 turtle.digDown()
367 turtle.placeDown()
368 for u=(m+1),16 do
369 if turtle.getItemCount(u)~=0 then
370 turtle.select(u)
371 turtle.dropDown()
372 end
373 end
374 if enderchest then
375 turtle.select(torches_slots+fuel_slots+1)
376 turtle.drop()
377 turtle.digDown()
378 end
379 current_slot[3], shortage[3] = rotateSlot(3, torches_slots+fuel_slots+current_slot[3], chests_slots)
380 refuel_count = moveForward(FacingAngle, false, 1, false, false, refuel_count)
381 if (Right_or_Left == "left") then
382 FacingAngle = turn(FacingAngle, false, 1)
383 else
384 FacingAngle = turn(FacingAngle, true, 1)
385 end
386 emt_send("inventory")
387 end
388 end
389 end
390 end
391 turtle.select(1)
392 return refuel_count
393end
394function placeTorch(Position)
395 if Torch_approval then
396 if shortage[1] then
397 textOutput("No Torches -", 11, 11, 0)
398 current_slot[1], shortage[1] = manageShortage(1, 1, torches_slots)
399 end
400 textOutput("Torches OK -", 11, 11, 0)
401 turtle.select(current_slot[1])
402 if Position == "front" then
403 turtle.dig()
404 turtle.place()
405 elseif Position == "below" then
406 turtle.digDown()
407 turtle.placeDown()
408 elseif Position == "up" then
409 turtle.digUp()
410 turtle.placeUp()
411 end
412 current_slot[1], shortage[1] = rotateSlot(1, current_slot[1], torches_slots)
413 end
414end
415function digVerticalLayer(refuel_count, FacingAngle, Width, Height, Height_Position, Bool_Torches, Right_or_Left)
416 if Right_or_Left then
417 Right_or_Left = "left"
418 else
419 Right_or_Left = "right"
420 end
421 done_columns = 0
422 if (Height_Position == "up") then
423 for columns=1, math.floor(Width/4) do
424 turtle.digUp()
425 if (Height > 3) then
426 refuel_count = moveUp(true, 1, refuel_count, false)
427 turtle.dig()
428 refuel_count = moveUp(false, (Height-2), refuel_count, true)
429 turtle.digDown()
430 end
431 refuel_count = moveForward(FacingAngle, true, 2, true, true, refuel_count)
432 refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
433 if (Height > 3) then
434 refuel_count = moveUp(false, 1, refuel_count, false)
435 turtle.dig()
436 refuel_count = moveUp(true, (Height-2), refuel_count, true)
437 turtle.digUp()
438 end
439 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
440 done_columns = done_columns + 1
441 if (Width - 4*done_columns ~= 0) then
442 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
443 end
444 end
445 if ((Width - 4*math.floor(Width/4)) == 0) then
446 Height_Position = "up"
447 elseif ((Width - 4*math.floor(Width/4)) == 1) then
448 turtle.digUp()
449 refuel_count = moveUp(false, (Height-3), refuel_count, false)
450 turtle.digDown()
451 refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
452 Height_Position = "down"
453 elseif ((Width - 4*math.floor(Width/4)) >= 2) then
454 if (Height > 3) then
455 refuel_count = moveUp(true, 1, refuel_count, false)
456 turtle.dig()
457 refuel_count = moveUp(false, (Height-2), refuel_count, true)
458 turtle.digDown()
459 end
460 turtle.digUp()
461 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
462 refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
463 Height_Position = "down"
464 if ((Width - 4*math.floor(Width/4)) == 3) then
465 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
466 refuel_count = moveUp(true, (Height - 3), refuel_count, false)
467 turtle.digUp()
468 Height_Position = "up"
469 end
470 end
471 elseif (Height_Position == "down") then
472 for columns=1, math.floor(Width/4) do
473 turtle.digDown()
474 if (Height > 3) then
475 refuel_count = moveUp(false, 1, refuel_count, false)
476 turtle.dig()
477 refuel_count = moveUp(true, (Height - 2), refuel_count, true)
478 turtle.digUp()
479 end
480 refuel_count = moveForward(FacingAngle, true, 2, true, true, refuel_count)
481 if (Height > 3) then
482 refuel_count = moveUp(true, 1, refuel_count, false)
483 turtle.dig()
484 refuel_count = moveUp(false, (Height - 2), refuel_count, true)
485 turtle.digDown()
486 end
487 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
488 done_columns = done_columns + 1
489 if (Width - 4*done_columns ~= 0) then
490 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
491 end
492 refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
493 if (done_columns%2 == 0) and Bool_Torches then
494 FacingAngle = turn(FacingAngle,true , 1)
495 placeTorch("front")
496 FacingAngle = turn(FacingAngle, false, 1)
497 end
498 end
499 if ((Width - 4*math.floor(Width/4)) == 0) then
500 Height_Position = "down"
501 elseif ((Width - 4*math.floor(Width/4)) == 1) then
502 turtle.digDown()
503 refuel_count = moveUp(true, (Height - 3), refuel_count, false)
504 turtle.digUp()
505 Height_Position = "up"
506 elseif ((Width - 4*math.floor(Width/4)) >= 2) then
507 if (Height > 3) then
508 refuel_count = moveUp(false, 1, refuel_count, false)
509 turtle.dig()
510 refuel_count = moveUp(true, (Height - 2), refuel_count, true)
511 turtle.digUp()
512 end
513 turtle.digDown()
514 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
515 Height_Position = "up"
516 if ((Width - 4*math.floor(Width/4)) == 3) then
517 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
518 refuel_count = moveUp(false, (Height - 3), refuel_count, false)
519 turtle.digDown()
520 refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
521 Height_Position = "down"
522 end
523 end
524 end
525 return refuel_count, Height_Position
526end
527
528enderchest, throw_stuff, Chest_approval, Torch_approval, Chest_mismatch, Torch_mismatch = false, false, false, false, false, false
529shortage, itemNames = {false, false, false}, {"torch", "fuel", "chest", "torches", "fuel", "chests"}
530
531resetScreen()
532if (io.open("favorite", "r") ~= nil) then
533 resetScreen()
534 textOutput("Do you wish to use your favorite configuration ?", 1, 4, 0)
535 Favorite_approval = securedInput(1, 6, "text", 0, 0, "Yes", "No")
536 if (Favorite_approval == "y") then
537 handle = fs.open("favorite", "r")
538 input = handle.readAll()
539 handle.close()
540 favorite = textutils.unserialize(input)
541 tunnels_integer = favorite.tunnels_integer
542 Width = favorite.Width
543 Height = favorite.Height
544 Length = favorite.Length
545 tunnels_separation = favorite.tunnels_separation
546 throw_stuff = favorite.throw_stuff
547 enderchest = favorite.enderchest
548 Torch_approval = favorite.Torch_approval
549 Chest_approval = favorite.Chest_approval
550 end
551end
552if (io.open("favorite", "r") == nil) or ((io.open("favorite", "r") ~= nil) and (Favorite_approval == "n")) then
553 resetScreen()
554 textOutput("Number of parallel tunnels ? ", 1, 4, 0)
555 tunnels_integer = securedInput(37, 4, "integer", 1, 1000, " ", " ")
556 textOutput("Width of the tunnels ? ", 1, 5, 0)
557 Width = securedInput(37, 5, "integer", 1, 1000, " ", " ")
558 term.setCursorPos(1,6)
559 textOutput("Height of the tunnels ? ", 1, 6, 0)
560 Height = securedInput(37, 6, "integer", 1, 200, " ", " ")
561 if (Height < 3) then
562 Height = 3
563 end
564 term.setCursorPos(1,7)
565 textOutput("Length of the tunnels ? ", 1, 7, 0)
566 Length = securedInput(37, 7, "integer", 1, 100000, " ", " ")
567 if (tunnels_integer > 1) then
568 term.setCursorPos(1,8)
569 textOutput("Separating blocks between tunnels ? ", 1, 8, 0)
570 tunnels_separation = securedInput(37, 8, "integer", 1, 1000, " ", " ")
571 else
572 tunnels_separation = 0
573 end
574
575 resetScreen()
576 textOutput("To use regular chests, press c", 1, 4, 0)
577 textOutput("To use an enderchest, press e", 1, 5, 0)
578 textOutput("To use torches, press t", 1, 6, 0)
579 textOutput("To throw away specific items, press p", 1, 7, 0)
580 textOutput("Press enter once you have chosen all the options you wanted to activate.", 1, 11, 0)
581 while true do
582 press, key = os.pullEvent("key")
583 if press == "key" and key == keys.enter then
584 break
585 elseif key == keys.c then
586 if Chest_approval then
587 Chest_approval = false
588 textOutput("", 10, 9, 11)
589 else
590 Chest_approval = true
591 textOutput("Chests,", 10, 9, 11)
592 end
593 elseif key == keys.e then
594 if enderchest then
595 enderchest = not(enderchest)
596 textOutput("", 10, 9, 11)
597 else
598 Chest_approval = true
599 enderchest = true
600 textOutput("Enderchest,", 10, 9, 11)
601 end
602 elseif key == keys.t then
603 if Torch_approval then
604 Torch_approval = false
605 textOutput("", 1, 9, 8)
606 else
607 Torch_approval = true
608 textOutput("Torches,", 1, 9, 8)
609 end
610 elseif key == keys.p then
611 if throw_stuff then
612 throw_stuff = not(throw_stuff)
613 textOutput("", 22, 9, 12)
614 else
615 throw_stuff = true
616 textOutput("Throw items.", 22, 9, 12)
617 end
618 end
619 end
620 resetScreen()
621
622 textOutput("Do you want to save this configuration as your favorite ?", 1, 4, 0)
623 New_favorite = securedInput(1, 6, "text", 0, 0, "Yes", "No")
624
625 if (New_favorite == "y") then
626 favorite = {}
627 favorite.tunnels_integer = tunnels_integer
628 favorite.Width = Width
629 favorite.Height = Height
630 favorite.Length = Length
631 favorite.tunnels_separation = tunnels_separation
632 favorite.Torch_approval = Torch_approval
633 favorite.Chest_approval = Chest_approval
634 favorite.throw_stuff = throw_stuff
635 favorite.enderchest = enderchest
636 output = textutils.serialize(favorite)
637 handle = fs.open("favorite", "w")
638 handle.write(output)
639 handle.close()
640 end
641end
642resetScreen()
643textOutput("To manage extra slots, press s", 1, 4, 0)
644textOutput("This option allows you to have several torches/fuel/chests slots, as well as different items to throw", 1, 6, 0)
645textOutput("Else, press enter to skip this step.", 1, 10, 0)
646torches_slots, chests_slots, garbage_slots = 0, 0, 0
647while true do
648 press, key = os.pullEvent("key")
649 if press == "key" and key == keys.enter then
650 fuel_slots = 1
651 break
652 elseif key == keys.s then
653 repeat
654 turtle.select(1)
655 resetScreen()
656 textOutput("Number of fuel slots ? ", 1, 4, 0)
657 fuel_slots = securedInput(29, 4, "integer", 1, 16, " ", " ")
658 slot_total = fuel_slots
659 if Torch_approval then
660 textOutput("Number of torches slots ? ", 1, 5, 0)
661 torches_slots = securedInput(29, 5, "integer", 1, 16, " ", " ")
662 slot_total = slot_total + torches_slots
663 end
664 if Chest_approval and not(enderchest) then
665 textOutput("Number of chests slots ? ", 1, 6, 0)
666 chests_slots = securedInput(29, 6, "integer", 1, 16, " ", " ")
667 slot_total = slot_total + chests_slots
668 end
669 if throw_stuff then
670 textOutput("Number of undesired items ? ", 1, 7, 0)
671 garbage_slots = securedInput(29, 7, "integer", 1, 16, " ", " ")
672 slot_total = slot_total + garbage_slots
673 end
674 until (slot_total < 16)
675 break
676 end
677end
678resetScreen()
679if (tunnels_integer > 1) then
680 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)
681 Bool_direction = securedInput(1, 9, "text", 0, 0, "Right", "Left")
682end
683if (tunnels_integer == 1) and (Width > 1) then
684 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)
685 Bool_direction = securedInput(1, 9, "text", 0, 0, "Right", "Left")
686end
687resetScreen()
688if Torch_approval then
689 if torches_slots > 1 then
690 textOutput("Torches in the slots 1 to "..torches_slots, 1, 4, 0)
691 else
692 torches_slots = 1
693 textOutput("Torches in the slot 1", 1, 4, 0)
694 end
695end
696if fuel_slots > 1 then
697 textOutput("Fuel in the slots "..(torches_slots+1).." to "..(torches_slots+fuel_slots), 1, 5, 0)
698else
699 fuel_slots = 1
700 textOutput("Fuel in the slot "..(torches_slots+1), 1, 5, 0)
701end
702if Chest_approval and not(enderchest) then
703 if chests_slots > 1 then
704 textOutput("Chests in the slots "..(torches_slots+fuel_slots+1).." to "..(torches_slots+fuel_slots+chests_slots), 1, 6, 0)
705 else
706 chests_slots = 1
707 textOutput("Chests in the slot "..(torches_slots+fuel_slots+1), 1, 6, 0)
708 end
709end
710if enderchest then
711 textOutput("The enderchest in the slot "..(torches_slots+fuel_slots+1), 1, 6, 0)
712 chests_slots = 1
713end
714if throw_stuff then
715 if garbage_slots > 1 then
716 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)
717 else
718 garbage_slots = 1
719 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)
720 end
721end
722if (Bool_direction == "r") then
723 Bool_direction = true
724else
725 Bool_direction = false
726end
727textOutput("Press enter to start", 1, 11, 0)
728while true do
729 press, key = os.pullEvent("key")
730 if press == "key" and key == keys.enter then
731 break
732 end
733end
734resetScreen()
735
736-- Open wireless modem and announce run start
737emt_open_modem()
738emt_send("start", {config=true})
739textOutput("", 1, 11, 20)
740if Torch_approval and (turtle.getItemCount(1) == 0) then
741 textOutput("The torches slot is empty. Are you sure you want to use torches ?", 1, 4, 0)
742 Torch_approval = convertToBool(securedInput(1, 6, "text", 0, 0, "Yes", "No"), "y")
743elseif Torch_approval and (turtle.getItemCount(1) ~= 0) then
744 for u = 1, torches_slots-1 do
745 turtle.select(u+1)
746 if not(turtle.compareTo(1)) then
747 Torch_mismatch = true
748 end
749 end
750 if Torch_mismatch then
751 resetScreen()
752 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)
753 Torch_approval = convertToBool(securedInput(1, 7, "text", 0, 0, "Yes", "No"), "y")
754 end
755end
756
757if Chest_approval and (turtle.getItemCount(torches_slots + fuel_slots + 1) == 0) then
758 resetScreen()
759 textOutput("The chests slot is empty. Are you sure you want to use chests ?", 1, 4, 0)
760 Chest_approval = convertToBool(securedInput(1, 6, "text", 0, 0, "Yes", "No"), "y")
761elseif Chest_approval and (turtle.getItemCount(torches_slots + fuel_slots + 1) ~= 0) then
762 for u = 1, chests_slots-1 do
763 turtle.select(torches_slots + fuel_slots + u + 1)
764 if not(turtle.compareTo(torches_slots + fuel_slots + 1)) then
765 Chest_mismatch = true
766 end
767 end
768 if Chest_mismatch then
769 resetScreen()
770 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)
771 Chest_approval = convertToBool(securedInput(1, 7, "text", 0, 0, "Yes", "No"), "y")
772 end
773end
774if Torch_approval then
775 empty_torches_slots = 0
776 for u = 1, torches_slots do
777 if turtle.getItemCount(u) == 0 then
778 empty_torches_slots = empty_torches_slots + 1
779 end
780 end
781 if empty_torches_slots == torches_slots then
782 shortage[1] = true
783 end
784 textOutput("No Torches -", 11, 11, 0)
785end
786if Torch_approval and (turtle.getItemCount(1) ~= 0) then
787 shortage[1] = false
788 textOutput("Torches OK -", 11, 11, 0)
789end
790if Chest_approval then
791 empty_chests_slots = 0
792 for u = 1, chests_slots do
793 if turtle.getItemCount(torches_slots + fuel_slots + u) == 0 then
794 empty_chests_slots = empty_chests_slots + 1
795 end
796 end
797 if empty_chests_slots == chests_slots then
798 shortage[3] = true
799 end
800 textOutput("No Chests -", 24, 11, 0)
801end
802if Chest_approval and (turtle.getItemCount(torches_slots + fuel_slots + 1) ~= 0) then
803 shortage[3] = false
804 textOutput("Chests OK -", 24, 11, 0)
805end
806textOutput("Fuel OK -", 1, 11, 0)
807refuel_count = 80 - turtle.getFuelLevel()
808FacingAngle, tunnel_forth, current_slot= 0, true, {1, 1, 1}
809total_tunnels = tunnels_integer
810total_layers_per_tunnel = math.ceil(Length/2)
811current_tunnel, current_layer = 0, 0
812refuel_count = moveUp(true, 1, refuel_count, false)
813if (Width == 1) then
814 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
815end
816for done_tunnels=1, tunnels_integer do
817 current_tunnel = done_tunnels
818 if (Width >= 2) then
819 for done_layers=1, math.ceil(Length/2) do
820 current_layer = done_layers
821 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
822 FacingAngle = turn(FacingAngle, Bool_direction, 1)
823 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, Width, Height, "down", false, Bool_direction)
824 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
825 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
826 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
827 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, Width, Height, Height_Position, false, not(Bool_direction))
828 FacingAngle = turn(FacingAngle, Bool_direction, 1)
829 if (done_layers%4 == 0) then
830 refuel_count = moveUp(false, 1, refuel_count, false)
831 FacingAngle = turn(FacingAngle, Bool_direction, 1)
832 placeTorch("front")
833 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
834 refuel_count = moveUp(true, 1, refuel_count, false)
835 end
836 emt_send("progress")
837 end
838 elseif (Width == 1) then
839 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, 2*math.ceil(Length/2), Height, "down", true, Bool_direction)
840 current_layer = total_layers_per_tunnel
841 emt_send("progress")
842 end
843 if (Height_Position == "up") then
844 refuel_count = moveUp(false, (Height - 3), refuel_count, false)
845 Height_Position = "down"
846 end
847 if tunnel_forth and (tunnels_integer - done_tunnels >= 1) then
848 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
849 FacingAngle = turn(FacingAngle, Bool_direction, 1)
850 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)+tunnels_separation), Height, "down", false, not(Bool_direction))
851 if (Height_Position == "up") then
852 refuel_count = moveUp(false, (Height - 3), refuel_count, false)
853 Height_Position = "down"
854 end
855 FacingAngle = turn(FacingAngle, Bool_direction, 1)
856 placeTorch("below")
857 elseif not(tunnel_forth) then
858 refuel_count = moveForward(FacingAngle, true, 1, true, false, refuel_count)
859 FacingAngle = turn(FacingAngle, Bool_direction, 1)
860 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)-1+tunnels_separation), Height, "down", false, Bool_direction)
861 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
862 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
863 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
864 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)-1+tunnels_separation), Height, Height_Position, false, not(Bool_direction))
865 if (Height_Position == "up") then
866 refuel_count = moveUp(false, (Height - 3), refuel_count, false)
867 Height_Position = "down"
868 end
869 FacingAngle = turn(FacingAngle, Bool_direction, 2)
870 refuel_count = moveForward(FacingAngle, true, (Width-2), true, true, refuel_count)
871 placeTorch("front")
872 FacingAngle = turn(FacingAngle, not(Bool_direction), 2)
873 refuel_count = moveForward(FacingAngle, true, (Width-2), true, true, refuel_count)
874 if (tunnels_integer - done_tunnels ~= 0) then
875 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
876 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (tunnels_separation+1), Height, Height_Position, false, Bool_direction)
877 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
878 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
879 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
880 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (tunnels_separation+1), Height, Height_Position, false, not(Bool_direction))
881 refuel_count = moveForward(FacingAngle, false, tunnels_separation, true, true, refuel_count)
882 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
883 placeTorch("front")
884 FacingAngle = turn(FacingAngle, not(Bool_direction), 2)
885 end
886 end
887 if tunnel_forth and (tunnels_integer - done_tunnels == 0) and (Width > 1) then
888 refuel_count = moveForward(FacingAngle, false, 2*math.ceil(Length/2), false, false, refuel_count)
889 FacingAngle = turn(FacingAngle, Bool_direction, 1)
890 refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
891 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (Width - 1), Height, Height_Position, false, Bool_direction)
892 FacingAngle = turn(FacingAngle, Bool_direction, 1)
893 refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
894 FacingAngle = turn(FacingAngle, Bool_direction, 1)
895 refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (Width - 1), Height, Height_Position, false, not(Bool_direction))
896 if (Height_Position == "up") then
897 refuel_count = moveUp(false, (Height - 3), refuel_count, false)
898 Height_Position = "down"
899 end
900 refuel_count = moveForward(FacingAngle, false, (Width - 2), false, false, refuel_count)
901 FacingAngle = turn(FacingAngle, Bool_direction, 2)
902 end
903 if (Width == 1) and (tunnels_integer - done_tunnels ~= 0) then
904 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
905 elseif (Width == 1) and (tunnels_integer - done_tunnels == 0) and tunnel_forth then
906 refuel_count = moveForward(FacingAngle, false, (2*math.ceil(Length/2)), false, false, refuel_count)
907 end
908 tunnel_forth = not(tunnel_forth)
909 current_layer = 0
910 emt_send("tunnel_complete")
911end
912refuel_count = moveUp(false, 1, refuel_count, false)
913if (Width == 1) and not(tunnel_forth) then
914 refuel_count = moveForward(FacingAngle, false, 1, false, false, refuel_count)
915 turn(FacingAngle, Bool_direction, 1)
916end
917refuel_count = moveForward(FacingAngle, false, ((tunnels_integer*Width) - 1 + (tunnels_separation*(tunnels_integer - 1))), false, false, refuel_count)
918FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
919refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
920emt_send("done", {done=true})
921resetScreen()
922write("Done. I hope I worked well !")
923term.setCursorPos(1,8)