Jebula999

do

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