Advertisement
MarsP4ste

Mining Controller--Minecraft-Warp Drive Mod

Apr 8th, 2020 (edited)
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ---Minecraft-Warp Drive Mod
  2. ---Mining Controller
  3. ---Edited version
  4. ---by MarsGame
  5.  
  6. ---Use at own Risk!!
  7.  
  8. ---To use this Programm for the Mining Laser you have to place the Advanced Computer somewhere else
  9. ---before installing this program, otherwise, you will get an error.
  10. ---After installing this program use "label set [NAME]" to make sure that the Programm
  11. ---will stay on the PC when moving it to its final destination.
  12.  
  13.  
  14. ---Settings for Programm
  15. minOffset=5 ---This is always added to the offset and is there to prevent the Laser from destroying your ship.
  16.  
  17.  
  18. ---Further down is the Code for the program, you don't need to change there anything, as the program should work perfectly.
  19.  
  20. ---Check for Advanced Computer
  21. if not term.isColor() then
  22.     print("Advanced computer required")
  23.     error()
  24. end
  25. term.setBackgroundColor(colors.black)
  26. term.setTextColor(colors.white)
  27.  
  28.  
  29. ---Get Lasers
  30. local sides = peripheral.getNames()
  31. local mininglasers = {}
  32. for _, side in pairs(sides) do
  33.     if peripheral.getType(side) == "warpdriveMiningLaser" then
  34.         table.insert(mininglasers, peripheral.wrap(side))
  35.     end
  36. end
  37.  
  38.  
  39. ---Check Laser Num
  40. if #mininglasers == 0 then
  41.     term.setBackgroundColor(colors.red)
  42.     term.setTextColor(colors.white)
  43.     print("No mining laser detected")
  44.     return
  45. end
  46.  
  47.  
  48. ---Get Command Options
  49. local layerOffset = 1
  50. local onlyOres = false
  51. local silktouch = false
  52. local args = {...}
  53.  
  54. if #args > 0 then
  55.  
  56.     if args[1] == "help" or args[1] == "?" then
  57.         print("Usage: mine <layerOffset> <onlyOres> <silktouch>")
  58.         print()
  59.         print("*Laser mines always downwards, ends at bedrock.")
  60.         print("*Set <layerOffset> to define starting level.")
  61.         print(" or your ship could get mined.")
  62.         print("*Power consumption will be much lower in space.")
  63.         print("*Set <onlyOres> if you only want to mine ores.")
  64.         print("*Mining only ores is faster, but costs much ")
  65.         print(" more power.")
  66.         print("*Mining laser can't go through forcefields.")
  67.         print("*Mined chests will drop their contents.")
  68.         print("*Set <silktouch> if you want silktouched Items.")
  69.         term.setTextColor(colours.red)
  70.         print("*For <silktouch> you need to define <layerOffset>!")
  71.         print("*Values for usage: true, yes, y!")
  72.         term.setTextColor(colours.white)
  73.         print()
  74.         return
  75.     end
  76.  
  77.     layerOffset = tonumber( args[1] ) or minOffset
  78.     if (layerOffset < minOffset) then layerOffset = minOffset end
  79.    
  80.     if #args > 1 then
  81.         if args[2] == "true"  or args[2] == "yes" or args[2] == "y" or args[2] == "1" then
  82.         onlyOres = true
  83.         end
  84.     end
  85.  
  86.     if #args > 2 then
  87.         if args[3] == "true"  or args[3] == "yes" or args[3] == "y" or args[3] == "1" then
  88.         silktouch = true
  89.         end
  90.     end
  91. end
  92.  
  93.  
  94. ---Start Lasers
  95. for _, mininglaser in pairs(mininglasers) do
  96.     local isEnabled = mininglaser.enable()
  97.     if not isEnabled then
  98.         mininglaser.offset(layerOffset)
  99.         mininglaser.onlyOres(onlyOres)
  100.         mininglaser.silktouch(silktouch)
  101.      
  102.         mininglaser.enable(true)
  103.     end
  104. end
  105. os.sleep(1)
  106.  
  107.  
  108. ---Get PC name
  109. local label = os.getComputerLabel()
  110. if label then
  111. else
  112.     label = "" .. os.getComputerID()
  113. end
  114.  
  115.  
  116. ---Display Laser information
  117. local areActive = true
  118. local stopMining = false
  119.  
  120. function Display()
  121. while areActive and not stopMining do
  122.     areActive = false
  123.     for key,mininglaser in pairs(mininglasers) do
  124.         local energyUnits = mininglaser.energyDisplayUnits()
  125.         local status, isActive, energy, currentLayer, mined, total = mininglaser.state()
  126.         local _, energyPerLayer, energyPerBlock = mininglaser.getEnergyRequired()
  127.        
  128.         term.setBackgroundColor(colors.black)
  129.         term.setTextColor(colors.blue)
  130.         term.clear()
  131.         term.setBackgroundColor(colors.lime)
  132.         term.setCursorPos(1, 1)
  133.         term.write(label .. " - Mining laser " .. key .. " of " .. #mininglasers)
  134.         term.setBackgroundColor(colors.black)
  135.         term.setCursorPos(1, 3)
  136.         term.write("Status: " .. status .. "   ")
  137.         term.setCursorPos(1, 5)
  138.         term.write("Energy level is " .. energy .. " " .. energyUnits)
  139.         term.setTextColor(colors.white)
  140.         term.setCursorPos(1, 7)
  141.         term.write("Mined " .. mined .. " out of " .. total .. " blocks at layer " .. currentLayer .. "   ")
  142.         term.setTextColor(colors.gray)
  143.         term.setCursorPos(1, 9)
  144.         term.write("Scanning requires " .. energyPerLayer .. " " .. energyUnits .. " per layer")
  145.         term.setCursorPos(1, 10)
  146.         term.write("Mining requires " .. energyPerBlock .. " " .. energyUnits .. " per block")
  147.         term.setTextColor(colors.red)
  148.         term.setCursorPos(1, 12)
  149.         term.write("Stop mining by hitting S")
  150.        
  151.         if isActive then
  152.             areActive = true
  153.             os.sleep(1)
  154.         else
  155.             os.sleep(0.1)
  156.         end
  157.     end
  158. end
  159. return 0
  160. end
  161.  
  162. function InputStop()
  163.    
  164.     local stopped = false
  165.    
  166.     while not stopped do
  167.         local event,key = os.pullEvent("key")
  168.         if key == keys.s then
  169.             stopped = true
  170.         end
  171.     end
  172.  
  173. ---Stop Lasers
  174.     term.clear()
  175.     term.setCursorPos(1, 1)
  176.     for key, mininglaser in pairs(mininglasers) do
  177.         term.setCursorPos(1, 2 + key)
  178.         local isEnabled = mininglaser.enable()
  179.         if not isEnabled then
  180.             term.setBackgroundColor(colors.black)
  181.             term.setTextColor(colors.gray)
  182.             term.write("Mining laser " .. key .. " of " .. #mininglasers .. " is already stopped")
  183.         else
  184.             mininglaser.enable(false)
  185.             term.setBackgroundColor(colors.lime)
  186.             term.setTextColor(colors.blue)
  187.             term.write("Mining laser " .. key .. " of " .. #mininglasers .. " has been stopped")
  188.         end
  189.     end
  190.     os.sleep(3)
  191. end
  192.  
  193. parallel.waitForAny(Display, InputStop)
  194.  
  195.  
  196.  
  197. ---Set PC colours to default
  198. term.setBackgroundColor(colors.black)
  199. term.setTextColor(colors.white)
  200. term.clear()
  201. term.setCursorPos(1, 1)
  202.  
  203. print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement