Ding

Ding

31M Downloads

Ding is unable to access sounds from other mods when those mods register them using RegistryEvent

TheNathanSpace opened this issue · 1 comments

commented

I've been trying to get Ding to play a sound from a mod I'm making. However, I keep getting the error Could not find sound: mymod:mysound.

I've done some digging around, and I figured out the problem.

Here's how Ding currently gets and plays the sounds:

SoundEvent useRegistered = (SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("mymod:mysound"));
Minecraft.getInstance().getSoundHandler().play(SimpleSound.master(useRegistered, 1));

It's trying to get the registered object. However, this doesn't work for mod sounds—it always throws this error message. (I know you haven't updated GitHub with the latest versions of Ding, but it's still pretty much the same)

I tried having Ding re-create the sound reference whenever it needs to play it, and it seems to do the trick. Here's how it works:

SoundEvent recreate = new SoundEvent(new ResourceLocation("mymod:mysound"));
Minecraft.getInstance().getSoundHandler().play(SimpleSound.master(recreate, 1));

Obviously you'd have to change that up to work with the Ding config file, but from my testing this fixes the problem I outlined above.

Here's a gist of Ding.java for the 1.15.2 with my changes.

Edit after some more testing

Alright, I've done some more digging around. It looks like Ding only has this problem when the sounds are registered using Events, as described here. When using DeferredRegister (seen here), it works fine. I guess the problem was sorta on my end, after all.

For anyone else who has trouble with this, here's an example of how you register using DeferredRegister (at least in 1.15).

I think it would be good for you to add something about this to the mod page on CurseForge so others don't have to figure it out like I did! I love the mod.

commented

Wait, wasn't this fixed in 1.2.0? It's behind a config that's disabled by default.