Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (โ‹ฎ) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

  • Author
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.

a SoundInstance (in 1.16.5 the class is calledย ISound) tells minecraft how to play the Sound, it contains the position, the delay, the volume, ...
you can look at the vanilla implementations of the interface for examples/ possible values you could use

  • Author

Ok, so, that's really helpful. I guess i need to learn how to make a custom sound instance for my sound.

  • Author

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions โ†’ Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.