Posted January 31, 20223 yr This has probably been asked and answered a million times, so feel free to flame me! But anyway, the little enchantment mod I'm playing with has most of its mechanics implemented on the server side. As it should, I believe. However, when certain things happen, I want to play a sound. Now, if I do that on the server side, everyone except the player will hear it. To play it to the player, I need to do it on the client side. My simple question is this: What's the best practice? Do I need to send some kind of network message to the client side informing it about the event or is there a more standard way? I figured there must be... And yes, I've read this https://mcforge.readthedocs.io/en/latest/effects/sounds/ but it doesn't really answer my question.
January 31, 20223 yr Author 24 minutes ago, diesieben07 said: Yes, it does. My guess is you are calling method 1 or 2 from the "Level" class (playSound(Player, BlockPos, SoundEvent, SoundCategory, volume, pitch) or playSound(Player, double x, double y, double z, SoundEvent, SoundCategory, volume, pitch)). Like stated in the documentation, when called with a player parameter these methods must be called on both logical sides. Like also stated in the documentation, you can pass in null for the player for it to work purely server-side. Yes, but how do I trigger the code that plays the sound on the client side on a multiplayer server? I guess I need to send a network package to inform the client of the event. Right now, I just have a flag in a static variable, but that obviously breaks if the server and client aren't running in the same process.
January 31, 20223 yr Author 15 minutes ago, diesieben07 said: Calling playSound on the server with null as the player will handle it all for you. Aaaaah... OK. I knew there was something simple I was overlooking!
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.