Guest User

mine

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