McMrARM

Computercraft miner

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