KiLMaN95

Untitled

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