Advertisement
Guest User

Mine

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