Posted November 26, 20213 yr 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.
November 26, 20213 yr 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 November 26, 20213 yr by llynxfyre To provide more info on the help I need.
November 27, 20213 yr Author 10 hours ago, Luis_ST said: a SoundInstance Is it ok if i ask what that is?
November 27, 20213 yr 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
November 28, 20213 yr Author Ok, so, that's really helpful. I guess i need to learn how to make a custom sound instance for my sound.
November 29, 20213 yr 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 November 29, 20213 yr 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.