SuperMcBrent

bundle_reader

Mar 25th, 2026
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. peripheral.find("modem", rednet.open)
  2.  
  3. local BUNDLED_SIDE = "back"
  4.  
  5. local bundledColors = {
  6.     colors.white,     -- 1
  7.     colors.orange,    -- 2
  8.     colors.magenta,   -- 4
  9.     colors.lightBlue, -- 8
  10.     colors.yellow,    -- 16
  11.     colors.lime,      -- 32
  12.     colors.pink,      -- 64
  13.     colors.gray,      -- 128
  14.     colors.lightGray, -- 256
  15.     colors.cyan,      -- 512
  16.     colors.purple,    -- 1024
  17.     colors.blue,      -- 2048
  18.     colors.brown,     -- 4096
  19.     colors.green,     -- 8192
  20.     colors.red,       -- 16384
  21.     colors.black      -- 32768
  22. }
  23.  
  24. local function getRedstoneSignalData()
  25.     local channels = {}
  26.  
  27.     for _, color in ipairs(bundledColors) do
  28.         channels[color] = rs.testBundledInput(BUNDLED_SIDE, color)
  29.     end
  30.  
  31.     return { channels = channels }
  32. end
  33.  
  34. local function HandleRequest(sender, message, protocol)
  35.     print("Handling: " .. tostring(message))
  36.     if message == "provideBundleSignals" then
  37.         local data = getRedstoneSignalData()
  38.         rednet.send(sender, data, protocol)
  39.     end
  40. end
  41.  
  42. local function requestListener()
  43.     while true do
  44.         local sender, message, protocol = rednet.receive()
  45.         if type(message) == "table" and protocol == "batchedRequests" then
  46.             print("Received batch of " .. #message .. " requests")
  47.             for _, req in ipairs(message) do
  48.                 HandleRequest(sender, req.message, req.protocol)
  49.             end
  50.         else
  51.             HandleRequest(sender, message, protocol)
  52.         end
  53.     end
  54. end
  55.  
  56. local function bundleMonitor()
  57.     while true do
  58.         sleep(0.5)
  59.     end
  60. end
  61.  
  62. parallel.waitForAll(bundleMonitor, requestListener)
  63.  
Advertisement
Add Comment
Please, Sign In to add comment