Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---Minecraft-Warp Drive Mod
- ---Mining Controller
- ---Edited version
- ---by MarsGame
- ---Use at own Risk!!
- ---To use this Programm for the Mining Laser you have to place the Advanced Computer somewhere else
- ---before installing this program, otherwise, you will get an error.
- ---After installing this program use "label set [NAME]" to make sure that the Programm
- ---will stay on the PC when moving it to its final destination.
- ---Settings for Programm
- minOffset=5 ---This is always added to the offset and is there to prevent the Laser from destroying your ship.
- ---Further down is the Code for the program, you don't need to change there anything, as the program should work perfectly.
- ---Check for Advanced Computer
- if not term.isColor() then
- print("Advanced computer required")
- error()
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- ---Get Lasers
- local sides = peripheral.getNames()
- local mininglasers = {}
- for _, side in pairs(sides) do
- if peripheral.getType(side) == "warpdriveMiningLaser" then
- table.insert(mininglasers, peripheral.wrap(side))
- end
- end
- ---Check Laser Num
- if #mininglasers == 0 then
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.white)
- print("No mining laser detected")
- return
- end
- ---Get Command Options
- local layerOffset = 1
- local onlyOres = false
- local silktouch = false
- local args = {...}
- if #args > 0 then
- if args[1] == "help" or args[1] == "?" then
- print("Usage: mine <layerOffset> <onlyOres> <silktouch>")
- print()
- print("*Laser mines always downwards, ends at bedrock.")
- print("*Set <layerOffset> to define starting level.")
- print(" or your ship could get mined.")
- print("*Power consumption will be much lower in space.")
- print("*Set <onlyOres> if you only want to mine ores.")
- print("*Mining only ores is faster, but costs much ")
- print(" more power.")
- print("*Mining laser can't go through forcefields.")
- print("*Mined chests will drop their contents.")
- print("*Set <silktouch> if you want silktouched Items.")
- term.setTextColor(colours.red)
- print("*For <silktouch> you need to define <layerOffset>!")
- print("*Values for usage: true, yes, y!")
- term.setTextColor(colours.white)
- print()
- return
- end
- layerOffset = tonumber( args[1] ) or minOffset
- if (layerOffset < minOffset) then layerOffset = minOffset end
- if #args > 1 then
- if args[2] == "true" or args[2] == "yes" or args[2] == "y" or args[2] == "1" then
- onlyOres = true
- end
- end
- if #args > 2 then
- if args[3] == "true" or args[3] == "yes" or args[3] == "y" or args[3] == "1" then
- silktouch = true
- end
- end
- end
- ---Start Lasers
- for _, mininglaser in pairs(mininglasers) do
- local isEnabled = mininglaser.enable()
- if not isEnabled then
- mininglaser.offset(layerOffset)
- mininglaser.onlyOres(onlyOres)
- mininglaser.silktouch(silktouch)
- mininglaser.enable(true)
- end
- end
- os.sleep(1)
- ---Get PC name
- local label = os.getComputerLabel()
- if label then
- else
- label = "" .. os.getComputerID()
- end
- ---Display Laser information
- local areActive = true
- local stopMining = false
- function Display()
- while areActive and not stopMining do
- areActive = false
- for key,mininglaser in pairs(mininglasers) do
- local energyUnits = mininglaser.energyDisplayUnits()
- local status, isActive, energy, currentLayer, mined, total = mininglaser.state()
- local _, energyPerLayer, energyPerBlock = mininglaser.getEnergyRequired()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.blue)
- term.clear()
- term.setBackgroundColor(colors.lime)
- term.setCursorPos(1, 1)
- term.write(label .. " - Mining laser " .. key .. " of " .. #mininglasers)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1, 3)
- term.write("Status: " .. status .. " ")
- term.setCursorPos(1, 5)
- term.write("Energy level is " .. energy .. " " .. energyUnits)
- term.setTextColor(colors.white)
- term.setCursorPos(1, 7)
- term.write("Mined " .. mined .. " out of " .. total .. " blocks at layer " .. currentLayer .. " ")
- term.setTextColor(colors.gray)
- term.setCursorPos(1, 9)
- term.write("Scanning requires " .. energyPerLayer .. " " .. energyUnits .. " per layer")
- term.setCursorPos(1, 10)
- term.write("Mining requires " .. energyPerBlock .. " " .. energyUnits .. " per block")
- term.setTextColor(colors.red)
- term.setCursorPos(1, 12)
- term.write("Stop mining by hitting S")
- if isActive then
- areActive = true
- os.sleep(1)
- else
- os.sleep(0.1)
- end
- end
- end
- return 0
- end
- function InputStop()
- local stopped = false
- while not stopped do
- local event,key = os.pullEvent("key")
- if key == keys.s then
- stopped = true
- end
- end
- ---Stop Lasers
- term.clear()
- term.setCursorPos(1, 1)
- for key, mininglaser in pairs(mininglasers) do
- term.setCursorPos(1, 2 + key)
- local isEnabled = mininglaser.enable()
- if not isEnabled then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.gray)
- term.write("Mining laser " .. key .. " of " .. #mininglasers .. " is already stopped")
- else
- mininglaser.enable(false)
- term.setBackgroundColor(colors.lime)
- term.setTextColor(colors.blue)
- term.write("Mining laser " .. key .. " of " .. #mininglasers .. " has been stopped")
- end
- end
- os.sleep(3)
- end
- parallel.waitForAny(Display, InputStop)
- ---Set PC colours to default
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement