GrooveypenguinX

ae2warehouse pocket computer

Jan 4th, 2025 (edited)
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. -- WirelessMonitor.lua
  2. -- Version 1.4.2
  3. -- Author: Modified by AshGrey
  4. -- Date: 2024-10-16
  5.  
  6. -- This script displays missing items or status updates from the AE2 Warehouse on a pocket computer, regular computer, or monitor.
  7.  
  8. -------------------------------------------------------------------------------
  9. -- INITIALIZATION
  10. -------------------------------------------------------------------------------
  11.  
  12. local function init()
  13. term.clear()
  14. term.setCursorPos(1, 1)
  15. print("Initializing Wireless Monitor...")
  16.  
  17. local modem = peripheral.find("modem")
  18. if not modem then error("Ender Modem not found.") end
  19. print("Ender Modem initialized.")
  20.  
  21. local monitor = peripheral.find("monitor")
  22. local display = term -- Default display to terminal
  23.  
  24. if monitor then
  25. monitor.setTextScale(0.5)
  26. display = monitor
  27. print("Monitor detected. Output will be displayed on the monitor.")
  28. else
  29. print("No monitor detected. Output will be displayed on the terminal.")
  30. end
  31.  
  32. return modem, display
  33. end
  34.  
  35. local modem, display = init()
  36. local channel = 1
  37. modem.open(channel)
  38.  
  39. -------------------------------------------------------------------------------
  40. -- FUNCTIONS
  41. -------------------------------------------------------------------------------
  42.  
  43. -- Strips unwanted prefixes from strings
  44. local function removePrefixes(str)
  45. return str:gsub("minecraft:", ""):gsub("minecolonies:", ""):gsub("domum_ornamentum:", ""):gsub("Missing items:", "")
  46. end
  47.  
  48. -- Wraps text for monitors
  49. local function wrapText(text, width)
  50. local wrappedText = {}
  51. for line in text:gmatch("[^\n]+") do
  52. while #line > width do
  53. local segment = line:sub(1, width):match("^(.-)%s") or line:sub(1, width)
  54. table.insert(wrappedText, segment)
  55. line = line:sub(#segment + 1):match("^%s*(.*)") or ""
  56. end
  57. if #line > 0 then
  58. table.insert(wrappedText, line)
  59. end
  60. end
  61. return wrappedText
  62. end
  63.  
  64. -- Writes text to the display
  65. local function writeToDisplay(display, lines)
  66. display.clear()
  67. display.setCursorPos(1, 1)
  68. for _, line in ipairs(lines) do
  69. display.write(line)
  70. local _, y = display.getCursorPos()
  71. display.setCursorPos(1, y + 1)
  72. end
  73. end
  74.  
  75. -- Processes item sections
  76. local function processItemSection(name, displayName, blocks, missingCount)
  77. local lines = { (displayName or "") .. "\n", "Type: " .. name, "Count: " .. missingCount }
  78.  
  79. if blocks then
  80. local blockList = {}
  81. for block in blocks:gmatch("([^,]+)") do
  82. table.insert(blockList, block)
  83. end
  84.  
  85. -- Check if the name or display name contains "shingle"
  86. if name:lower():find("shingle") or (displayName and displayName:lower():find("shingle")) then
  87. -- Swap block order for "shingle" items
  88. if #blockList >= 2 then
  89. table.insert(lines, " Shingle:" .. blockList[2])
  90. table.insert(lines, " Support:" .. blockList[1])
  91. else
  92. -- Less than 2 blocks, show them normally
  93. for _, block in ipairs(blockList) do
  94. table.insert(lines, " " .. block)
  95. end
  96. end
  97. else
  98. -- Normal block display
  99. for _, block in ipairs(blockList) do
  100. table.insert(lines, " " .. block)
  101. end
  102. end
  103. end
  104.  
  105. return lines
  106. end
  107.  
  108.  
  109. -- Parses and displays missing items
  110. local function displayMissingItems(display, message)
  111. local lines = { "Missing Items Report:" }
  112. for itemSection in message:gmatch("([^\n]+:.-Missing Count: %d+)") do
  113. local name = itemSection:match("^([^:]+):")
  114. local displayName = itemSection:match("Display Name: ([^\n]+)")
  115. local blocks = itemSection:match("Blocks Needed: ([^\n]+)")
  116. local missingCount = itemSection:match("Missing Count: (%d+)")
  117. local sectionLines = processItemSection(name, displayName, blocks, missingCount)
  118. for _, line in ipairs(sectionLines) do
  119. table.insert(lines, line)
  120. end
  121. end
  122. writeToDisplay(display, wrapText(table.concat(lines, "\n"), display.getSize()))
  123. end
  124.  
  125. -- Displays non-item status updates
  126. local function displayStatusUpdate(display, message)
  127. local lines = wrapText("Status Update:\n" .. message, display.getSize())
  128. writeToDisplay(display, lines)
  129. end
  130.  
  131. -------------------------------------------------------------------------------
  132. -- MAIN LOOP
  133. -------------------------------------------------------------------------------
  134.  
  135. print("Wireless Monitor is now running...")
  136. while true do
  137. local event, _, receivedChannel, _, message = os.pullEvent("modem_message")
  138. if receivedChannel == channel then
  139. message = removePrefixes(message)
  140.  
  141. if message:find("Missing Count:") then
  142. displayMissingItems(display, message)
  143. else
  144. displayStatusUpdate(display, message)
  145. end
  146. end
  147. end
  148.  
Advertisement
Add Comment
Please, Sign In to add comment