Advertisement
MrHG

SDMiner

Jan 24th, 2019
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.45 KB | None | 0 0
  1. -- uses Robust Turtle API: pastebin get RXTW1YbW t
  2. os.loadAPI("t")
  3. local args = {...}
  4. local versionNumber = "3.1"
  5. local programName = "StarDustMiner "
  6. local programNameShort = "SDMiner"
  7. local startInventory = 2
  8. local torchEnabled = true
  9. local containerEnabled = true
  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. local tunnelsSinceLastTorch = 6
  18. local tunnelTimer = 2
  19.  
  20.  
  21. if #args < 2 or #args > 3 then
  22.     print ("Usage: "..programNameShort.." (Main Tunnel Length) (Corridor Length) [Corridor Spacing]")
  23.     return
  24. else
  25.     mainTL = tonumber(args[1])
  26.     indivTL = tonumber(args[2])
  27.     if #args == 3 then
  28.         indivTunnelSpacing = tonumber(args[3])
  29.     end
  30.     if mainTL < 1 then
  31.         print("Main Tunnel Length must be positive.")
  32.         return
  33.     end
  34.     if indivTL < 1 then
  35.         print("Corridor Length must be positive.")
  36.         return
  37.     end
  38.     if indivTunnelSpacing < 1 then
  39.         print("Corridor Spacing must be positive.")
  40.         return
  41.     end
  42.     -- INITIAL SETUP FASE
  43.     term.clear()
  44.     term.setCursorPos(1,1)
  45.    
  46.     print(programName..versionNumber.." Coded by MrHG")
  47.     print("")
  48.     sleep(1)
  49.     -- FUEL CALCULATION
  50.     -- for every 2 blocks after block 1 in MainTL, add 4 times IndivTL.
  51.     -- then add 1 for every time you add 4xIndivTL. Then add another MainTL
  52.     -- then add 80 just in case.
  53.     local blocksToTravel = (2*mainTL) + (((math.floor(mainTL/2)+1)*4) * indivTL + 1) + 80
  54.     print("Required fuel: " .. blocksToTravel)
  55.     print("Slot 1: Fuel")
  56.     print("Slot 2-4: Torches")
  57.     print("Commencing Dig.")   
  58. end
  59.  
  60. function DisableTorchMode()
  61.     print("Out of Torches.")
  62.     startInventory = 2
  63.     torchEnabled = false
  64.     return false
  65. end
  66.  
  67. function checkForTorches()
  68.     if torchEnabled == true then
  69.         if turtle.getItemCount(2) > 1 then
  70.             startInventory = 3
  71.             torchEnabled = true
  72.             return true
  73.         else
  74.       if t.restock(2,3,true) then
  75.        return true
  76.       else
  77.              DisableTorchMode()
  78.       end
  79.         end
  80.     else
  81.         startInventory = 2
  82.     end
  83. end
  84.  
  85. function PlaceTorch()
  86.     if checkForTorches() then
  87.         if turtle.detect() then
  88.             t.back()
  89.             blocksToMove = blocksToMove-1
  90.             t.place(2)
  91.             turtle.select(startInventory)
  92.             return
  93.         end
  94.     end
  95. end
  96.  
  97. function PlaceTorchDown()
  98.  if checkForTorches() then
  99.   t.down()
  100.   if turtle.detectDown() then
  101.    t.up()
  102.    t.placeDown(2)
  103.    turtle.select(startInventory)
  104.   else
  105.    t.up()
  106.   end
  107.  end
  108. end
  109.  
  110. function DigIndivTunnel()
  111.     blocksSinceLastTorch = 0
  112.     for i=1,indivTL do
  113.         t.refuel(160,startInventory)
  114.         t.dig()
  115.         t.forward()
  116.         blocksSinceLastTorch = blocksSinceLastTorch + 1
  117.         t.digUp()
  118.         t.digDown()
  119.         -- Torches every 7 blocks
  120.         if indivTL % 7 ~= 0 and i % 7 == 0 and torchEnabled and indivTunnelSpacing > 1 then
  121.             if checkForTorches() then
  122.                 t.up()
  123.                 t.right()
  124.                 t.forward()
  125.                 t.dig()
  126.                 local blockDetected = turtle.detectDown()
  127.                 t.back()
  128.                 -- do divisable by 3 check here so the hole is still made
  129.                 -- allowing light from other torches to pass through.
  130.                 if blockDetected and indivDug%3 == 0 then
  131.                     t.place(2)
  132.                     blocksSinceLastTorch = 0
  133.                 end
  134.                 t.left()
  135.                 t.down()
  136.             end
  137.     end
  138.     if tunnelsSinceLastTorch > 5 and torchEnabled and indivTunnelSpacing == 1 then
  139.      if i % 5 == 0 and checkForTorches() then
  140.       PlaceTorchDown()
  141.      end  
  142.     end
  143.     end
  144.     blocksToMove = indivTL
  145.     if torchEnabled and blocksSinceLastTorch > 2 then
  146.     if indivTunnelSpacing ~= 1 then
  147.          PlaceTorch()
  148.     else
  149.      tunnelsSinceLastTorch = tunnelsSinceLastTorch + 1
  150.      if tunnelsSinceLastTorch > 5 then
  151.        PlaceTorch()
  152.        tunnelTimer = tunnelTimer-1
  153.        if tunnelTimer == 0 then
  154.         tunnelsSinceLastTorch = 0
  155.         tunnelTimer = 2
  156.        end
  157.      end
  158.     end
  159.     end
  160.     t.turnAround()
  161.     t.refuel(blocksToMove,startInventory)
  162.     t.forward(blocksToMove)
  163. end
  164.  
  165. function EmptyInventory()
  166.     local itemsDepositedCount = 0
  167.     for i=startInventory,16 do
  168.         turtle.select(i)
  169.         itemsDepositedCount = itemsDepositedCount + turtle.getItemCount()
  170.         if turtle.getItemCount() == 0 then
  171.             --twiddle your thumbs
  172.         elseif not turtle.drop() then
  173.             print("Container full. Please empty it.")
  174.             error()
  175.         end
  176.     end
  177.     print("Deposited "..itemsDepositedCount.." Items.")
  178.     if not torchEnabled then
  179.         sleep(3)
  180.         torchEnabled = true
  181.         if checkForTorches() then
  182.             print("Torch mode enabled.")
  183.         end
  184.     end
  185.     turtle.select(startInventory)
  186. end
  187.  
  188. function InventoryCheck(LeftSide)
  189.     turtle.select(fullInv)
  190.     if turtle.getItemCount() > 0 then
  191.         if LeftSide then
  192.          t.right()
  193.         else
  194.          t.left()
  195.         end
  196.         t.forward(blocksAwayFromContainer)
  197.         t.down()
  198.         if not containerEnabled then
  199.          print("Inventory Full.")
  200.          brokeEarly = true
  201.          return true
  202.         end
  203.         EmptyInventory()
  204.         t.turnAround()
  205.         t.up()
  206.         t.forward(blocksAwayFromContainer)
  207.         if LeftSide then
  208.          t.right()
  209.         else
  210.          t.left()
  211.         end
  212.     end
  213.     return false
  214. end
  215.  
  216. -- Main Block
  217. t.refuel(160,startInventory)
  218. checkForTorches()
  219. t.turnAround()
  220. containerEnabled = turtle.detect()
  221. fullInv = 14
  222. if containerEnabled then
  223.  EmptyInventory()
  224.  print("Inventory emptied. Heading out.")
  225.  fullInv = 14
  226. else
  227.  print("No container: Mining until full.")
  228.  fullInv = 16
  229. end
  230. t.turnAround()
  231. t.up()
  232. blocksAwayFromContainer = 0
  233. brokeEarly = false
  234. for i=1,mainTL do
  235.     t.refuel(160,startInventory)
  236.     t.dig()
  237.     t.forward()
  238.     blocksAwayFromContainer = blocksAwayFromContainer + 1
  239.     t.digUp()
  240.     t.digDown()
  241.     if (i%indivTunnelSpacing == 0) then
  242.         t.left()
  243.         DigIndivTunnel()
  244.         -- Inventory check for Left tunnel
  245.         if InventoryCheck(true) then
  246.             break
  247.         end
  248.         DigIndivTunnel()
  249.         -- Increment Amount of Individual Tunnels dug by 1
  250.         -- We do this after every second tunnel so it stays even on every side.
  251.         indivDug = indivDug + 1
  252.         -- Inventory check for Right tunnel
  253.         if InventoryCheck(false) then
  254.             break
  255.         end
  256.         t.right()
  257.     else
  258.         t.refuel(160,startInventory)
  259.         t.right()
  260.         t.dig()
  261.         t.forward()
  262.         t.digUp()
  263.         t.digDown()
  264.         t.back()
  265.         if torchEnabled and (nonIndivDug % 3 == 0)then
  266.             if checkForTorches() then
  267.                 t.place(2)
  268.             end
  269.         end
  270.         t.turnAround()
  271.         t.dig()
  272.         t.forward()
  273.         t.digUp()
  274.         t.digDown()
  275.         t.back()
  276.         t.right()
  277.         nonIndivDug = nonIndivDug + 1
  278.     end
  279. end
  280. if not brokeEarly then
  281.  t.turnAround()
  282.  t.forward(mainTL)
  283.  t.down()
  284.  if containerEnabled then
  285.   EmptyInventory()
  286.  end
  287.  t.turnAround()
  288. end
  289. print("")
  290. print("Dig Complete!")
  291. print("Thank you for using "..programName.."!")
  292. print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement