Viesis Posted April 5, 2017 Share Posted April 5, 2017 (edited) 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 April 5, 2017 by Viesis Quote Link to comment Share on other sites More sharing options...
Viesis Posted April 5, 2017 Author Share Posted April 5, 2017 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. Quote Link to comment Share on other sites More sharing options...
Viesis Posted April 5, 2017 Author Share Posted April 5, 2017 4 hours ago, diesieben07 said: You can cancel any sound using PlaySoundEvent. Thank you, I was able to stop the background music when I wanted to play a song. Quote Link to comment Share on other sites More sharing options...
jeffryfisher Posted April 5, 2017 Share Posted April 5, 2017 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). Quote 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 More sharing options...
OreCruncher Posted April 5, 2017 Share Posted April 5, 2017 (edited) 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 April 5, 2017 by OreCruncher Quote Link to comment Share on other sites More sharing options...
Draco18s Posted April 5, 2017 Share Posted April 5, 2017 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. Quote 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 More sharing options...
Aeronica Posted April 5, 2017 Share Posted April 5, 2017 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. Quote Link to comment Share on other sites More sharing options...
OreCruncher Posted April 5, 2017 Share Posted April 5, 2017 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. Quote Link to comment Share on other sites More sharing options...
Viesis Posted April 6, 2017 Author Share Posted April 6, 2017 (edited) 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 April 6, 2017 by Viesis Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.