Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     return 500
  110. end
  111. function moveForward(FacingAngle, Boolfb, moving_integer, digUpBool, digDownBool, refuel_count)
  112.     local moving_count = 1
  113.     for moving_count=1,moving_integer do
  114.         if (refuel_count == 80) then
  115.             refuel_count = refuel()
  116.         end
  117.         Bool1 = false
  118.         while not(Bool1) do
  119.             if (Boolfb) then
  120.                 turtle.dig()
  121.                 Bool1 = turtle.forward()
  122.                 if (digUpBool) then
  123.                     turtle.digUp()
  124.                 end
  125.                 if (digDownBool) then
  126.                     turtle.digDown()
  127.                 end  
  128.             else
  129.                 Bool1 = turtle.back()
  130.                 if not(Bool1) then
  131.                     turn(FacingAngle, true, 2)
  132.                     turtle.dig()
  133.                     turn(FacingAngle, false, 2)
  134.                 end
  135.             end    
  136.         end
  137.         moving_count = moving_count + 1
  138.         refuel_count = refuel_count + 1
  139.     end
  140.     return refuel_count  
  141. end
  142. function moveUp(Boolud, moving_integer, refuel_count, Bool_DigFront)
  143.     local moving_count = 1
  144.     for moving_count=1, moving_integer do
  145.         if (refuel_count == 80) then
  146.             refuel_count = refuel()
  147.         end
  148.         Bool2 = false
  149.         if Bool_DigFront then
  150.             turtle.dig()
  151.         end
  152.         while not(Bool2) do
  153.             if (Boolud) then
  154.                 turtle.digUp()  
  155.                 Bool2 = turtle.up()
  156.             else
  157.                 turtle.digDown()
  158.                 Bool2 = turtle.down()
  159.             end
  160.         end
  161.         moving_count = moving_count + 1
  162.         refuel_count = refuel_count + 1
  163.     end
  164.     return refuel_count
  165. end
  166. function manageShortage(managedItem, initial_item_slot, final_item_slot)
  167.     textOutput("The turtle has used all the "..(itemNames[managedItem+3]).." intitially given. Have you refilled all the "..(itemNames[managedItem+3]).." slots ?", 1, 4, 0)
  168.     textOutput("Press enter if all the "..(itemNames[managedItem+3]).." slots are refilled (slots "..(initial_item_slot).." to "..(final_item_slot)..").", 1, 7, 0)
  169.     repeat
  170.         turn(FacingAngle, true, 4)
  171.         os.startTimer(1)
  172.         press, key = os.pullEvent()
  173.     until (key == 28)
  174.     clearLines(4,10)
  175.     current_slot[managedItem] = 1
  176.     shortage[managedItem] = false
  177.     return current_slot[managedItem], shortage[managedItem]
  178. end
  179. function rotateSlot(managedItem, control_slot, rotation_controler)
  180.     if (turtle.getItemCount(control_slot) == 0) or (managedItem == 2) then         
  181.         if current_slot[managedItem]==rotation_controler and (managedItem ~= 2) then
  182.             shortage[managedItem] = true
  183.         else
  184.             current_slot[managedItem]=((current_slot[managedItem])%rotation_controler)+1
  185.         end
  186.     end
  187.     return current_slot[managedItem], shortage[managedItem]
  188. end                
  189. function inventoryManagement(refuel_count,Right_or_Left,throw_cobble)
  190.     function fullInventory(n)
  191.         n = m + 1
  192.         repeat
  193.             item_count = turtle.getItemCount(n)
  194.             if (item_count ~= 0) then          
  195.                 boolSlotOccupied = true
  196.                 n = n + 1  
  197.             else
  198.                 boolSlotOccupied = false  
  199.             end  
  200.         until (boolSlotOccupied == false) or (n == 17)
  201.         return n
  202.     end
  203.     if Chest_approval then
  204.         m = torches_slots + chests_slots + fuel_slots + garbage_slots
  205.         thrown_slots = 0
  206.         if (turtle.getItemCount(16) ~= 0) and (m~=16) then
  207.             if fullInventory(m)==17 then
  208.                 if throw_stuff then
  209.                     for k=1, garbage_slots do
  210.                         for j=1, (16-m) do
  211.                             turtle.select(m - garbage_slots + k)
  212.                             Bool_match_stuff = turtle.compareTo(m+j)
  213.                             if Bool_match_stuff then
  214.                                 thrown_slots = thrown_slots + 1
  215.                                 turtle.select(m+j)
  216.                                 turtle.drop()    
  217.                             end
  218.                         end
  219.                         turtle.select(m - garbage_slots + k)
  220.                         turtle.drop(turtle.getItemCount(m - garbage_slots + k)-1)
  221.                     end
  222.                     for z = (m+1), 16 do
  223.                         for u = (z+1), 16 do
  224.                             if turtle.getItemCount(u)~=0 then
  225.                                 turtle.select(u)
  226.                                 turtle.transferTo(z)
  227.                             end
  228.                         end
  229.                     end
  230.                 end
  231.                 if not(throw_stuff) or ((thrown_slots <= 2) and (fullInventory(n)>15)) then
  232.                     if shortage[3] then
  233.                         textOutput("No Chests", 24, 11, 0)
  234.                         current_slot[3], shortage[3] = manageShortage(3, torches_slots+fuel_slots+1, torches_slots+fuel_slots+chests_slots)
  235.                     end
  236.                     textOutput("Chests OK", 24, 11, 0)
  237.                     if (Right_or_Left == "left") then
  238.                         FacingAngle = turn(FacingAngle, true, 1)
  239.                     else
  240.                         FacingAngle = turn(FacingAngle, false, 1)
  241.                     end  
  242.                     refuel_count = moveForward(FacingAngle, true, 1, false, true, refuel_count)
  243.                     turtle.select(torches_slots+fuel_slots+current_slot[3])
  244.                     turtle.digDown()
  245.                     turtle.placeDown()
  246.                     for u=(m+1),16 do
  247.                         if turtle.getItemCount(u)~=0 then
  248.                             turtle.select(u)
  249.                             turtle.dropDown()
  250.                         end
  251.                     end
  252.                     if enderchest then
  253.                         turtle.select(torches_slots+fuel_slots+1)
  254.                         turtle.drop()
  255.                         turtle.digDown()
  256.                     end
  257.                     current_slot[3], shortage[3] = rotateSlot(3, torches_slots+fuel_slots+current_slot[3], chests_slots)
  258.                     refuel_count = moveForward(FacingAngle, false, 1, false, false, refuel_count)
  259.                     if (Right_or_Left == "left") then
  260.                         FacingAngle = turn(FacingAngle, false, 1)
  261.                     else
  262.                         FacingAngle = turn(FacingAngle, true, 1)
  263.                     end
  264.                 end  
  265.             end
  266.         end
  267.     end
  268.     turtle.select(1)
  269.     return refuel_count  
  270. end
  271. function placeTorch(Position)
  272.     if Torch_approval then
  273.         if shortage[1] then
  274.             textOutput("No Torches -", 11, 11, 0)
  275.             current_slot[1], shortage[1] = manageShortage(1, 1, torches_slots)
  276.         end
  277.         textOutput("Torches OK -", 11, 11, 0)
  278.         turtle.select(current_slot[1])
  279.         if Position == "front" then
  280.             turtle.dig()
  281.             turtle.place()
  282.         elseif Position ==  "below" then
  283.             turtle.digDown()
  284.             turtle.placeDown()
  285.         elseif Position == "up" then
  286.             turtle.digUp()
  287.             turtle.placeUp()
  288.         end
  289.         current_slot[1], shortage[1] = rotateSlot(1, current_slot[1], torches_slots)
  290.     end
  291. end
  292. function digVerticalLayer(refuel_count, FacingAngle, Width, Height, Height_Position, Bool_Torches, Right_or_Left)
  293.     if Right_or_Left then
  294.         Right_or_Left = "left"
  295.     else
  296.         Right_or_Left = "right"
  297.     end
  298.     done_columns = 0
  299.     if (Height_Position == "up") then
  300.         for columns=1, math.floor(Width/4) do
  301.             turtle.digUp()
  302.             if (Height > 3) then
  303.                 refuel_count = moveUp(true, 1, refuel_count, false)
  304.                 turtle.dig()
  305.                 refuel_count = moveUp(false, (Height-2), refuel_count, true)
  306.                 turtle.digDown()
  307.             end
  308.             refuel_count = moveForward(FacingAngle, true, 2, true, true, refuel_count)
  309.             refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
  310.             if (Height > 3) then
  311.                 refuel_count = moveUp(false, 1, refuel_count, false)
  312.                 turtle.dig()
  313.                 refuel_count = moveUp(true, (Height-2), refuel_count, true)
  314.                 turtle.digUp()
  315.             end
  316.             refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  317.             done_columns = done_columns + 1
  318.             if (Width - 4*done_columns ~= 0) then
  319.                 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  320.             end
  321.         end  
  322.         if ((Width - 4*math.floor(Width/4)) == 0) then
  323.             Height_Position = "up"
  324.         elseif ((Width - 4*math.floor(Width/4)) == 1) then
  325.             turtle.digUp()
  326.             refuel_count = moveUp(false, (Height-3), refuel_count, false)
  327.             turtle.digDown()
  328.             refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
  329.             Height_Position = "down"
  330.         elseif ((Width - 4*math.floor(Width/4)) >= 2) then
  331.             if (Height > 3) then
  332.                 refuel_count = moveUp(true, 1, refuel_count, false)
  333.                 turtle.dig()
  334.                 refuel_count = moveUp(false, (Height-2), refuel_count, true)
  335.                 turtle.digDown()
  336.             end
  337.             turtle.digUp()
  338.             refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  339.             refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
  340.             Height_Position = "down"
  341.             if ((Width - 4*math.floor(Width/4)) == 3) then
  342.                 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  343.                 refuel_count = moveUp(true, (Height - 3), refuel_count, false)
  344.                 turtle.digUp()
  345.                 Height_Position = "up"
  346.             end
  347.         end
  348.     elseif (Height_Position == "down") then
  349.         for columns=1, math.floor(Width/4) do
  350.             turtle.digDown()
  351.             if (Height > 3) then
  352.                 refuel_count = moveUp(false, 1, refuel_count, false)
  353.                 turtle.dig()
  354.                 refuel_count = moveUp(true, (Height - 2), refuel_count, true)
  355.                 turtle.digUp()
  356.             end
  357.             refuel_count = moveForward(FacingAngle, true, 2, true, true, refuel_count)
  358.             if (Height > 3) then
  359.                 refuel_count = moveUp(true, 1, refuel_count, false)
  360.                 turtle.dig()
  361.                 refuel_count = moveUp(false, (Height - 2), refuel_count, true)
  362.                 turtle.digDown()
  363.             end
  364.             refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  365.             done_columns = done_columns + 1
  366.             if (Width - 4*done_columns ~= 0) then
  367.                 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  368.             end
  369.             refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
  370.             if (done_columns%2 == 0) and Bool_Torches then
  371.                 FacingAngle = turn(FacingAngle,true , 1)
  372.                 placeTorch("front")
  373.                 FacingAngle = turn(FacingAngle, false, 1)
  374.             end
  375.         end
  376.         if ((Width - 4*math.floor(Width/4)) == 0) then
  377.             Height_Position = "down"
  378.         elseif ((Width - 4*math.floor(Width/4)) == 1) then
  379.             turtle.digDown()     
  380.             refuel_count = moveUp(true, (Height - 3), refuel_count, false)
  381.             turtle.digUp()
  382.             Height_Position = "up"
  383.         elseif ((Width - 4*math.floor(Width/4)) >= 2) then
  384.             if (Height > 3) then
  385.                 refuel_count = moveUp(false, 1, refuel_count, false)
  386.                 turtle.dig()     
  387.                 refuel_count = moveUp(true, (Height - 2), refuel_count, true)
  388.                 turtle.digUp()
  389.             end
  390.             turtle.digDown()
  391.             refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  392.             Height_Position = "up"
  393.             if ((Width - 4*math.floor(Width/4)) == 3) then
  394.                 refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  395.                 refuel_count = moveUp(false, (Height - 3), refuel_count, false)
  396.                 turtle.digDown()
  397.                 refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
  398.                 Height_Position = "down"
  399.             end    
  400.         end      
  401.     end
  402.     return refuel_count, Height_Position     
  403. end
  404.  
  405. enderchest, throw_stuff, Chest_approval, Torch_approval, Chest_mismatch, Torch_mismatch = false, false, false, false, false, false
  406. shortage, itemNames = {false, false, false}, {"torch", "fuel", "chest", "torches", "fuel", "chests"}
  407.  
  408. resetScreen()
  409. if (io.open("favorite", "r") ~= nil) then
  410.         resetScreen()
  411.         textOutput("Do you wish to use your favorite configuration ?", 1, 4, 0)
  412.         Favorite_approval = securedInput(1, 6, "text", 0, 0, "Yes", "No")
  413.     if (Favorite_approval == "y") then
  414.         handle = fs.open("favorite", "r")
  415.         input = handle.readAll()
  416.         handle.close()
  417.         favorite = textutils.unserialize(input)
  418.         tunnels_integer = favorite.tunnels_integer
  419.         Width = favorite.Width
  420.         Height = favorite.Height
  421.         Length = favorite.Length
  422.         tunnels_separation = favorite.tunnels_separation
  423.         throw_stuff = favorite.throw_stuff
  424.         enderchest = favorite.enderchest
  425.         Torch_approval = favorite.Torch_approval
  426.         Chest_approval = favorite.Chest_approval
  427.     end
  428. end
  429. if (io.open("favorite", "r") == nil) or ((io.open("favorite", "r") ~= nil) and (Favorite_approval == "n")) then
  430.     resetScreen()
  431.     textOutput("Number of parallel tunnels ? ", 1, 4, 0)
  432.     tunnels_integer = securedInput(37, 4, "integer", 1, 1000, " ", " ")
  433.     textOutput("Width of the tunnels ? ", 1, 5, 0)
  434.     Width = securedInput(37, 5, "integer", 1, 1000, " ", " ")
  435.     term.setCursorPos(1,6)
  436.     textOutput("Height of the tunnels ? ", 1, 6, 0)
  437.     Height = securedInput(37, 6, "integer", 1, 200, " ", " ")
  438.     if (Height < 3) then
  439.         Height = 3
  440.     end
  441.     term.setCursorPos(1,7)
  442.     textOutput("Length of the tunnels ? ", 1, 7, 0)
  443.     Length = securedInput(37, 7, "integer", 1, 100000, " ", " ")
  444.     if (tunnels_integer > 1) then
  445.         term.setCursorPos(1,8)
  446.         textOutput("Separating blocks between tunnels ? ", 1, 8, 0)
  447.         tunnels_separation = securedInput(37, 8, "integer", 1, 1000, " ", " ")
  448.     else
  449.         tunnels_separation = 0
  450.     end
  451.    
  452.     resetScreen()
  453.     textOutput("To use regular chests, press c", 1, 4, 0)
  454.     textOutput("To use an enderchest, press e", 1, 5, 0)
  455.     textOutput("To use torches, press t", 1, 6, 0)
  456.     textOutput("To throw away specific items, press p", 1, 7, 0)
  457.     textOutput("Press enter once you have chosen all the options you wanted to activate.", 1, 11, 0)
  458.     while true do
  459.         press, key = os.pullEvent()
  460.         if press == "key" and key == 28 then
  461.             break
  462.         elseif key == 46 then
  463.             if Chest_approval then
  464.                 Chest_approval = false
  465.                 textOutput("", 10, 9, 11)
  466.             else   
  467.                 Chest_approval = true
  468.                 textOutput("Chests,", 10, 9, 11)
  469.             end
  470.         elseif key == 18 then
  471.             if enderchest then
  472.                 enderchest = not(enderchest)
  473.                 textOutput("", 10, 9, 11)
  474.             else
  475.                 Chest_approval = true
  476.                 enderchest = true
  477.                 textOutput("Enderchest,", 10, 9, 11)
  478.             end
  479.         elseif key == 20 then
  480.             if Torch_approval then
  481.                 Torch_approval = false
  482.                 textOutput("", 1, 9, 8)
  483.             else
  484.                 Torch_approval = true
  485.                 textOutput("Torches,", 1, 9, 8)
  486.             end
  487.         elseif key == 25 then
  488.             if throw_stuff then
  489.                 throw_stuff = not(throw_stuff)
  490.                 textOutput("", 22, 9, 12)          
  491.             else   
  492.                 throw_stuff = true
  493.                 textOutput("Throw items.", 22, 9, 12)
  494.             end
  495.         end
  496.     end
  497.     resetScreen()
  498.    
  499.     textOutput("Do you want to save this configuration as your favorite ?", 1, 4, 0)
  500.     New_favorite = securedInput(1, 6, "text", 0, 0, "Yes", "No")
  501.    
  502.     if (New_favorite == "y") then
  503.         favorite = {}
  504.         favorite.tunnels_integer = tunnels_integer
  505.         favorite.Width = Width
  506.         favorite.Height = Height
  507.         favorite.Length = Length
  508.         favorite.tunnels_separation = tunnels_separation
  509.         favorite.Torch_approval = Torch_approval
  510.         favorite.Chest_approval = Chest_approval
  511.         favorite.throw_stuff = throw_stuff
  512.         favorite.enderchest = enderchest
  513.         output = textutils.serialize(favorite)
  514.         handle = fs.open("favorite", "w")
  515.         handle.write(output)
  516.         handle.close()
  517.     end
  518. end
  519. resetScreen()
  520. textOutput("To manage extra slots, press s", 1, 4, 0)
  521. textOutput("This option allows you to have several torches/fuel/chests slots, as well as different items to throw", 1, 6, 0)
  522. textOutput("Else, press enter to skip this step.", 1, 10, 0)
  523. torches_slots, chests_slots, garbage_slots = 0, 0, 0   
  524. while true do
  525.     press, key = os.pullEvent()
  526.     if press == "key" and key == 28 then
  527.         fuel_slots = 1
  528.         break
  529.     elseif key == 31 then
  530.         repeat
  531.             turtle.select(1)
  532.             resetScreen()
  533.             textOutput("Number of fuel slots ? ", 1, 4, 0)
  534.             fuel_slots = securedInput(29, 4, "integer", 1, 16, " ", " ")   
  535.             slot_total = fuel_slots
  536.             if Torch_approval then 
  537.                 textOutput("Number of torches slots ? ", 1, 5, 0)
  538.                 torches_slots = securedInput(29, 5, "integer", 1, 16, " ", " ")
  539.                 slot_total = slot_total + torches_slots
  540.             end
  541.             if Chest_approval  and not(enderchest) then
  542.                 textOutput("Number of chests slots ? ", 1, 6, 0)
  543.                 chests_slots = securedInput(29, 6, "integer", 1, 16, " ", " ")
  544.                 slot_total = slot_total + chests_slots
  545.             end
  546.             if throw_stuff then
  547.                 textOutput("Number of undesired items ? ", 1, 7, 0)
  548.                 garbage_slots = securedInput(29, 7, "integer", 1, 16, " ", " ")
  549.                 slot_total = slot_total + garbage_slots
  550.             end
  551.         until (slot_total < 16)
  552.         break
  553.     end
  554. end
  555. resetScreen()
  556. if (tunnels_integer > 1) then
  557.     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)
  558.     Bool_direction = securedInput(1, 9, "text", 0, 0, "Right", "Left")
  559. end
  560. if (tunnels_integer == 1) and (Width > 1) then
  561.     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)
  562.     Bool_direction = securedInput(1, 9, "text", 0, 0, "Right", "Left")
  563. end
  564. resetScreen()
  565. if Torch_approval then
  566.     if torches_slots > 1 then
  567.         textOutput("Torches in the slots 1 to "..torches_slots, 1, 4, 0)
  568.     else
  569.         torches_slots = 1
  570.         textOutput("Torches in the slot 1", 1, 4, 0)
  571.     end
  572. end
  573. if fuel_slots > 1 then
  574.     textOutput("Fuel in the slots "..(torches_slots+1).." to "..(torches_slots+fuel_slots), 1, 5, 0)
  575. else
  576.     fuel_slots = 1
  577.     textOutput("Fuel in the slot "..(torches_slots+1), 1, 5, 0)
  578. end
  579. if Chest_approval  and not(enderchest) then
  580.     if chests_slots > 1 then
  581.         textOutput("Chests in the slots "..(torches_slots+fuel_slots+1).." to "..(torches_slots+fuel_slots+chests_slots), 1, 6, 0)
  582.     else
  583.         chests_slots = 1
  584.         textOutput("Chests in the slot "..(torches_slots+fuel_slots+1), 1, 6, 0)
  585.     end
  586. end    
  587. if enderchest then
  588.     textOutput("The enderchest in the slot "..(torches_slots+fuel_slots+1), 1, 6, 0)
  589.     chests_slots = 1
  590. end
  591. if throw_stuff then
  592.     if garbage_slots > 1 then
  593.         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)
  594.     else
  595.         garbage_slots = 1
  596.         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)
  597.     end
  598. end  
  599. if (Bool_direction == "r") then
  600.     Bool_direction = true
  601. else
  602.     Bool_direction = false
  603. end
  604. textOutput("Press enter to start", 1, 11, 0)
  605. while true do
  606.     press, key = os.pullEvent()
  607.     if press == "key" and key == 28 then
  608.         break
  609.     end
  610. end
  611. resetScreen()
  612. textOutput("", 1, 11, 20)
  613. if Torch_approval and (turtle.getItemCount(1) == 0) then
  614.     textOutput("The torches slot is empty. Are you sure you want to use torches ?", 1, 4, 0)
  615.     Torch_approval = convertToBool(securedInput(1, 6, "text", 0, 0, "Yes", "No"), "y")
  616. elseif Torch_approval and (turtle.getItemCount(1) ~= 0) then
  617.     for u = 1, torches_slots-1 do
  618.         turtle.select(u+1)
  619.         if  not(turtle.compareTo(1)) then
  620.             Torch_mismatch = true
  621.         end
  622.     end
  623.     if Torch_mismatch then
  624.         resetScreen()
  625.         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)
  626.         Torch_approval = convertToBool(securedInput(1, 7, "text", 0, 0, "Yes", "No"), "y")
  627.     end
  628. end
  629.  
  630. if Chest_approval and (turtle.getItemCount(torches_slots + fuel_slots + 1) == 0) then
  631.     resetScreen()
  632.     textOutput("The chests slot is empty. Are you sure you want to use chests ?", 1, 4, 0)
  633.     Chest_approval = convertToBool(securedInput(1, 6, "text", 0, 0, "Yes", "No"), "y")
  634. elseif Chest_approval and (turtle.getItemCount(torches_slots + fuel_slots + 1) ~= 0) then
  635.     for u = 1, chests_slots-1 do
  636.         turtle.select(torches_slots + fuel_slots + u + 1)
  637.         if  not(turtle.compareTo(torches_slots + fuel_slots + 1)) then
  638.             Chest_mismatch = true
  639.         end
  640.     end
  641.     if Chest_mismatch then
  642.         resetScreen()
  643.         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)
  644.         Chest_approval = convertToBool(securedInput(1, 7, "text", 0, 0, "Yes", "No"), "y")
  645.     end
  646. end
  647. if Torch_approval then
  648.     empty_torches_slots = 0
  649.     for u = 1, torches_slots do
  650.         if turtle.getItemCount(u) == 0 then
  651.             empty_torches_slots = empty_torches_slots + 1
  652.         end
  653.     end
  654.     if empty_torches_slots == torches_slots then
  655.         shortage[1] = true
  656.     end
  657.     textOutput("No Torches -", 11, 11, 0)
  658. end
  659. if Torch_approval and (turtle.getItemCount(1) ~= 0) then
  660.     shortage[1] = false
  661.     textOutput("Torches OK -", 11, 11, 0)
  662. end
  663. if Chest_approval then
  664.     empty_chests_slots = 0
  665.     for u = 1, chests_slots do
  666.         if turtle.getItemCount(torches_slots + fuel_slots + u) == 0 then
  667.             empty_chests_slots = empty_chests_slots + 1
  668.         end
  669.     end
  670.     if empty_chests_slots == chests_slots then
  671.         shortage[3] = true
  672.     end
  673.     textOutput("No Chests -", 24, 11, 0)
  674. end
  675. if Chest_approval and (turtle.getItemCount(torches_slots + fuel_slots + 1) ~= 0) then
  676.     shortage[3] = false
  677.     textOutput("Chests OK -", 24, 11, 0)
  678. end
  679. textOutput("Fuel OK -", 1, 11, 0)
  680. refuel_count = 80 - turtle.getFuelLevel()
  681. FacingAngle, tunnel_forth, current_slot= 0, true, {1, 1, 1}
  682. refuel_count = moveUp(true, 1, refuel_count, false)
  683. if (Width == 1) then
  684.     refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  685. end
  686. for done_tunnels=1, tunnels_integer do
  687.     if (Width >= 2) then
  688.         for done_layers=1, math.ceil(Length/2) do
  689.             refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  690.             FacingAngle = turn(FacingAngle, Bool_direction, 1)
  691.             refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, Width, Height, "down", false, Bool_direction)
  692.             FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  693.             refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  694.             FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  695.             refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, Width, Height, Height_Position, false, not(Bool_direction))
  696.             FacingAngle = turn(FacingAngle, Bool_direction, 1)
  697.             if (done_layers%4 == 0) then
  698.                 refuel_count = moveUp(false, 1, refuel_count, false)
  699.                 FacingAngle = turn(FacingAngle, Bool_direction, 1)
  700.                 placeTorch("front")
  701.                 FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  702.                 refuel_count = moveUp(true, 1, refuel_count, false)
  703.             end
  704.         end
  705.     elseif (Width == 1) then
  706.         refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, 2*math.ceil(Length/2), Height, "down", true, Bool_direction)
  707.     end
  708.     if (Height_Position == "up") then
  709.         refuel_count = moveUp(false, (Height - 3), refuel_count, false)
  710.         Height_Position = "down"
  711.     end
  712.     if tunnel_forth and (tunnels_integer - done_tunnels >= 1) then
  713.         refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  714.         FacingAngle = turn(FacingAngle, Bool_direction, 1)
  715.         refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)+tunnels_separation), Height, "down", false, not(Bool_direction))
  716.         if (Height_Position == "up") then
  717.             refuel_count = moveUp(false, (Height - 3), refuel_count, false)
  718.             Height_Position = "down"
  719.         end
  720.         FacingAngle = turn(FacingAngle, Bool_direction, 1)
  721.         placeTorch("below")
  722.     elseif not(tunnel_forth) then
  723.         refuel_count = moveForward(FacingAngle, true, 1, true, false, refuel_count)
  724.         FacingAngle = turn(FacingAngle, Bool_direction, 1)
  725.         refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)-1+tunnels_separation), Height, "down", false, Bool_direction)
  726.         FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  727.         refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  728.         FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  729.         refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)-1+tunnels_separation), Height, Height_Position, false, not(Bool_direction))
  730.         if (Height_Position == "up") then
  731.             refuel_count = moveUp(false, (Height - 3), refuel_count, false)
  732.             Height_Position = "down"
  733.         end
  734.         FacingAngle = turn(FacingAngle, Bool_direction, 2)
  735.         refuel_count = moveForward(FacingAngle, true, (Width-2), true, true, refuel_count)
  736.         placeTorch("front")
  737.         FacingAngle = turn(FacingAngle, not(Bool_direction), 2)
  738.         refuel_count = moveForward(FacingAngle, true, (Width-2), true, true, refuel_count)
  739.         if (tunnels_integer - done_tunnels ~= 0) then
  740.             refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  741.             refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (tunnels_separation+1), Height, Height_Position, false, Bool_direction)
  742.             FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  743.             refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  744.             FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  745.             refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (tunnels_separation+1), Height, Height_Position, false, not(Bool_direction))
  746.             refuel_count = moveForward(FacingAngle, false, tunnels_separation, true, true, refuel_count)
  747.             FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  748.             placeTorch("front")
  749.             FacingAngle = turn(FacingAngle, not(Bool_direction), 2)
  750.         end
  751.     end
  752.     if tunnel_forth and (tunnels_integer - done_tunnels == 0) and (Width > 1) then
  753.         refuel_count = moveForward(FacingAngle, false, 2*math.ceil(Length/2), false, false, refuel_count)
  754.         FacingAngle = turn(FacingAngle, Bool_direction, 1)
  755.         refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
  756.         refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (Width - 1), Height, Height_Position, false, Bool_direction)
  757.         FacingAngle = turn(FacingAngle, Bool_direction, 1)
  758.         refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
  759.         FacingAngle = turn(FacingAngle, Bool_direction, 1)
  760.         refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (Width - 1), Height, Height_Position, false, not(Bool_direction))
  761.         if (Height_Position == "up") then
  762.             refuel_count = moveUp(false, (Height - 3), refuel_count, false)
  763.             Height_Position = "down"
  764.         end
  765.         refuel_count = moveForward(FacingAngle, false, (Width - 2), false, false, refuel_count)
  766.         FacingAngle = turn(FacingAngle, Bool_direction, 2)
  767.     end
  768.     if (Width == 1) and (tunnels_integer - done_tunnels ~= 0) then
  769.         refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  770.     elseif (Width == 1) and (tunnels_integer - done_tunnels == 0) and tunnel_forth then
  771.         refuel_count = moveForward(FacingAngle, false, (2*math.ceil(Length/2)), false, false, refuel_count)
  772.     end
  773.     tunnel_forth = not(tunnel_forth)
  774. end
  775. refuel_count = moveUp(false, 1, refuel_count, false)
  776. if (Width == 1) and not(tunnel_forth) then
  777.     refuel_count = moveForward(FacingAngle, false, 1, false, false, refuel_count)
  778.     turn(FacingAngle, Bool_direction, 1)
  779. end
  780. refuel_count = moveForward(FacingAngle, false, ((tunnels_integer*Width) - 1 + (tunnels_separation*(tunnels_integer - 1))), false, false, refuel_count)
  781. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  782. refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
  783. resetScreen()
  784. write("Done. I hope I worked well !")
  785. term.setCursorPos(1,8)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement