Mr_Rockers

QuarryBot

Nov 20th, 2015
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function CleanClear()
  2.   term.clear()
  3.   term.setCursorPos(1, 1)
  4. end
  5.  
  6. currentLevel = 0
  7. function Quarry(xDistance, zDistance, Depth, returnFrequency, amntOfTorches)
  8.    
  9.     for currentLevel = 1, Depth do
  10.         turtle.digDown()
  11.         turtle.down()
  12.        
  13.         if currentLevel >= turtle.getFuelLevel() then --If runs out of fuel
  14.             local oldLevel = currentLevel
  15.             for clvl = currentLevel, 0 do
  16.             turtle.digUp()
  17.             turtle.up()
  18.             end
  19.             currentLevel = 0
  20.            
  21.             CleanClear()
  22.             currentLevel = 0
  23.             print("Returned To Surface\n")
  24.             print("Reason:\nRan out of fuel.\n")
  25.             print("Refuel?")
  26.             print("Enter Y for yes or anything else to end the Quarry.")
  27.             fuelConfQuarry = read()
  28.            
  29.             if fuelConfQuarry == "Y" then
  30.                 CleanClear()
  31.                 print("Enter the amount of items of fuel you want to load in or enter \'all\' to load QuarryBot with all the fuel within its inventory. If you don't use \'all\' then it will only take fuel from the top-left slot.\n")
  32.                 local fuelParamEnter = read()
  33.            
  34.                 if fuelParamEnter == "all" then    
  35.                     Fuel(true, 0)
  36.                 else
  37.                     Fuel(false, fuelParamEnter)
  38.                 end
  39.                
  40.                 print("Refuelled!\n")
  41.                 print("There is now "..turtle.getFuelLevel().." fuel inside of QuarryBot.")
  42.                 sleep(2)
  43.                 CleanClear()
  44.                 textutils.slowPrint("Continuing Quarry...")
  45.                
  46.                 for nclvl = currentLevel, oldLevel do
  47.                     turtle.digDown()
  48.                     turtle.down()
  49.                 end
  50.                 currentLevel = oldLevel
  51.                
  52.             else
  53.             CleanClear()
  54.             print("Thank you for using QuarryBot!")
  55.             sleep(1)
  56.             os.shutdown()
  57.             end
  58.         end
  59.        
  60.         local success, data = turtle.inspectDown()
  61.         if success then --If detects bedrock below
  62.             if data.name == "minecraft:bedrock" then
  63.                 for bclvl = currentLevel, 0 do
  64.                     turtle.digUp()
  65.                     turtle.up()
  66.                 end
  67.                 currentLevel = 0
  68.                 break
  69.             end
  70.         end
  71.    
  72.         if currentLevel == Depth then
  73.             print("Depth Called!")
  74.             for dclvl = currentLevel, 0 do
  75.                 turtle.digUp()
  76.                 turtle.up()
  77.             end
  78.         end
  79.    
  80.         print ("cL: "..currentLevel.." D: "..Depth)
  81.     end
  82.     currentLevel = 0
  83.    
  84. end
  85.  
  86. function Fuel(all, amount)
  87.   if all == true then
  88.  
  89.     for i = 1, 16 do
  90.           turtle.select(i)
  91.           if turtle.refuel(0) then
  92.             turtle.refuel(turtle.getItemCount(i))
  93.           end
  94.         end
  95.         turtle.select(1)
  96.  
  97.   else
  98.  
  99.     turtle.select(1)
  100.         if(turtle.refuel(0)) then
  101.           turtle.refuel(tonumber(amount))
  102.         end
  103.  
  104.   end
  105. end
  106.  
  107. function Confirm(xD, zD, dep, retFq)
  108.   CleanClear()
  109.   textutils.slowPrint("So...")
  110.   sleep(2)
  111.   CleanClear()
  112.   textutils.slowPrint("Quarry Parameter Preview\n")
  113.   print("Quarry X: "..xD)
  114.   print("Quarry Z: "..zD)
  115.   print("Quarry depth: "..dep)
  116.   print("Quarry return frequency: "..retFq.."\n")
  117.   sleep(2)
  118.   print("Is this correct?")
  119.   textutils.slowPrint("Y for yes or anything else for no...")
  120.   confirmEnter = read()
  121.  
  122.    if confirmEnter ~= "Y" then
  123.     CleanClear()
  124.     print("Okay... Restarting program.")
  125.     sleep(1)
  126.     Start()
  127.   else
  128.     CleanClear()
  129.     textutils.slowPrint("Quarry Fuel Preview\n")
  130.     local amOfFuelIn = turtle.getFuelLevel()
  131.     if amOfFuelIn <= 0 then
  132.       print("It seems that there is no fuel left in QuarryBot. In order to continue, enter the amount of items of fuel you want to load in or enter \'all\' to load QuarryBot with all the fuel within its inventory. If you don't use \'all\' then it will only take fuel from the top-left slot.\n")
  133.       local fuelParamEnter = read()
  134.  
  135.          if fuelParamEnter == "all" then    
  136.         Fuel(true, 0)
  137.           else
  138.         Fuel(false, fuelParamEnter)
  139.           end
  140.  
  141.       print("Refuelled!\n")
  142.       print("There is now "..turtle.getFuelLevel().." fuel inside of QuarryBot.")
  143.       sleep(2)
  144.     else
  145.     print("Would you like to refuel? Enter Y for yes or anything else for no...")
  146.     local fuelConfCheck = read()
  147.  
  148.     if fuelConfCheck == "Y" then
  149.     print("In order to continue, enter the amount of items of fuel you want to load in or enter \'all\' to load QuarryBot with all the fuel within its inventory. If you don't use \'all\' then it will only take fuel from the top-left slot.\n")
  150.    
  151.       local fuelParamEnter = read()
  152.       if fuelParamEnter == "all" then    
  153.         Fuel(true, 0)
  154.           else
  155.         Fuel(false, fuelParamEnter)
  156.           end
  157.       print("Refuelled!\n")
  158.       print("There is now "..turtle.getFuelLevel().." fuel inside of QuarryBot.")
  159.       sleep(2)
  160.     end
  161.     end
  162.     CleanClear()
  163.     textutils.slowPrint("Quarry Light Preview\n")
  164.     print("Please enter how frequently you want the QuarryBot to place a torch on a wall of the Quarry.")
  165.     print("(Per levels. For example, if you entered \'5\' then it would place a torch every 5 levels it goes down. If you do not want torches to be placed, enter \'0\'. If you are going to be placing torches, make sure that there are some torches in QuarryBot's inventory otherwise they won't be placed!)\n")
  166.     local amountOfTorchesToPlace = tonumber(read())
  167.     CleanClear()
  168.     textutils.slowPrint("Starting Quarry...")
  169.     sleep(3)
  170.     Quarry(xD, zD, dep, amountOfTorchesToPlace)
  171. end
  172. end
  173.  
  174. function Start()
  175.   CleanClear()
  176.   textutils.slowPrint("Welcome to Quarry")
  177.   sleep(2)
  178.   print("How far on the X-Axis do you want to quarry?")
  179.   local xDist = tonumber(read())
  180.   sleep(1)
  181.   print("How far on the Z-Axis do you want to quarry?")
  182.   local zDist = tonumber(read())
  183.   sleep(1)
  184.   print("How deep would you like to quarry?")
  185.   local depth = tonumber(read())
  186.   sleep(1)
  187.   print("How often would you like the QuarryBot to return to the surface?")
  188.   print("(Per the amount of blocks the quarry mines.)")
  189.   local returnFreq = tonumber(read())
  190.   sleep(2)
  191.   Confirm(xDist, zDist, depth, returnFreq)
  192. end
  193.  
  194. Start()
Advertisement
Add Comment
Please, Sign In to add comment