Advertisement
zamoth

Untitled

Jul 5th, 2025 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.11 KB | None | 0 0
  1. local modemSide = "left" -- Use your modem side here
  2. local monitor = peripheral.find("monitor") or peripheral.wrap("monitor_5")
  3. if not monitor then error("Monitor not found.") end
  4.  
  5. rednet.open(modemSide)
  6.  
  7. monitor.setTextScale(0.5)
  8. local monW, monH = monitor.getSize()
  9. local midX = math.floor(monW / 2)
  10.  
  11. local function coloredLine(mon, color, text)
  12.   mon.setTextColor(color)
  13.   mon.write(text)
  14.   mon.setTextColor(colors.white)
  15. end
  16.  
  17. local prevCrafting = {}
  18. local craftHistory = {} -- list of {item, cpu, timestamp, duration}
  19.  
  20. while true do
  21.   local senderId, jobs = rednet.receive("ae2_crafting_status")
  22.   monitor.clear()
  23.   monitor.setCursorPos(1,1)
  24.   coloredLine(monitor, colors.white, "Live CPUs:\n")
  25.   monitor.setCursorPos(midX+1,1)
  26.   coloredLine(monitor, colors.white, "Crafting History:\n")
  27.  
  28.   -- Draw vertical grey line between sections
  29.   for y = 1, monH do
  30.     monitor.setCursorPos(midX, y)
  31.     monitor.setTextColor(colors.gray)
  32.     monitor.write("|")
  33.   end
  34.   monitor.setTextColor(colors.white) -- reset
  35.  
  36.   -- Find finished jobs
  37.   local currBusy = {}
  38.   for _, job in ipairs(jobs or {}) do
  39.     if job.isBusy then
  40.       currBusy[job.cpu] = job
  41.     end
  42.   end
  43.   for cpu, prev in pairs(prevCrafting) do
  44.     if prev and (not currBusy[cpu]) and prev.item then
  45.       -- CPU was busy, now idle: job finished!
  46.       local tstamp = textutils.formatTime(os.time(), true)
  47.       table.insert(craftHistory, 1, {item=prev.item, cpu=cpu, timestamp=tstamp, duration=prev.elapsed})
  48.       if #craftHistory > monH - 1 then
  49.         table.remove(craftHistory, #craftHistory)
  50.       end
  51.     end
  52.   end
  53.   prevCrafting = currBusy
  54.  
  55.   -- LEFT: Show all CPUs
  56.   local line = 2
  57.   if type(jobs) ~= "table" or #jobs == 0 then
  58.     monitor.setCursorPos(1,line)
  59.     coloredLine(monitor, colors.gray, "  (None)\n")
  60.     line = line + 1
  61.   else
  62.     for _, job in ipairs(jobs) do
  63.       if line > monH - 2 then break end
  64.       monitor.setCursorPos(1,line)
  65.       coloredLine(monitor, colors.cyan, string.format("CPU #%d: ", job.cpu))
  66.       if job.isBusy and job.item then
  67.         coloredLine(monitor, colors.green, job.item .. "\n")
  68.         line = line + 1
  69.         monitor.setCursorPos(3,line)
  70.         local pct = 0
  71.         if (job.progress and job.total and job.total > 0) then
  72.           pct = math.floor((job.progress / job.total) * 100)
  73.         end
  74.         coloredLine(monitor, colors.orange, string.format("Progress: %d%%", pct))
  75.         line = line + 1
  76.         monitor.setCursorPos(3,line)
  77.         coloredLine(monitor, colors.gray, string.format("Elapsed: %ds", job.elapsed or 0))
  78.         line = line + 2
  79.       else
  80.         coloredLine(monitor, colors.gray, "idle\n")
  81.         line = line + 2
  82.       end
  83.     end
  84.   end
  85.  
  86.   -- RIGHT: Crafting history (newest first), [timestamp]  name  (duration)
  87.   for i, hist in ipairs(craftHistory) do
  88.     if i > monH - 1 then break end
  89.     monitor.setCursorPos(midX+1, i+1)
  90.     coloredLine(monitor, colors.gray, "[" .. hist.timestamp .. "] ")
  91.     coloredLine(monitor, colors.green, hist.item .. " ")
  92.     coloredLine(monitor, colors.orange, string.format("(%ds)\n", hist.duration))
  93.   end
  94. end
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement