Posted April 7, 20232 yr As the title suggests, I am trying to set (in this case override) the ambient music in the Nether with a custom song but cannot get looping to work. I have registered the .ogg file, set up correct configurations for a streamed sound in sounds.json and ensured everything is hooked up within the main mod file for the custom SoundEvent to be recognized. Which of event.setSound and play.playSound is needed? Is there a simple flag to do this or is there a more appropriate method/approach? @Mod.EventBusSubscriber(modid = FirstMod.MOD_ID) public static class ForgeEvents { @SubscribeEvent public static void onPlaySound(PlaySoundEvent event) { if (Minecraft.getInstance().player != null) { if (Minecraft.getInstance().level != null) { if (Minecraft.getInstance().level.dimension() == Level.NETHER) { LocalPlayer player = Minecraft.getInstance().player; if (!isCustomSongPlaying) { isCustomSongPlaying = true; event.setSound(SimpleSoundInstance.forLocalAmbience(ModSounds.CUSTOM_SONG.get(), 1.0f, 1.0f)); player.playSound(ModSounds.CUSTOM_SONG.get(), 1.0f, 1.0f); } } else { isCustomSongPlaying = false; } } } } } Edited April 7, 20232 yr by Gedeon Sound working but not looping like with vanilla music.
April 8, 20232 yr Unfortunately, there's no easy method to do this. However, your logic would indicate that it's impossible for the sound to loop as it assumes the custom sound is play for as long as the player is in the nether. You are better to check whether the SoundManager finds the current sound instance active (via SoundManager#isActive). You will need to hold a current instance of the SoundInstance being played.
April 9, 20232 yr Author 9 hours ago, ChampionAsh5357 said: Unfortunately, there's no easy method to do this. However, your logic would indicate that it's impossible for the sound to loop as it assumes the custom sound is play for as long as the player is in the nether. You are better to check whether the SoundManager finds the current sound instance active (via SoundManager#isActive). You will need to hold a current instance of the SoundInstance being played. Thank you for the feedback. Is another event subscription needed (onTick or other) to periodically call the isActive method? Could you please elaborate some more on your recommendation for a current instance of SoundInstance? Does this tie into the current subscription I have to PlaySoundEvent or something else?
April 9, 20232 yr 14 minutes ago, Gedeon said: Is another event subscription needed (onTick or other) to periodically call the isActive method? Yep, probably ClientTickEvent 14 minutes ago, Gedeon said: Could you please elaborate some more on your recommendation for a current instance of SoundInstance? Does this tie into the current subscription I have to PlaySoundEvent or something else? See how MusicManager works since this is essentially what you are trying to design.
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.