Jump to content

[1.18.1] Sound and sides


NJSwede

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.