Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Help with event.setResultSound()


llynxfyre
 Share

Recommended Posts

Hi,

I'm quite new to modding and I'm trying to use event.setResultSound to play some custom music under certain conditions in place of music.game. All the examples I've seen of this being used involve a variable or something called ISound. I'm not sure what it is and my ide doesn't recognize it as being a part of forge or minecraft. How do I use this method? Is it even appropriate for what i wish to do? Like i said before, I'm very new to modding and an explanation would be super helpful for my learning process.

Link to comment
Share on other sites

3 hours ago, Luis_ST said:

you need to subscribe to a SoundEvent

 

	@SubscribeEvent
	public static void whenGameMusicPlays(final PlaySoundEvent event) {
		if (event.getName().equals("music.game")) {
			event.setResultSound(null);
		}

this is the code that i have so far. I'm essentially looking for what i need to put in the field that currently says null. Can I put the sound event i made in there?

Edited by llynxfyre
To provide more info on the help I need.
Link to comment
Share on other sites

Alright, I did what i wanted to do with my code, thank you so much for you patience with helping me. i just thought i'd post the code i wrote in case other people go looking for the same answers i was

		if (event.getName().equals("music.game")) { 
			ResourceLocation loc = new ResourceLocation(CaveMusic.MODID + ":" + "music.overworld.underground");
			SimpleSoundInstance MyPSR = new SimpleSoundInstance(
				loc, SoundSource.MUSIC, 1.0f, 1.0f, false, 0, SoundInstance.Attenuation.NONE, 0.0D, 0.0D, 0.0D, true); 
			event.setResultSound(MyPSR);
			
		}

 

Edited by llynxfyre
by the way this code is for 1.17.1 forge
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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.