fbMarcel

| mine | Tunnels

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