Advertisement
Grexxity

Untitled

Oct 19th, 2024 (edited)
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.40 KB | None | 0 0
  1. local time = 0
  2. local storage = peripheral.wrap("back")
  3. local mon = peripheral.find("monitor")
  4. local w, h = mon.getSize()
  5.  
  6. -- The item you want to track and its fixed EMC value
  7. local tracked_item = "projecte:rm_furnace"
  8. local tracked_emc_value = 10059784
  9.  
  10. -- History buffer for EMC values and timestamps
  11. local emc_history = {}
  12.  
  13. local function clear()
  14.     mon.clear()
  15.     mon.setTextScale(2)
  16. end
  17.  
  18. function formatTime(sec)
  19.     return string.format("%.2d:%.2d:%.2d", sec / (60 * 60), sec / 60 % 60, sec % 60)
  20. end
  21.  
  22. function formatLargeNumber(n)
  23.     local suffixes = {"", "K", "M", "B", "T", "Q"}
  24.     local i = 1
  25.     while n >= 1000 and i < #suffixes do
  26.         n = n / 1000
  27.         i = i + 1
  28.     end
  29.     return string.format("%.1f %s", n, suffixes[i])
  30. end
  31.  
  32. -- Function to center text horizontally
  33. local function centerText(line, text)
  34.     local xPos = math.floor((w - #text) / 2) + 1
  35.     mon.setCursorPos(xPos, line)
  36.     mon.write(text)
  37. end
  38.  
  39. clear()
  40.  
  41. while true do
  42.     mon.clear()
  43.  
  44.     local emc = 0
  45.     local amount = 0
  46.  
  47.     -- Iterate over each item in the storage container
  48.     for slot, item in pairs(storage.list()) do
  49.         if item.name == tracked_item then
  50.             amount = amount + item.count
  51.             emc = emc + (item.count * tracked_emc_value)
  52.         end
  53.     end
  54.  
  55.     -- Add current EMC and timestamp to history buffer
  56.     table.insert(emc_history, {emc = emc, timestamp = os.clock()})
  57.  
  58.     -- Keep only the last 60 entries (~1 minute history)
  59.     if #emc_history > 60 then
  60.         table.remove(emc_history, 1)
  61.     end
  62.  
  63.     -- Calculate EMC/m
  64.     local emcrate = 0
  65.     if #emc_history >= 2 then
  66.         local first = emc_history[1]
  67.         local last = emc_history[#emc_history]
  68.         local emc_diff = last.emc - first.emc
  69.         local time_diff = last.timestamp - first.timestamp
  70.  
  71.         if time_diff > 0 then
  72.             emcrate = (emc_diff / time_diff) * 60  -- Scale to per minute
  73.             emcrate = math.max(emcrate, 0)         -- Prevent negative rates
  74.         end
  75.     end
  76.  
  77.     -- Display Information (Centered)
  78.     mon.setTextColor(colors.black)
  79.     centerText(1, "EMC Monitor")
  80.  
  81.     centerText(3, "EMC: " .. formatLargeNumber(emc))
  82.     centerText(4, "EMC/m: " .. formatLargeNumber(emcrate))
  83.     centerText(5, "Time: " .. formatTime(time))
  84.     centerText(6, "Amount: " .. formatLargeNumber(amount))
  85.  
  86.     time = time + 1
  87.     sleep(1)
  88. end
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement