MiStAWaFFlEZZ

BranchTurtle_Final

Dec 29th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.40 KB | None | 0 0
  1. function shaft()
  2.     --main shaft
  3.     term.clear()
  4.     term.setCursorPos(1,1)
  5.     print("Digging shaft")
  6.     count = 0
  7.  branchcount = 0
  8.     --for count = 0, tonumber(mainshaft) do
  9.     repeat
  10.         turtle.dig()
  11.         if turtle.forward() then
  12.             count = count + 1
  13.             branchcount = branchcount + 1
  14.         end
  15.         turtle.digUp()
  16.         if branchcount == 4 then --branch clause
  17.             print("Branching!")
  18.             branch()
  19.             branchcount = 0
  20.         end
  21.         --reset variables
  22.         percent() --percent complete clause
  23.         until count == tonumber(mainshaft)
  24.     --end
  25.     --final inv check
  26.     finalinv()
  27.     count = 0
  28. end
  29.  
  30. function branch()
  31.     --branch
  32.     --left first
  33.     local torchplace = 0
  34.     local turtlereturnleft = 0
  35.     local turtlereturnright = 0
  36.     turtle.turnLeft()
  37.     local branchleftcount = 0
  38.     repeat
  39.      --for branchleftcount = 0, tonumber(branchshaft) do
  40.         turtle.dig()
  41.         --turtle.forward()
  42.  
  43.         if turtle.forward() then
  44.             turtlereturnleft = turtlereturnleft + 1
  45.             branchleftcount = branchleftcount + 1
  46.         end
  47.         turtle.digUp()
  48.      --end
  49.     until branchleftcount == tonumber(branchshaft)
  50.     turtle.turnLeft()
  51.     turtle.turnLeft()
  52.     repeat
  53.       turtle.dig()
  54.      -- turtle.forward()
  55.       if turtle.forward() then
  56.         turtlereturnleft = turtlereturnleft - 1
  57.         torchplace = torchplace + 1
  58.       end
  59.       if placetorches == true then
  60.        if torchplace == 5 then
  61.         if turtle.getItemCount(1) > 1 then -- don't want to run out of torches. will fill tunnel with random block (in slot 1)
  62.         turtle.select(1) --select torches
  63.         turtle.placeUp()
  64.         torchplace = 0
  65.         else
  66.         print("Torch supply low")
  67.        end
  68.       end
  69.       end
  70.       --turtle.digUp()
  71.     until turtlereturnleft == 0
  72.    
  73.     --right now
  74.     torchplace = 0
  75.     local branchrightcount = 0
  76.     repeat
  77.     -- for branchrightcount = 0, tonumber(branchshaft) do --UNCOMMENT THIS AND 56 FOR OLD SYSTEM
  78.         turtle.dig()
  79.         --turtle.forward()
  80.         if turtle.forward() then
  81.             turtlereturnright = turtlereturnright + 1
  82.             branchrightcount = branchrightcount + 1
  83.         end
  84.         turtle.digUp()
  85.     until branchrightcount == tonumber(branchshaft)
  86.     --end --UNCOMMENT THIS AND 48 FOR OLD SYSTEM
  87.     turtle.turnLeft()
  88.     turtle.turnLeft()
  89.     repeat
  90.       turtle.dig()
  91.      -- turtle.forward()
  92.       if turtle.forward() then
  93.         turtlereturnright = turtlereturnright - 1
  94.         torchplace = torchplace + 1
  95.       end
  96.       if placetorches == true then
  97.        if torchplace == 5 then
  98.         if turtle.getItemCount(1) > 1 then -- don't want to run out of torches. will fill tunnel with random block (in slot 1)
  99.         turtle.select(1) --select torches
  100.         turtle.placeUp()
  101.         torchplace = 0
  102.         else
  103.         print("Torch supply low")
  104.        end
  105.       end
  106.      end
  107.      -- turtle.digUp()
  108.     until turtlereturnright == 0   
  109.     turtle.turnRight()
  110.     print("Finished Branching!")
  111.     if usechest == true then
  112.         invcheck() -- CHECK INVENTORY
  113.     end
  114.     end
  115.  
  116. function invcheck()
  117.     --inventory checking
  118.     print("Checking Inventory...")
  119.     if turtle.getItemCount(16) ~= 0 then
  120.         print("Ejecting Inventory!")
  121.         turtle.select(2)
  122.         if turtle.placeUp then
  123.             turtle.digUp()
  124.             turtle.placeUp()
  125.             turtle.select(3)
  126.             turtle.dropUp()
  127.             turtle.select(4)
  128.             turtle.dropUp()
  129.             turtle.select(5)
  130.             turtle.dropUp()    
  131.             turtle.select(6)
  132.             turtle.dropUp()
  133.             turtle.select(7)
  134.             turtle.dropUp()    
  135.             turtle.select(8)
  136.             turtle.dropUp()    
  137.             turtle.select(9)
  138.             turtle.dropUp()    
  139.             turtle.select(10)
  140.             turtle.dropUp()
  141.             turtle.select(11)
  142.             turtle.dropUp()
  143.             turtle.select(12)
  144.             turtle.dropUp()
  145.             turtle.select(13)
  146.             turtle.dropUp()
  147.             turtle.select(14)
  148.             turtle.dropUp()
  149.             turtle.select(15)
  150.             turtle.dropUp()
  151.             turtle.select(16)
  152.             turtle.dropUp()
  153.             --print("Dropped 3x3 Area! Transferring for next check!")
  154.                 -- MOVING ITEMS
  155.             --  turtle.select(4)
  156.             --  turtle.transferTo(3)
  157.             --  turtle.select(8)
  158.             --  turtle.transferTo(5)
  159.             --  turtle.select(12)
  160.             --  turtle.transferTo(6)
  161.             --  turtle.select(13)
  162.             --  turtle.transferTo(7)
  163.             --  turtle.select(14)
  164.             --  turtle.transferTo(9)
  165.             --  turtle.select(15)
  166.             --  turtle.transferTo(10)
  167.             --  turtle.select(16)
  168.             --  turtle.transferTo(11)              
  169.             print("Transferred Inventory! Collecting Chest!")
  170.             turtle.select(2)
  171.             turtle.digUp()
  172.         else
  173.             turtle.digUp()
  174.             turtle.placeUp()
  175.             turtle.select(3)
  176.             turtle.dropUp()
  177.             --turtle.select(4)
  178.             --turtle.dropUp()
  179.             turtle.select(5)
  180.             turtle.dropUp()    
  181.             turtle.select(6)
  182.             turtle.dropUp()
  183.             turtle.select(7)
  184.             turtle.dropUp()    
  185.             --turtle.select(8)
  186.             --turtle.dropUp()      
  187.             turtle.select(9)
  188.             turtle.dropUp()    
  189.             turtle.select(10)
  190.             turtle.dropUp()
  191.             turtle.select(11)
  192.             turtle.dropUp()
  193.             --turtle.select(12)
  194.             --turtle.dropUp()
  195.             --turtle.select(13)
  196.             --turtle.dropUp()
  197.             --turtle.select(14)
  198.             --turtle.dropUp()
  199.             --turtle.select(15)
  200.             --turtle.dropUp()
  201.             --turtle.select(16)
  202.             --turtle.dropUp()
  203.             print("Dropped 3x3 Area! Transferring for next check!")
  204.                 -- MOVING ITEMS
  205.                 turtle.select(4)
  206.                 turtle.transferTo(3)
  207.                 turtle.select(8)
  208.                 turtle.transferTo(5)
  209.                 turtle.select(12)
  210.                 turtle.transferTo(6)
  211.                 turtle.select(13)
  212.                 turtle.transferTo(7)
  213.                 turtle.select(14)
  214.                 turtle.transferTo(9)
  215.                 turtle.select(15)
  216.                 turtle.transferTo(10)
  217.                 turtle.select(16)
  218.                 turtle.transferTo(11)          
  219.             print("Dropped Inventory! Collecting Chest!")
  220.             turtle.select(2)
  221.             turtle.digUp()
  222.      end
  223.     else
  224.         print("Inventory Fine!")
  225.     end
  226. end
  227. function finalinv()
  228.     print("Excreting inventory!")
  229.     sleep(1)
  230.     turtle.digUp()
  231.     turtle.select(2)
  232.             turtle.digUp()
  233.             turtle.placeUp()
  234.             turtle.select(3)
  235.             turtle.dropUp()
  236.             sleep(1)
  237.             turtle.select(4)
  238.             turtle.dropUp()
  239.             sleep(1)
  240.             turtle.select(5)
  241.             turtle.dropUp()    
  242.             sleep(1)
  243.             turtle.select(6)
  244.             turtle.dropUp()
  245.             sleep(1)
  246.             turtle.select(7)
  247.             turtle.dropUp()    
  248.                         sleep(1)
  249.             turtle.select(8)
  250.             turtle.dropUp()
  251.             sleep(1)           
  252.             turtle.select(9)
  253.             turtle.dropUp()
  254.             sleep(1)           
  255.             turtle.select(10)
  256.             turtle.dropUp()
  257.                         sleep(1)
  258.             turtle.select(11)
  259.             turtle.dropUp()
  260.                         sleep(1)
  261.             turtle.select(12)
  262.             turtle.dropUp()
  263.                         sleep(1)
  264.             turtle.select(13)
  265.             turtle.dropUp()
  266.                         sleep(1)
  267.             turtle.select(14)
  268.             turtle.dropUp()
  269.                         sleep(1)
  270.             turtle.select(15)
  271.             turtle.dropUp()
  272.                         sleep(1)
  273.             turtle.select(16)
  274.             turtle.dropUp()
  275.                         sleep(1)
  276.             print("Done!")
  277. end
  278.  
  279. function percent()
  280.     --percentage completion
  281.     local percent = count/mainshaft*100
  282.     --print( ..count.. " of " ..mineshaft.. )
  283.     print("Percent Complete:" ..percent.. "%")
  284. end
  285.  
  286. print("Branch Miner")
  287. print("Type begin to begin")
  288. local confirm = read()
  289. if confirm == "begin" then
  290.     print("How long should the main shaft be? Default: 64")
  291.     mainshaft = read()
  292.     print("Digging the main shaft " ..mainshaft..  " blocks long")
  293.     sleep(1)
  294.     print("How long should branches be? Default: 32")
  295.     branchshaft = read()
  296.     print("Digging the branch shafts " ..branchshaft..  " blocks long")
  297.     -- TORCHES
  298.     print("Place Torches? (y/n)")
  299.     local torches = read()
  300.     if torches == "y" then
  301.         print("Torches MUST be in slot 1! I will (try) to place them!")
  302.         placetorches = true
  303.     end
  304.     --ENDERCHEST
  305.     print("Use Ender Chests to empty inventory? (y/n)")
  306.     local chests = read()
  307.     if chests == "y" then
  308.         print("Currently WIP. Place chest in slot 2!")
  309.         usechest = true
  310.     end
  311.    
  312.     sleep(1)
  313.     print("Confirm? (write confirm)")
  314.     local confirm2 = read()
  315.     if confirm2 == "confirm" then
  316.         term.clear()
  317.         shaft()
  318.     else
  319.         print("Shutting Down...")
  320.         sleep(0.5)
  321.         os.shutdown()
  322.     end
  323.  
  324. else
  325.     print("Shutting down...")
  326.     os.shutdown()
  327. end
Advertisement
Add Comment
Please, Sign In to add comment