Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- blocks = {}
- blocks.MJ = {}
- blocks.MJ.Storage = {"redstone_energy_cell"}
- blocks.MJ.Producer = {"engine", "engineBlock"}
- blocks.MJ.Consumer = {"machine", "factory"}
- blocks.MJ.Functions = {getEnergyReceive = {{name = "value", vType = "number", alias = "Maximum Energy Received", unit = "MJ/t"}}, getEnergySend = {{name = "value", vType = "number", alias = "Maximum Energy Send", unit = "MJ/t"}}, getPowerProvider = {{name = "maxEnergyStored", vType = "number", alias = "Maximum Energy Stored", unit = "MJ"}, {name = "energyStored", vType = "number", alias = "Current Energy Stored", unit = "MJ"}}, getPower = {{name = "value", vType = "number", alias = "Current Energy Production", unit = "MJ/t"}}}
- --[[blocks.EU = {}
- blocks.EU.Storage = {"blockElectric"}
- blocks.EU.Producer = {"blockGenerator"}
- blocks.EU.Consumer = {"blockMachine"}
- blocks.EU.Functions = {}]]
- clear = function()
- term.clear()
- term.setCursorPos(1, 1)
- end
- getNetworkStats = function(network)
- local stats = {}
- for blockType, blockNames in pairs(network) do
- if blockType ~= "Functions" then
- for blockName, blocks in pairs(blockNames) do
- for _, block in pairs(blocks) do
- for functionName, functionUsages in pairs(network.Functions) do
- if type(block[functionName]) == "function" then
- functionValue = block[functionName]()
- for __, usage in pairs(functionUsages) do
- if usage.name == "value" then
- if usage.vType == "number" then
- functionValue = {[usage.name] = tonumber(functionValue)}
- else
- functionValue = {[usage.name] = functionValue}
- end
- end
- if type(functionValue[usage.name]) == usage.vType then
- if not stats[usage.alias] then
- stats[usage.alias] = {}
- if usage.vType == "number" then
- stats[usage.alias].value = 0
- end
- end
- if usage.vType == "number" then
- stats[usage.alias].value = stats[usage.alias].value + functionValue[usage.name]
- stats[usage.alias].unit = usage.unit
- end
- end
- end
- end
- end
- end
- end
- end
- end
- return stats
- end
- scanNetwork = function(blocklist)
- local network = {}
- for blockType, blockNames in pairs(blocklist) do
- if blockType ~= "Functions" then
- for _, blockName in pairs(blockNames) do
- if not network[blockType] then
- network[blockType] = {}
- end
- if not network[blockType][blockName] then
- network[blockType][blockName] = {}
- end
- end
- else
- network[blockType] = blockNames
- end
- end
- for _, side in pairs(peripheral.getNames()) do
- for blockType, blockNames in pairs(network) do
- if blockType ~= "Functions" then
- for blockName, blocks in pairs(blockNames) do
- if string.find(side, blockName.."_") then
- network[blockType][blockName][#blocks + 1] = peripheral.wrap(side)
- print(" Added ", blockType, " ", blockName, " (", side, ")!")
- end
- end
- end
- end
- end
- return network
- end
- print("Initialising...")
- networks = {}
- for networkName, networkComponents in pairs(blocks) do
- print(" Scanning for ", networkName, " Components!")
- networks[networkName] = scanNetwork(networkComponents)
- print(" Successfully scanned for ", networkName, " Components!")
- end
- print(" Checking for Refreshinterval argument...")
- refreshTime = tonumber((...))
- if not refreshTime then
- print(" No Argument found! Defaulting to 30s!")
- refreshTime = 30
- else
- print(" Argument found! Refreshinterval set to ", refreshTime, "s!")
- end
- print("Initialised successfully!")
- os.startTimer(2.5)
- while true do
- event, param1, param2, param3 = os.pullEvent()
- if event == "timer" then
- networkStats = {}
- for networkName, networkComponents in pairs(networks) do
- networkStats[networkName] = getNetworkStats(networkComponents)
- end
- clear()
- for networkName, stats in pairs(networkStats) do
- print("Statistics for ", networkName, " Network:")
- for statName, statInfo in pairs(stats) do
- print(" ", statName, ": ", statInfo.value, " ", statInfo.unit)
- end
- print("")
- end
- os.startTimer(refreshTime)
- elseif event == "peripheral" or event == "peripheral_detach" then
- print("Change in connected Peripherals detected!")
- local relevantTo = nil
- for networkName, network in pairs(networks) do
- for blockType, blockNames in pairs(network) do
- if blockType ~= "Function" then
- for blockName, _ in pairs(blockNames) do
- if string.find(param1, blockName.."_") then
- relevantTo = networkName
- end
- end
- end
- end
- end
- if relevantTo then
- print(" Change relevant to ", relevantTo, " Network! Rescanning...")
- networks[relevantTo] = scanNetwork(blocks[relevantTo])
- print(" Rescanned ", relevantTo, " Network successfully!")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement