Advertisement
Guest User

Miner

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