Advertisement
jaklsfjlsak

信号接收器 原型v2 红石

Mar 22nd, 2025
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Open rednet on the modem side (adjust "left" as needed)
  2. rednet.open("top")
  3.  
  4. print("Waiting for coordinate broadcasts when redstone is active on the front...")
  5.  
  6. while true do
  7.     -- Only process messages when redstone signal on the "front" is on.
  8.     if redstone.getInput("front") then
  9.         -- Use a timeout (0.5 seconds) so the call doesn't block indefinitely and allows rechecking the redstone state.
  10.         local senderID, message, protocol = rednet.receive("coordBroadcast", 0.5)
  11.        
  12.         if senderID then
  13.             if message and message.x and message.y and message.z then
  14.                 print("Received coordinates from computer " .. senderID .. ":")
  15.                 print("X: " .. message.x .. ", Y: " .. message.y .. ", Z: " .. message.z)
  16.             else
  17.                 print("Received invalid data from computer " .. senderID)
  18.             end
  19.         end
  20.     else
  21.         -- Optionally, you can print a message when redstone is off or simply sleep quietly.
  22.         -- print("Redstone is off on the front; not receiving messages.")
  23.         sleep(0.1)
  24.     end
  25. end
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement