Advertisement
Guest User

Untitled

a guest
Nov 4th, 2024
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. -- Configuration for the additional computer
  2. local modem = peripheral.wrap("top") -- Ender modem on the top
  3. modem.open(1) -- Open channel 1 to listen for messages
  4.  
  5. -- Function to initialize all redstone signals to 0 at startup
  6. local function initializeRedstone()
  7. rs.setBundledOutput("bottom", 0) -- Set all bundled signals to 0
  8. rs.setOutput("bottom", false) -- Turn off main redstone signal
  9. end
  10.  
  11. initializeRedstone() -- Set signals to 0 at the first startup
  12.  
  13. -- Processing messages and controlling redstone
  14. while true do
  15. local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  16. if channel == 1 then
  17. local id = message.id
  18. local state = message.state
  19.  
  20. -- If ID is "grinder", set main redstone signal on the bottom
  21. if id == "grinder" then
  22. rs.setOutput("bottom", state)
  23. elseif type(id) == "number" and id >= 1 and id <= 16 then
  24. -- Use `setBundledOutput` for individual switches
  25. local color = 2 ^ (id - 1) -- Convert ID to the appropriate color bit
  26. local currentOutput = rs.getBundledOutput("bottom")
  27. if state then
  28. rs.setBundledOutput("bottom", bit.bor(currentOutput, color))
  29. else
  30. rs.setBundledOutput("bottom", bit.band(currentOutput, bit.bnot(color)))
  31. end
  32. end
  33. end
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement