SpoonTune

Untitled

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