Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local time = 0
- local storage = peripheral.wrap("back")
- local mon = peripheral.find("monitor")
- local w, h = mon.getSize()
- -- The item you want to track and its fixed EMC value
- local tracked_item = "projecte:rm_furnace"
- local tracked_emc_value = 10059784
- -- History buffer for EMC values and timestamps
- local emc_history = {}
- local function clear()
- mon.clear()
- mon.setTextScale(2)
- end
- function formatTime(sec)
- return string.format("%.2d:%.2d:%.2d", sec / (60 * 60), sec / 60 % 60, sec % 60)
- end
- function formatLargeNumber(n)
- local suffixes = {"", "K", "M", "B", "T", "Q"}
- local i = 1
- while n >= 1000 and i < #suffixes do
- n = n / 1000
- i = i + 1
- end
- return string.format("%.1f %s", n, suffixes[i])
- end
- -- Function to center text horizontally
- local function centerText(line, text)
- local xPos = math.floor((w - #text) / 2) + 1
- mon.setCursorPos(xPos, line)
- mon.write(text)
- end
- clear()
- while true do
- mon.clear()
- local emc = 0
- local amount = 0
- -- Iterate over each item in the storage container
- for slot, item in pairs(storage.list()) do
- if item.name == tracked_item then
- amount = amount + item.count
- emc = emc + (item.count * tracked_emc_value)
- end
- end
- -- Add current EMC and timestamp to history buffer
- table.insert(emc_history, {emc = emc, timestamp = os.clock()})
- -- Keep only the last 60 entries (~1 minute history)
- if #emc_history > 60 then
- table.remove(emc_history, 1)
- end
- -- Calculate EMC/m
- local emcrate = 0
- if #emc_history >= 2 then
- local first = emc_history[1]
- local last = emc_history[#emc_history]
- local emc_diff = last.emc - first.emc
- local time_diff = last.timestamp - first.timestamp
- if time_diff > 0 then
- emcrate = (emc_diff / time_diff) * 60 -- Scale to per minute
- emcrate = math.max(emcrate, 0) -- Prevent negative rates
- end
- end
- -- Display Information (Centered)
- mon.setTextColor(colors.black)
- centerText(1, "EMC Monitor")
- centerText(3, "EMC: " .. formatLargeNumber(emc))
- centerText(4, "EMC/m: " .. formatLargeNumber(emcrate))
- centerText(5, "Time: " .. formatTime(time))
- centerText(6, "Amount: " .. formatLargeNumber(amount))
- time = time + 1
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement