Advertisement
drpepper240

Multiminer

Oct 14th, 2021 (edited)
1,306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.19 KB | None | 0 0
  1. local refreshSeconds = 0.1
  2.  
  3. if not term.isColor() then
  4.     print("Advanced computer required")
  5.     error()
  6. end
  7.  
  8. local sides = peripheral.getNames()
  9. local mininglasers = {}
  10. for _, side in pairs(sides) do
  11.     if peripheral.getType(side) == "warpdriveMiningLaser" then
  12.         print("Wrapping " .. side)
  13.         table.insert(mininglasers, peripheral.wrap(side))
  14.     end
  15. end
  16.  
  17.  
  18. local noExit = true
  19. local layerOffset = 1
  20. local onlyOres = false
  21. local silktouch = false
  22. local args = {...}
  23. if #args > 0 then
  24.     if args[1] == "help" or args[1] == "?" then
  25.         print("Usage: mine <layerOffset> <onlyOres> <silktouch>")
  26.         print()
  27.         print("Miner always mines below it, down to bedrock.")
  28.         print("Set layerOffset to define starting level.")
  29.         print("Power consumption will be much lower in space.")
  30.         print("Mining only ores is faster but more expensive...")
  31.         print("Mining laser can't go through forcefields.")
  32.         print("Mined chests will drop their contents.")
  33.         print()
  34.         noExit = false
  35.     else
  36.         layerOffset = tonumber( args[1] ) or 1
  37.     end
  38.    
  39.     if #args > 1 then
  40.         if args[2] == "true" or args[2] == "1" then
  41.             onlyOres = true
  42.         end
  43.     end
  44.    
  45.     if #args > 2 then
  46.         if args[3] == "true" or args[3] == "1" then
  47.             silktouch = true
  48.         end
  49.     end
  50. end
  51.  
  52. if #mininglasers == 0 then
  53.     term.setBackgroundColor(colors.red)
  54.     term.setTextColor(colors.white)
  55.     print("No mining laser detected")
  56.  
  57.     noExit = false
  58. end
  59. if noExit then
  60.     for _, mininglaser in pairs(mininglasers) do
  61.         local isEnabled = mininglaser.enable()
  62.         if not isEnabled then
  63.             mininglaser.offset(layerOffset)
  64.             mininglaser.onlyOres(onlyOres)
  65.             mininglaser.silktouch(silktouch)
  66.            
  67.             mininglaser.enable(true)
  68.         end
  69.     end
  70.     os.sleep(1)
  71. end
  72.  
  73. local label = os.getComputerLabel()
  74. if label then
  75. else
  76.     label = "" .. os.getComputerID()
  77. end
  78.  
  79. if noExit then
  80.     local areActive
  81.     term.setBackgroundColor(colors.black)
  82.     term.setTextColor(colors.blue)
  83.     term.clear()
  84.     term.setBackgroundColor(colors.lime)
  85.     term.setCursorPos(1, 1)
  86.     term.setBackgroundColor(colors.black)
  87.     term.setCursorPos(1, 2)
  88.     term.write("#   status   active   energy  mined/total  layer")
  89.     repeat
  90.         areActive = false
  91.         for key,mininglaser in pairs(mininglasers) do
  92.             local energyUnits = mininglaser.energyDisplayUnits()
  93.             local status, isActive, energy, currentLayer, mined, total = mininglaser.state()
  94.             -- local _, energyPerLayer, energyPerBlock = mininglaser.getEnergyRequired()
  95.             term.setBackgroundColor(colors.black)
  96.             term.setCursorPos(1, key+2)
  97.             term.clearLine()
  98.             term.write(tostring(key) .. "  " .. status .. "  " .. tostring(isActive) .. "  " .. energy .. " " .. energyUnits .. "  " .. mined .. "/" .. total .. "  " .. currentLayer)
  99.             -- term.setTextColor(colors.gray)
  100.             -- term.setCursorPos(1, 9)
  101.             -- term.write("Scanning requires " .. energyPerLayer .. " " .. energyUnits .. " per layer")
  102.             -- term.setCursorPos(1, 10)
  103.             -- term.write("Mining requires " .. energyPerBlock .. " " .. energyUnits .. " per block")
  104.            
  105.             if isActive then
  106.                 areActive = true
  107.                 os.sleep(refreshSeconds)
  108.             else
  109.                 os.sleep(refreshSeconds)
  110.             end
  111.         end
  112.     until not areActive
  113. end
  114.  
  115. term.setBackgroundColor(colors.black)
  116. term.setTextColor(colors.white)
  117.  
  118. print()
  119. print("Program closed")
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement