Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- reactor_monitor_status.lua
- -- This script reads Mekanism Fission Reactor status and displays it on a CC: Tweaked Advanced Monitor.
- -- It expects the Fission Reactor Logic Adapter and the Monitor to be connected via Wired Modems
- -- and Networking Cable.
- -- Function to safely wrap a peripheral by name
- local function getPeripheralByName(peripheralName)
- local p = peripheral.wrap(peripheralName)
- if p then
- print("Successfully connected to peripheral: " .. peripheralName)
- return p
- else
- error("Could not find peripheral: " .. peripheralName .. ". Check connection and name. Exiting.")
- end
- end
- -- --- Color Definitions (Based on your discoveries) ---
- -- These are the *specific numeric IDs* that work in your environment
- local COLOR_BLACK_BACKGROUND = 0x8000 -- User confirmed this works for black background
- local COLOR_WHITE_TEXT = 0x1 -- User confirmed this works for white text
- -- IMPORTANT: The following colors are **GUESSES** based on standard 16-color palettes.
- -- You might need to adjust these using the "Color Discovery Tool" below.
- local COLOR_RED_GUESS = 0x80 -- Often standard bitmask for Red
- local COLOR_YELLOW_GUESS = 0x40 -- Often standard bitmask for Yellow
- local COLOR_LIME_GUESS = 0x20 -- Often standard bitmask for Lime
- local COLOR_AQUA_LIGHT_BLUE_GUESS = 0x8 -- Often standard bitmask for Cyan/LightBlue, but you'll need to confirm your preferred shade
- -- --- Main Program ---
- -- !!! IMPORTANT !!!
- -- Using the specified peripheral name: "fissionReactorLogicAdapter_0"
- local reactorPeripheralName = "fissionReactorLogicAdapter_0"
- local monitorPeripheralName = "monitor_0" -- Keep this as "monitor_0" unless you've confirmed otherwise
- local reactor = getPeripheralByName(reactorPeripheralName)
- local monitor = getPeripheralByName(monitorPeripheralName)
- -- Check if both peripherals were successfully wrapped
- if not reactor or not monitor then
- return
- end
- -- Get monitor dimensions to ensure lines are cleared properly
- local monitorWidth, monitorHeight = monitor.getSize()
- -- --- Setup for Advanced Monitor ---
- monitor.setTextScale(0.75) -- A common comfortable size, try 0.5, 1.0 etc.
- monitor.setBackgroundColor(COLOR_BLACK_BACKGROUND) -- Use the discovered ID for black background
- -- --- Initial Draw (Draw static elements once) ---
- monitor.clear() -- Clear once at the start to ensure a clean slate
- monitor.setCursorPos(1, 1)
- monitor.setTextColor(COLOR_WHITE_TEXT) -- Use the discovered ID for white text
- monitor.write("--- Mekanism Fission Reactor Status ---")
- monitor.setCursorPos(1, 2)
- monitor.write("-----------------------------------")
- -- Static labels (we'll update the values next to them)
- monitor.setCursorPos(1, 4) monitor.write("Status: ")
- monitor.setCursorPos(1, 5) monitor.write("Temp: ")
- monitor.setCursorPos(1, 6) monitor.write("Damage: ")
- monitor.setCursorPos(1, 7) monitor.write("Burn Rate: ")
- monitor.setCursorPos(1, 8) monitor.write("Fuel: ")
- monitor.setCursorPos(1, 9) monitor.write("Waste: ")
- monitor.setCursorPos(1, 10) monitor.write("Coolant: ")
- monitor.setCursorPos(1, 11) monitor.write("Heating: ")
- monitor.setCursorPos(1, 12) monitor.write("Fuel Assemblies: ")
- monitor.setCursorPos(1, monitorHeight) monitor.write("Last updated: ")
- -- Helper function to overwrite a line with padding and safe color handling
- local function overwriteLine(y, text, textColor)
- monitor.setCursorPos(1, y)
- -- Pad the string with spaces to overwrite any previous longer text
- monitor.setTextColor(COLOR_WHITE_TEXT) -- Use the discovered white for padding spaces
- monitor.write(string.rep(" ", monitorWidth)) -- Clear the entire line
- monitor.setCursorPos(1, y) -- Move cursor back to start of line
- local finalColor = COLOR_WHITE_TEXT -- Default to discovered white if textColor is invalid
- if type(textColor) == "number" then
- -- We're not checking range to 0xFFFFFF anymore, as your monitor seems to use a different scale.
- -- We're assuming any number passed will be an attempt at a valid palette ID.
- finalColor = math.floor(textColor) -- Ensure it's an integer
- else
- -- Debug: If textColor is not a number (e.g., nil, string, table)
- print("Debug: Passed textColor is not a number. Type: " .. type(textColor) .. ", Value: " .. tostring(textColor) .. " (Line: " .. y .. ")")
- end
- monitor.setTextColor(finalColor)
- monitor.write(text)
- end
- -- Main loop to continuously update the monitor
- while true do
- -- Update reactor status
- overwriteLine(4, "Status: " .. (reactor.getStatus() and "Active" or "Disabled"), COLOR_WHITE_TEXT)
- -- Update Temperature
- local currentTemp = reactor.getTemperature()
- local tempString = string.format("Temp: %.2fK", currentTemp)
- local tempColor = COLOR_WHITE_TEXT -- Default
- if currentTemp > 500 then
- tempColor = COLOR_YELLOW_GUESS
- elseif currentTemp > 600 then
- tempColor = COLOR_RED_GUESS
- end
- overwriteLine(5, tempString, tempColor)
- -- Update Damage
- local damagePercent = reactor.getDamagePercent() * 100
- local damageString = string.format("Damage: %.2f%%", damagePercent)
- local damageColor = COLOR_WHITE_TEXT -- Default
- if damagePercent > 50 then
- damageColor = COLOR_YELLOW_GUESS
- elseif damagePercent > 75 then
- damageColor = COLOR_RED_GUESS
- end
- overwriteLine(6, damageString, damageColor)
- -- Update Burn Rate
- overwriteLine(7, string.format("Burn Rate: %.2f mB/t", reactor.getActualBurnRate()), COLOR_WHITE_TEXT)
- -- Update Fuel
- local fuelInfo = reactor.getFuel()
- local fuelAmount = fuelInfo.amount or 0
- local fuelPercentage = 0
- if fuelInfo.capacity and fuelInfo.capacity > 0 then
- fuelPercentage = (fuelInfo.amount / fuelInfo.capacity) * 100
- end
- local fuelString = string.format("Fuel: %.2f mB (%.2f%%)", fuelAmount, fuelPercentage)
- local fuelColor = COLOR_WHITE_TEXT -- Default
- if fuelPercentage < 10 then
- fuelColor = COLOR_RED_GUESS
- elseif fuelPercentage < 25 then
- fuelColor = COLOR_YELLOW_GUESS
- else
- fuelColor = COLOR_LIME_GUESS
- end
- overwriteLine(8, fuelString, fuelColor)
- -- Update Waste
- local wasteInfo = reactor.getWaste()
- local wasteAmount = wasteInfo.amount or 0
- local wastePercentage = 0
- if wasteInfo.capacity and wasteInfo.capacity > 0 then
- wastePercentage = (wasteInfo.amount / wasteInfo.capacity) * 100
- end
- local wasteString = string.format("Waste: %.2f mB (%.2f%%)", wasteAmount, wastePercentage)
- local wasteColor = COLOR_WHITE_TEXT -- Default
- if wastePercentage > 90 then
- wasteColor = COLOR_RED_GUESS
- elseif wastePercentage > 75 then
- wasteColor = COLOR_YELLOW_GUESS
- else
- wasteColor = COLOR_WHITE_TEXT
- end
- overwriteLine(9, wasteString, wasteColor)
- -- Update Coolant
- local coolant = reactor.getCoolant()
- local coolantPercentage = reactor.getCoolantFilledPercentage() * 100
- local coolantString = string.format("Coolant: %s %.2f mB (%.2f%%)", coolant.type, coolant.amount, coolantPercentage)
- local coolantColor = COLOR_WHITE_TEXT -- Default
- if coolantPercentage < 10 then
- coolantColor = COLOR_RED_GUESS
- elseif coolantPercentage < 25 then
- coolantColor = COLOR_YELLOW_GUESS
- else
- coolantColor = COLOR_AQUA_LIGHT_BLUE_GUESS
- end
- overwriteLine(10, coolantString, coolantColor)
- -- Update Heating
- overwriteLine(11, string.format("Heating: %.2fJ/t (Env: %.2fJ/t)", reactor.getHeatingRate(), COLOR_WHITE_TEXT))
- -- Update Fuel Assemblies
- overwriteLine(12, string.format("Fuel Assemblies: %d", reactor.getFuelAssemblies()), COLOR_WHITE_TEXT)
- -- Update Timestamp
- overwriteLine(monitorHeight, "Last updated: " .. os.date("%H:%M:%S"), COLOR_WHITE_TEXT)
- sleep(1) -- Wait for 1 second before updating again
- end
Advertisement
Add Comment
Please, Sign In to add comment