Jump to content

1.11.2 Sounds that follow a player.


Viesis

Recommended Posts

Is there a way to play a sound (a song in this case) and have it follow the player when they move?  I see that Entity::playSound seems like it just get the position and executes the sound at said position, almost like a record. When you move away form the pos, it fades. I am trying to find a way to play a song on an entity, like a player, and have it follow them, if that is possible. Any direction would be much appreciated. Thank you.

Edit: Also is there a way to disable the background music while said song is playing?

Edited by Viesis
Link to comment
Share on other sites

22 minutes ago, diesieben07 said:

Look at how the minecart sounds work.

I found MovingSoundMinecart and See that I could just made a new generic one, but just not sure how to call it.  I haven't really worked with sounds, and I don't think I use the player.playSound(SoundEvents.RECORD_WARD, 0.5F, 0.5F) I had as a test since it will play based on my players pos and not move. 

Link to comment
Share on other sites

If the sound system hasn't changed too much, then I think that a moving sound remembers its entity and then ticks periodically to correct its position to wherever the entity has moved. I remember triggering a sound on the server (which handled the sending of packets to all players within earshot), but then my mod on the client-side needed to use a Forge event to replace the default sound renderer (also called a "sound", adding to the confusion) with my my own custom renderer because the server's packets could only spawn the default.

 

One of the confusing things about sound (at least up to MC v 1,10.2) was the confusability between server-side and client-side processing (and multiple methods having the same name but subtly different purposes).

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

I do that very thing in my mod.  Some notes:

 

  • Works better if you set the sound to have no attenuation (volume doesn't diminish with distance)
  • I place the sound location 32 blocks above the player rather than right near by.  Reason is that the sound position is updated once per tick and depending on the sound it would have clicks because the player position moves during a partial tick.  Having the actual source location above the player reduces this impact.
Edited by OreCruncher
Link to comment
Share on other sites

No attenuation means that it may as well not be a positioned sound: another player won't perceive the effect as a boom-box traveling with the first player, but exactly the same as if the boombox was on their shoulder.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

In my mod I use a full stereo non moving sound for the ThePlayer, then all the listeners in the area get the monaural moving sound. The issue with moving sound as stated earlier is you get a pulsing effect as the client updates and moves the 3D sound source to follow as ThePlayer moves.

Link to comment
Share on other sites

19 minutes ago, Draco18s said:

No attenuation means that it may as well not be a positioned sound: another player won't perceive the effect as a boom-box traveling with the first player, but exactly the same as if the boombox was on their shoulder.

What I found is that non-attenuated sounds are located at 0,0,0 in the world.  For my system I can hear that sound relative to where the player is located and facing.  Not sure why that is.  It's why I did the 32 blocks above the player thing.

Link to comment
Share on other sites

Thank you everyone for your responses, I will be tackling this tonight.  I found how the MovingSoundMinecart was called but I am getting no sound when I try to mimic it.  I will see what I can do. :)

Edit:  AAANNNDDD, my volume was at 0.  Looks like it is working pretty well now.  Ahh, I knew it was probably something minor.  Again, thank you everyone for your help.  I really appreciate it.

Edited by Viesis
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.