Huntertech01

Induction Matrix monitor

Oct 6th, 2025 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.14 KB | None | 0 0
  1. -- Mekanism Induction Matrix Monitor + Redstone Hysteresis
  2. -- CC:Tweaked 1.21.1
  3. -- Auto-detects matrix, monitor, and redstone relay
  4. -- Redstone ON below 10%, OFF above 90%
  5.  
  6. -- === Detect Peripherals ===
  7. local modem = peripheral.find("modem")
  8. if not modem then
  9.     print("❌ No wired modem found on this computer.")
  10.     return
  11. end
  12.  
  13. local peripherals = peripheral.getNames()
  14. local matrixName, redstoneName = nil, nil
  15.  
  16. for _, name in ipairs(peripherals) do
  17.     if name:find("inductionPort") or name:find("inductionMatrix") then
  18.         matrixName = name
  19.     elseif name:find("redstoneIntegrator") or name:find("redstoneRelay") then
  20.         redstoneName = name
  21.     end
  22. end
  23.  
  24. if not matrixName then
  25.     print("❌ No Mekanism Induction Matrix found on the network.")
  26.     return
  27. end
  28.  
  29. local matrix = peripheral.wrap(matrixName)
  30. local redstone = redstoneName and peripheral.wrap(redstoneName) or nil
  31. local monitor = peripheral.find("monitor")
  32.  
  33. if not monitor then
  34.     print("❌ No monitor found.")
  35.     return
  36. end
  37.  
  38. monitor.setTextScale(1)
  39. monitor.setBackgroundColor(colors.black)
  40. monitor.clear()
  41.  
  42. -- === Helper Functions ===
  43. local function drawBar(mon, y, percent, width)
  44.     local filled = math.floor(width * percent / 100)
  45.     local color = colors.green
  46.     if percent < 25 then color = colors.red
  47.     elseif percent < 60 then color = colors.yellow end
  48.  
  49.     mon.setCursorPos(1, y)
  50.     mon.setBackgroundColor(colors.gray)
  51.     mon.write(string.rep(" ", width))
  52.     mon.setCursorPos(1, y)
  53.     mon.setBackgroundColor(color)
  54.     mon.write(string.rep(" ", filled))
  55.     mon.setBackgroundColor(colors.black)
  56. end
  57.  
  58. local monX, monY = monitor.getSize()
  59. local function centerText(y, text)
  60.     local x = math.floor((monX - #text) / 2)
  61.     if x < 1 then x = 1 end
  62.     monitor.setCursorPos(x, y)
  63.     monitor.write(text)
  64. end
  65.  
  66. -- === Configurable Thresholds ===
  67. local lowThreshold = 10   -- % to turn ON redstone
  68. local highThreshold = 90  -- % to turn OFF redstone
  69. local redstoneSide = "back"  -- side of the redstone integrator output
  70.  
  71. local redstoneState = false
  72.  
  73. -- === Main Loop ===
  74. while true do
  75.     local energy = matrix.getEnergy() or 0
  76.     local maxEnergy = matrix.getMaxEnergy() or 1
  77.     local input = matrix.getLastInput and matrix.getLastInput() or 0
  78.     local output = matrix.getLastOutput and matrix.getLastOutput() or 0
  79.     local percent = (energy / maxEnergy) * 100
  80.  
  81.     -- === Hysteresis Control Logic ===
  82.     if redstone then
  83.         if percent < lowThreshold and not redstoneState then
  84.             redstone.setOutput(redstoneSide, true)
  85.             redstoneState = true
  86.         elseif percent > highThreshold and redstoneState then
  87.             redstone.setOutput(redstoneSide, false)
  88.             redstoneState = false
  89.         end
  90.     end
  91.  
  92.     -- === Display ===
  93.     monitor.clear()
  94.     monitor.setTextColor(colors.white)
  95.  
  96.     centerText(1, "⚡ Mekanism Induction Matrix ⚡")
  97.     centerText(2, string.rep("-", monX))
  98.  
  99.     monitor.setCursorPos(2, 4)
  100.     monitor.write(string.format("Stored: %.2f MFE", energy / 1e6))
  101.     monitor.setCursorPos(2, 5)
  102.     monitor.write(string.format("Capacity: %.2f MFE", maxEnergy / 1e6))
  103.     monitor.setCursorPos(2, 6)
  104.     monitor.write(string.format("Charge: %.1f%%", percent))
  105.     monitor.setCursorPos(2, 7)
  106.     monitor.write(string.format("Input:  %.2f kFE/t", input / 1e3))
  107.     monitor.setCursorPos(2, 8)
  108.     monitor.write(string.format("Output: %.2f kFE/t", output / 1e3))
  109.  
  110.     drawBar(monitor, 10, percent, monX)
  111.  
  112.     if redstone then
  113.         monitor.setCursorPos(2, 12)
  114.         if redstoneState then
  115.             monitor.setTextColor(colors.red)
  116.             monitor.write(string.format("⚠️ LOW POWER (%.1f%%) — Redstone ON ⚠️", percent))
  117.         else
  118.             monitor.setTextColor(colors.green)
  119.             monitor.write(string.format("Power Stable (%.1f%%) — Redstone OFF", percent))
  120.         end
  121.     else
  122.         monitor.setCursorPos(2, 12)
  123.         monitor.setTextColor(colors.yellow)
  124.         monitor.write("No redstone relay found on network.")
  125.     end
  126.  
  127.     monitor.setTextColor(colors.white)
  128.     centerText(monY, "⟳ Updating every 2s...")
  129.     sleep(2)
  130. end
Advertisement
Add Comment
Please, Sign In to add comment