Advertisement
MrHG

SDMiner 2.4

Aug 6th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.05 KB | None | 0 0
  1. -- uses Robust Turtle API: pastebin get 0TnEBf2P t
  2. os.loadAPI("t")
  3. local args = {...}
  4. local versionNumber = "2.4"
  5. local programName = "StarDustMiner"
  6. local programNameShort = "SDMiner"
  7. local startInventory = 2
  8. local torchEnabled = true
  9. local torchName = "minecraft:torch"
  10. -- CHANGEABLE BY USER
  11. local indivTunnelSpacing = 3
  12. -- do the same for indivDug
  13. local indivDug = 3
  14. -- Start nonIndivDug at 3 so that the first corridor places a torch.
  15. local nonIndivDug = 3
  16. local blocksSinceLastTorch = 0
  17.  
  18. if #args < 2 or #args > 3 then
  19.     print ("Usage: "..programNameShort.." (Main Tunnel Length) (Individual Tunnel Length) [Tunnel Spacing]")
  20.     return
  21. else
  22.     mainTL = tonumber(args[1])
  23.     indivTL = tonumber(args[2])
  24.     if #args == 3 then
  25.         indivTunnelSpacing = tonumber(args[3])
  26.     end
  27.     if mainTL < 1 then
  28.         print("Main Tunnel Length must be positive.")
  29.         return
  30.     end
  31.     if indivTL < 1 then
  32.         print("Individual Tunnel Length must be positive.")
  33.         return
  34.     end
  35.     if indivTunnelSpacing < 1 then
  36.         print("Tunnel Spacing must be positive.")
  37.         return
  38.     end
  39.     -- INITIAL SETUP FASE
  40.     term.clear()
  41.     term.setCursorPos(1,1)
  42.    
  43.     print("Welcome to"..programName.."Version "..versionNumber.." !")
  44.     print("(Coded by MrHG using RobustTurtleAPI)")
  45.     print("")
  46.     sleep(1)
  47.     -- FUEL CALCULATION
  48.     -- for every 2 blocks after block 1 in MainTL, add 4 times IndivTL.
  49.     -- then add 1 for every time you add 4xIndivTL. Then add another MainTL
  50.     -- then add 80 just in case.
  51.     local blocksToTravel = (2*mainTL) + (((math.floor(mainTL/2)+1)*4) * indivTL + 1) + 80
  52.     if blocksToTravel>3000 then
  53.         print("This will result in a mine bigger than 3000 blocks. Are you sure? (y/n)")
  54.         if read()~="y" then
  55.             print("Aborting operation")
  56.             return
  57.         end
  58.     end
  59.     print("Operation will need " .. blocksToTravel .. " fuel.")
  60.     print("~" .. math.floor(blocksToTravel/80) .. " Pieces of coal.")
  61.     print("Please ensure these are located in the top left slot.")
  62.     print("To enable Torchmode, put torches next to the fuel.")
  63.     print("Starting in 3 Seconds...")
  64.     sleep(3)
  65.     term.clear()
  66.     print("Commencing Dig.")   
  67. end
  68.  
  69. function DisableTorchMode()
  70.     print("No torches found, Disabling Torch Mode.")
  71.     startInventory = 2
  72.     torchEnabled = false
  73.     return false
  74. end
  75.  
  76. function checkForTorches()
  77.     if torchEnabled == true then
  78.         if turtle.getItemDetail(2) then
  79.             if turtle.getItemDetail(2).name == torchName then
  80.                 startInventory = 3
  81.                 torchEnabled = true
  82.                 return true
  83.             else
  84.                 DisableTorchMode()
  85.             end
  86.         else
  87.             DisableTorchMode()
  88.         end
  89.     else
  90.         startInventory = 2
  91.     end
  92. end
  93.  
  94. function Refuel(amountOfRequiredFuel)
  95.     turtle.select(1)
  96.     if (turtle.getFuelLevel() == "unlimited") then
  97.         -- that's pretty neat dude.
  98.         return
  99.     end
  100.     if (turtle.getFuelLevel() < amountOfRequiredFuel) then
  101.         while (true) do
  102.             if turtle.refuel(1) then
  103.                 if (turtle.getFuelLevel() > amountOfRequiredFuel) then
  104.                     break
  105.                 end
  106.             else
  107.                 print("Turtle could not refuel. Please check why.")
  108.                 error()
  109.             end
  110.         end
  111.     end
  112. end
  113.  
  114. function PlaceTorch()
  115.     if checkForTorches() then
  116.         t.digUp()
  117.         t.up()
  118.         if turtle.detect() then
  119.             t.turnAround()
  120.             t.forward()
  121.             t.turnAround()
  122.             t.place(2)
  123.             t.down()
  124.             t.forward()
  125.             return
  126.         end
  127.         t.down()
  128.     end
  129. end
  130.  
  131. function DigIndivTunnel()
  132.     blocksSinceLastTorch = 0
  133.     for i=1,indivTL do
  134.         Refuel(160)
  135.         t.dig()
  136.         t.forward()
  137.         blocksSinceLastTorch = blocksSinceLastTorch + 1
  138.         t.digUp()
  139.         -- Torches every 7 blocks
  140.         if indivTL % 7 ~= 0 and i % 7 == 0 and torchEnabled then
  141.             if checkForTorches() then
  142.                 t.up()
  143.                 t.right()
  144.                 t.forward()
  145.                 t.dig()
  146.                 local blockDetected = turtle.detectDown()
  147.                 t.back()
  148.                 -- do divisable by 3 check here so the hole is still made
  149.                 -- allowing light from other torches to pass through.
  150.                 if blockDetected and indivDug%3 == 0 then
  151.                     t.place(2)
  152.                     blocksSinceLastTorch = 0
  153.                 end
  154.                 t.left()
  155.                 t.down()
  156.             end
  157.         end
  158.     end
  159.     if torchEnabled and blocksSinceLastTorch > 4 then
  160.         PlaceTorch()
  161.     end
  162.     t.turnAround()
  163.     Refuel(indivTL)
  164.     t.forward(indivTL)
  165. end
  166.  
  167. function EmptyInventory()
  168.     local itemsDepositedCount = 0
  169.     for i=startInventory,16 do
  170.         turtle.select(i)
  171.         itemsDepositedCount = itemsDepositedCount + turtle.getItemCount()
  172.         if turtle.getItemCount() == 0 then
  173.             --twiddle your thumbs
  174.         elseif not turtle.drop() then
  175.             print("Container full. Please empty it.")
  176.             error()
  177.         end
  178.     end
  179.     print("Deposited "..itemsDepositedCount.." Items.")
  180.     if not torchEnabled then
  181.         print("Torch mode currently Disabled.")
  182.         print("Insert torches in slot 2 to enable.")
  183.         sleep(3)
  184.         torchEnabled = true
  185.         if checkForTorches() then
  186.             print("Torch mode Enabled.")
  187.         end
  188.     end
  189.     turtle.select(1)
  190. end
  191.  
  192. -- Main Block
  193. checkForTorches()
  194. t.turnAround()
  195. EmptyInventory()
  196. print("Inventory emptied. Heading out.")
  197. t.turnAround()
  198. local blocksAwayFromContainer = 0
  199. for i=1,mainTL do
  200.     Refuel(160)
  201.     t.dig()
  202.     t.forward()
  203.     blocksAwayFromContainer = blocksAwayFromContainer + 1
  204.     t.digUp()
  205.     if (i%indivTunnelSpacing == 0) then
  206.         t.left()
  207.         DigIndivTunnel()
  208.         -- Inventory check
  209.         turtle.select(14)
  210.         if turtle.getItemCount() > 0 then
  211.             t.right()
  212.             t.forward(blocksAwayFromContainer)
  213.             EmptyInventory()
  214.             t.turnAround()
  215.             t.forward(blocksAwayFromContainer)
  216.             t.right()
  217.         end
  218.         DigIndivTunnel()
  219.         -- Increment Amount of Individual Tunnels dug by 1
  220.         -- We do this after every second tunnel so it stays even on every side.
  221.         indivDug = indivDug + 1
  222.         turtle.select(14)
  223.         if turtle.getItemCount() > 0 then
  224.             t.left()
  225.             t.forward(blocksAwayFromContainer)
  226.             EmptyInventory()
  227.             t.turnAround()
  228.             t.forward(blocksAwayFromContainer)
  229.         else
  230.             t.right()
  231.         end
  232.     else
  233.         Refuel(160)
  234.         t.right()
  235.         t.dig()
  236.         t.up()
  237.         t.dig()
  238.         if torchEnabled and (nonIndivDug % 3 == 0)then
  239.             if checkForTorches() then
  240.                 t.place(2)
  241.             end
  242.         end
  243.         t.turnAround()
  244.         t.dig()
  245.         t.down()
  246.         t.dig()
  247.         t.right()
  248.         nonIndivDug = nonIndivDug + 1
  249.     end
  250. end
  251. t.turnAround()
  252. t.forward(mainTL)
  253. EmptyInventory()
  254. t.turnAround()
  255. print("")
  256. print("Dig Complete!")
  257. print("Thank you for using "..programName.."!")
  258. print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement