Advertisement
ccraftersanonmoose

ME storage monitor

Mar 18th, 2023 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | Gaming | 0 0
  1. -- Load necessary APIs and peripherals
  2. local me = peripheral.wrap("meBridge_3")
  3.  
  4. -- Set up the monitor(s)
  5. local monitor_side = "left"  -- Change this to match the side where your monitor is located
  6. local monitor = peripheral.wrap(monitor_side)
  7. monitor.setTextScale(0.5)  -- Adjust the text scale as needed for your monitor size
  8.  
  9. -- Set up the display parameters
  10. local item_column_width = 25
  11. local count_column_width = 10
  12. local num_columns = math.floor(monitor.getSize() / (item_column_width + count_column_width))
  13.  
  14. -- Set up the refresh interval (in seconds)
  15. local refresh_interval = 5
  16.  
  17.  
  18. function display_items()
  19.     -- Get the list of items from the ME storage system
  20.     local items = me.listItems()
  21.  
  22.     -- Clear the monitor
  23.     monitor.clear()
  24.  
  25.     -- Display the header row
  26.     monitor.setCursorPos(1,1)
  27.     monitor.write("Item" .. string.rep(" ", item_column_width - 4) .. "Count")
  28.  
  29.     -- Display each item and its count in a row
  30.     local row = 2
  31.     for i, item in ipairs(items) do
  32.         local col = (i-1) % num_columns + 1
  33.         local _, item_start = string.find(item.name, ":")
  34.         local item_name = item.name:gsub("_", " "):sub(item_start + 1, item_start + item_column_width)
  35.         monitor.setCursorPos((col-1) * (item_column_width + count_column_width) + 1, row)
  36.         monitor.write(item_name)
  37.         monitor.setCursorPos(col * (item_column_width + count_column_width) - count_column_width + 1, row)
  38.         monitor.write(tostring(item.amount):sub(1, count_column_width))
  39.         if col == num_columns then
  40.             row = row + 1
  41.         end
  42.     end
  43. end
  44.  
  45.  
  46.  
  47. -- Loop to update the display at regular intervals
  48. while true do
  49.     display_items()
  50.     sleep(refresh_interval)
  51. end
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement