The world is the world where your entity is right now. theEntityYouWantToPlaySoundAt is your player entity. The path to the sound is usually YOURMODID:PATHTOTHESOUND. The first float is the pitch and the second float is the volume at which the sound will play.
Thanks! That worked, I just had to figure out how to set up the sounds .json- now a twist. My sound is a song that I wanted to play, and I see that it doesn't stop the default music from playing and cuts out after a few seconds. Is there a different line of code I should use for this?
Either way, Thanks again. I will be sure to bookmark this page for later use.
<derp> The fading out is apparently just part of the song. But still, is there a way to stop any music that is already playing? The song is activated by a right click with an item, so if the player just holds it down, their ears die within seconds. That can't be good for the mod reputation.
After further testing (I can't write it all in one post) I have found that the sound neither follows the player...
All of my problems I am too noobish to understand:
Needs to stop other sounds, like itself.
Needs to follow player.
Note: The "fading out" was of course just me walking out of range of the song.
*sigh* More notes, and I apologize for making this thread a mess. I need it to play for only the player who activated the song.
In that case, do not use World#playSoundAtEntity, use Player#playSound. The second one will only play the sound for this specific player. The parameters are the same, except the first one, as you do not need to give a location.
I'm not sure how you would stop music, or how you would stop your player from right clicking furiously, sorry
[EDIT]
I found that there is a PlaySoundEvent, maybe you could look into that
Is there a simple way to play a sound somewhere in the src/main/resources folder?
I have an item with this.onItemRightClick(); set up, but I need to know what I would do to play a sound.
Yes, I am very active. I am a noob.
Thanks!
Been playing since 1.2_02!
You should use this:
Let me break it down for you:
The world is the world where your entity is right now. theEntityYouWantToPlaySoundAt is your player entity. The path to the sound is usually YOURMODID:PATHTOTHESOUND. The first float is the pitch and the second float is the volume at which the sound will play.
Check out my mod, Placeable Items!
If my comment helped you or you just like me, hit the green arrow down there!
Thanks! That worked, I just had to figure out how to set up the sounds .json- now a twist. My sound is a song that I wanted to play, and I see that it doesn't stop the default music from playing and cuts out after a few seconds. Is there a different line of code I should use for this?
Either way, Thanks again. I will be sure to bookmark this page for later use.
Been playing since 1.2_02!
<derp> The fading out is apparently just part of the song. But still, is there a way to stop any music that is already playing? The song is activated by a right click with an item, so if the player just holds it down, their ears die within seconds. That can't be good for the mod reputation.
After further testing (I can't write it all in one post) I have found that the sound neither follows the player...
All of my problems I am too noobish to understand:
Needs to stop other sounds, like itself.
Needs to follow player.
Note: The "fading out" was of course just me walking out of range of the song.
Hopefully I can close this soon.
Been playing since 1.2_02!
*sigh* More notes, and I apologize for making this thread a mess. I need it to play for only the player who activated the song.
Been playing since 1.2_02!
In that case, do not use World#playSoundAtEntity, use Player#playSound. The second one will only play the sound for this specific player. The parameters are the same, except the first one, as you do not need to give a location.
I'm not sure how you would stop music, or how you would stop your player from right clicking furiously, sorry
[EDIT]
I found that there is a PlaySoundEvent, maybe you could look into that
Check out my mod, Placeable Items!
If my comment helped you or you just like me, hit the green arrow down there!
Thanks, I'll look into both of those.
Been playing since 1.2_02!