TheyCallMeAmi

Untitled

Jul 22nd, 2025 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.89 KB | None | 0 0
  1. -- reactor_monitor_status.lua
  2. -- This script reads Mekanism Fission Reactor status and displays it on a CC: Tweaked Advanced Monitor.
  3. -- It expects the Fission Reactor Logic Adapter and the Monitor to be connected via Wired Modems
  4. -- and Networking Cable.
  5.  
  6. -- Function to safely wrap a peripheral by name
  7. local function getPeripheralByName(peripheralName)
  8.     local p = peripheral.wrap(peripheralName)
  9.     if p then
  10.         print("Successfully connected to peripheral: " .. peripheralName)
  11.         return p
  12.     else
  13.         error("Could not find peripheral: " .. peripheralName .. ". Check connection and name. Exiting.")
  14.     end
  15. end
  16.  
  17. -- --- Color Definitions (Based on your discoveries) ---
  18. -- These are the *specific numeric IDs* that work in your environment
  19. local COLOR_BLACK_BACKGROUND = 0x8000 -- User confirmed this works for black background
  20. local COLOR_WHITE_TEXT = 0x1          -- User confirmed this works for white text
  21. -- IMPORTANT: The following colors are **GUESSES** based on standard 16-color palettes.
  22. -- You might need to adjust these using the "Color Discovery Tool" below.
  23. local COLOR_RED_GUESS = 0x80          -- Often standard bitmask for Red
  24. local COLOR_YELLOW_GUESS = 0x40       -- Often standard bitmask for Yellow
  25. local COLOR_LIME_GUESS = 0x20         -- Often standard bitmask for Lime
  26. local COLOR_AQUA_LIGHT_BLUE_GUESS = 0x8 -- Often standard bitmask for Cyan/LightBlue, but you'll need to confirm your preferred shade
  27.  
  28.  
  29. -- --- Main Program ---
  30.  
  31. -- !!! IMPORTANT !!!
  32. -- Using the specified peripheral name: "fissionReactorLogicAdapter_0"
  33. local reactorPeripheralName = "fissionReactorLogicAdapter_0"
  34. local monitorPeripheralName = "monitor_0" -- Keep this as "monitor_0" unless you've confirmed otherwise
  35.  
  36. local reactor = getPeripheralByName(reactorPeripheralName)
  37. local monitor = getPeripheralByName(monitorPeripheralName)
  38.  
  39. -- Check if both peripherals were successfully wrapped
  40. if not reactor or not monitor then
  41.     return
  42. end
  43.  
  44. -- Get monitor dimensions to ensure lines are cleared properly
  45. local monitorWidth, monitorHeight = monitor.getSize()
  46.  
  47. -- --- Setup for Advanced Monitor ---
  48. monitor.setTextScale(0.75) -- A common comfortable size, try 0.5, 1.0 etc.
  49. monitor.setBackgroundColor(COLOR_BLACK_BACKGROUND) -- Use the discovered ID for black background
  50.  
  51. -- --- Initial Draw (Draw static elements once) ---
  52. monitor.clear() -- Clear once at the start to ensure a clean slate
  53. monitor.setCursorPos(1, 1)
  54. monitor.setTextColor(COLOR_WHITE_TEXT) -- Use the discovered ID for white text
  55. monitor.write("--- Mekanism Fission Reactor Status ---")
  56. monitor.setCursorPos(1, 2)
  57. monitor.write("-----------------------------------")
  58. -- Static labels (we'll update the values next to them)
  59. monitor.setCursorPos(1, 4) monitor.write("Status: ")
  60. monitor.setCursorPos(1, 5) monitor.write("Temp: ")
  61. monitor.setCursorPos(1, 6) monitor.write("Damage: ")
  62. monitor.setCursorPos(1, 7) monitor.write("Burn Rate: ")
  63. monitor.setCursorPos(1, 8) monitor.write("Fuel: ")
  64. monitor.setCursorPos(1, 9) monitor.write("Waste: ")
  65. monitor.setCursorPos(1, 10) monitor.write("Coolant: ")
  66. monitor.setCursorPos(1, 11) monitor.write("Heating: ")
  67. monitor.setCursorPos(1, 12) monitor.write("Fuel Assemblies: ")
  68. monitor.setCursorPos(1, monitorHeight) monitor.write("Last updated: ")
  69.  
  70.  
  71. -- Helper function to overwrite a line with padding and safe color handling
  72. local function overwriteLine(y, text, textColor)
  73.     monitor.setCursorPos(1, y)
  74.     -- Pad the string with spaces to overwrite any previous longer text
  75.     monitor.setTextColor(COLOR_WHITE_TEXT) -- Use the discovered white for padding spaces
  76.     monitor.write(string.rep(" ", monitorWidth)) -- Clear the entire line
  77.     monitor.setCursorPos(1, y) -- Move cursor back to start of line
  78.  
  79.     local finalColor = COLOR_WHITE_TEXT -- Default to discovered white if textColor is invalid
  80.     if type(textColor) == "number" then
  81.         -- We're not checking range to 0xFFFFFF anymore, as your monitor seems to use a different scale.
  82.         -- We're assuming any number passed will be an attempt at a valid palette ID.
  83.         finalColor = math.floor(textColor) -- Ensure it's an integer
  84.     else
  85.         -- Debug: If textColor is not a number (e.g., nil, string, table)
  86.         print("Debug: Passed textColor is not a number. Type: " .. type(textColor) .. ", Value: " .. tostring(textColor) .. " (Line: " .. y .. ")")
  87.     end
  88.  
  89.     monitor.setTextColor(finalColor)
  90.     monitor.write(text)
  91. end
  92.  
  93. -- Main loop to continuously update the monitor
  94. while true do
  95.     -- Update reactor status
  96.     overwriteLine(4, "Status: " .. (reactor.getStatus() and "Active" or "Disabled"), COLOR_WHITE_TEXT)
  97.  
  98.     -- Update Temperature
  99.     local currentTemp = reactor.getTemperature()
  100.     local tempString = string.format("Temp: %.2fK", currentTemp)
  101.     local tempColor = COLOR_WHITE_TEXT -- Default
  102.     if currentTemp > 500 then
  103.         tempColor = COLOR_YELLOW_GUESS
  104.     elseif currentTemp > 600 then
  105.         tempColor = COLOR_RED_GUESS
  106.     end
  107.     overwriteLine(5, tempString, tempColor)
  108.  
  109.     -- Update Damage
  110.     local damagePercent = reactor.getDamagePercent() * 100
  111.     local damageString = string.format("Damage: %.2f%%", damagePercent)
  112.     local damageColor = COLOR_WHITE_TEXT -- Default
  113.     if damagePercent > 50 then
  114.         damageColor = COLOR_YELLOW_GUESS
  115.     elseif damagePercent > 75 then
  116.         damageColor = COLOR_RED_GUESS
  117.     end
  118.     overwriteLine(6, damageString, damageColor)
  119.  
  120.     -- Update Burn Rate
  121.     overwriteLine(7, string.format("Burn Rate: %.2f mB/t", reactor.getActualBurnRate()), COLOR_WHITE_TEXT)
  122.  
  123.     -- Update Fuel
  124.     local fuelInfo = reactor.getFuel()
  125.     local fuelAmount = fuelInfo.amount or 0
  126.     local fuelPercentage = 0
  127.     if fuelInfo.capacity and fuelInfo.capacity > 0 then
  128.         fuelPercentage = (fuelInfo.amount / fuelInfo.capacity) * 100
  129.     end
  130.     local fuelString = string.format("Fuel: %.2f mB (%.2f%%)", fuelAmount, fuelPercentage)
  131.     local fuelColor = COLOR_WHITE_TEXT -- Default
  132.     if fuelPercentage < 10 then
  133.         fuelColor = COLOR_RED_GUESS
  134.     elseif fuelPercentage < 25 then
  135.         fuelColor = COLOR_YELLOW_GUESS
  136.     else
  137.         fuelColor = COLOR_LIME_GUESS
  138.     end
  139.     overwriteLine(8, fuelString, fuelColor)
  140.  
  141.     -- Update Waste
  142.     local wasteInfo = reactor.getWaste()
  143.     local wasteAmount = wasteInfo.amount or 0
  144.     local wastePercentage = 0
  145.     if wasteInfo.capacity and wasteInfo.capacity > 0 then
  146.         wastePercentage = (wasteInfo.amount / wasteInfo.capacity) * 100
  147.     end
  148.     local wasteString = string.format("Waste: %.2f mB (%.2f%%)", wasteAmount, wastePercentage)
  149.     local wasteColor = COLOR_WHITE_TEXT -- Default
  150.     if wastePercentage > 90 then
  151.         wasteColor = COLOR_RED_GUESS
  152.     elseif wastePercentage > 75 then
  153.         wasteColor = COLOR_YELLOW_GUESS
  154.     else
  155.         wasteColor = COLOR_WHITE_TEXT
  156.     end
  157.     overwriteLine(9, wasteString, wasteColor)
  158.  
  159.     -- Update Coolant
  160.     local coolant = reactor.getCoolant()
  161.     local coolantPercentage = reactor.getCoolantFilledPercentage() * 100
  162.     local coolantString = string.format("Coolant: %s %.2f mB (%.2f%%)", coolant.type, coolant.amount, coolantPercentage)
  163.     local coolantColor = COLOR_WHITE_TEXT -- Default
  164.     if coolantPercentage < 10 then
  165.         coolantColor = COLOR_RED_GUESS
  166.     elseif coolantPercentage < 25 then
  167.         coolantColor = COLOR_YELLOW_GUESS
  168.     else
  169.         coolantColor = COLOR_AQUA_LIGHT_BLUE_GUESS
  170.     end
  171.     overwriteLine(10, coolantString, coolantColor)
  172.  
  173.     -- Update Heating
  174.     overwriteLine(11, string.format("Heating: %.2fJ/t (Env: %.2fJ/t)", reactor.getHeatingRate(), COLOR_WHITE_TEXT))
  175.  
  176.     -- Update Fuel Assemblies
  177.     overwriteLine(12, string.format("Fuel Assemblies: %d", reactor.getFuelAssemblies()), COLOR_WHITE_TEXT)
  178.  
  179.     -- Update Timestamp
  180.     overwriteLine(monitorHeight, "Last updated: " .. os.date("%H:%M:%S"), COLOR_WHITE_TEXT)
  181.  
  182.     sleep(1) -- Wait for 1 second before updating again
  183. end
Advertisement
Add Comment
Please, Sign In to add comment