eforen

General Strip Miner

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