Jump to content

[SOLVED] [1.12] Registered SoundEvent not playing without error


IceMetalPunk

Recommended Posts

I'm just trying to get a sound to play, but it's not. It's not playing anything, but there are no errors or warnings logged. For the filenames below, my mod ID is redplusplus.

I have a sounds.json file in my assets/redplusplus folder with this in it:

 

{
	"redplusplus:item.redstone_sandwich.eat": {
		"sounds": [
			"redplusplus:item/redstone_sandwich/eat"
		]
	}
}

 

I've also tried leaving out the redplusplus domain from the sound location, but it didn't help. (And of course, if I leave the redplusplus domain out of the sound name itself, I get an "unable to play empty sound" error, so I think it's necessary, yes?)

I have a class which extends SoundEvent for easier registration, which just sets the registry name upon initialization:

 

package com.icemetalpunk.redplusplus.sounds;

import com.icemetalpunk.redplusplus.RedPlusPlus;

import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

public abstract class RedPlusPlusSound extends SoundEvent {
	public RedPlusPlusSound(String name) {
		super(new ResourceLocation(RedPlusPlus.MODID, name));
		this.setRegistryName(new ResourceLocation(RedPlusPlus.MODID, name));
	}

	public void register() {
		GameRegistry.findRegistry(SoundEvent.class).register(this);
	}
}

 

And then my sound group classes extend RedPlusPlusSound, taking in a specific name within the group; for instance, I have this class for the sounds related to eating "redstone sandwiches" (an item in my mod):

 

package com.icemetalpunk.redplusplus.sounds;

public class SoundRedstoneSandwich extends RedPlusPlusSound {

	public SoundRedstoneSandwich(String subset) {
		super("item.redstone_sandwich." + subset);
	}

}

So I can have item.redstone_sandwich.eat, and in the future (when this is working), item.redstone_sandwich.super, etc. all be instances of the same class.

And then I actually just call these instances' register() methods (defined in the parent RedPlusPlusSound class above) in a handler for the RegistryEvent<SoundEvent> event type.

I do have the file assets/redplusplus/sounds/item/redstone_sandwich/eat.ogg which is a non-empty sound. And when I use the /playsound command, that full resource location for my sound does properly auto-complete, so it's definitely registering something with that name.

 

So what would cause the sound not to play if there's no indication of any errors?

Edited by IceMetalPunk
Added Solved Tag

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

Minecraft automatically uses your mod ID as the domain for the top-level sound event names in sounds.json, don't specify it yourself.

 

Change redplusplus:item.redstone_sandwich.eat to item.redstone_sandwich.eat in your sounds.json file.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

11 minutes ago, Choonster said:

Minecraft automatically uses your mod ID as the domain for the top-level sound event names in sounds.json, don't specify it yourself.

 

Change redplusplus:item.redstone_sandwich.eat to item.redstone_sandwich.eat in your sounds.json file.

As I said, that's what I tried originally, and not only did the sound not play, but I got an error logged when trying to play the sound that it was an "empty sound". That's why I added the domain, and the error disappeared...

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

Sorry, I missed that.

 

This is very odd, including your mod ID in the sounds.json event name should result in a Sound being registered for the ResourceLocation with <modid> as the domain and <modid>:<name> as the path.

 

Could you post a Git repository of your mod? I'd like to see if I can reproduce and debug this locally.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Never mind, it works now >_< Originally, I didn't have the domain on either the sound name or the resource location. That's when it was giving me the "empty sound event" error. Then I added it to the sound name, which removed that error, so I thought I was going in the right direction and added it to the resource location. Obviously, still no luck.

Turns out the domain is required in the resource location, but cannot be in the sound name. Because with that combination, it works just fine. Go figure.

Now I know! Thank you for your help! :D

Whatever Minecraft needs, it is most likely not yet another tool tier.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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