Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Registering custom sound


Tonyenike
 Share

Recommended Posts

Sound file is registered, but when I use the /playsound command, no sound is playing.

 

ModSounds.java:

@Mod.EventBusSubscriber(modid = ExampleMod.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
@ObjectHolder(ExampleMod.MODID)
public class ModSounds {

	public static SoundEvent epic_music;
	

    
    /**
     * The actual event handler that registers the custom items.
     *
     * @param event The event this event handler handles
     */
	@SubscribeEvent
	public static void registerSounds(RegistryEvent.Register<SoundEvent> event){
		ResourceLocation yeet = new ResourceLocation(ExampleMod.MODID, "epic_music");
	    epic_music  = new SoundEvent(yeet).setRegistryName(yeet);
		final SoundEvent[] soundEvents = {
				epic_music
		};
		event.getRegistry().registerAll(soundEvents);
	}

}

the sounds.json file is in src/main/resources/assets/examplemod/sounds.json

{
  "epic_music": {
    "category": "master",
    "sounds": [
      {
        "name": "examplemod:epic_music",
        "stream": true
      }
    ]
  }
}

 

The sound file is called epic_music.ogg and is in src/main/resources/assets/examplemod/sounds/epic_music.ogg

The epic_music.ogg file is a 9.5 minute speech file.

 

ExampleMod.java

@Mod("examplemod")
public class ExampleMod
{

    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();
	public static final String MODID = "examplemod";

    public ExampleMod() {

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }


    // You can use SubscribeEvent and let the Event Bus discover methods to call
    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        // do something when the server starts
        LOGGER.info("HELLO from server starting");
    }
    
}

 

The game recognizes the examplemod:epic_music sound when I go to enter the /playsound command, but no sound is playing

 

 

Link to comment
Share on other sites

  • 1 month later...
On 1/9/2020 at 2:54 AM, Tonyenike said:

Sound file is registered, but when I use the /playsound command, no sound is playing.

 

ModSounds.java:


@Mod.EventBusSubscriber(modid = ExampleMod.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
@ObjectHolder(ExampleMod.MODID)
public class ModSounds {

	public static SoundEvent epic_music;
	

    
    /**
     * The actual event handler that registers the custom items.
     *
     * @param event The event this event handler handles
     */
	@SubscribeEvent
	public static void registerSounds(RegistryEvent.Register<SoundEvent> event){
		ResourceLocation yeet = new ResourceLocation(ExampleMod.MODID, "epic_music");
	    epic_music  = new SoundEvent(yeet).setRegistryName(yeet);
		final SoundEvent[] soundEvents = {
				epic_music
		};
		event.getRegistry().registerAll(soundEvents);
	}

}

the sounds.json file is in src/main/resources/assets/examplemod/sounds.json


{
  "epic_music": {
    "category": "master",
    "sounds": [
      {
        "name": "examplemod:epic_music",
        "stream": true
      }
    ]
  }
}

 

The sound file is called epic_music.ogg and is in src/main/resources/assets/examplemod/sounds/epic_music.ogg

The epic_music.ogg file is a 9.5 minute speech file.

 

ExampleMod.java


@Mod("examplemod")
public class ExampleMod
{

    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();
	public static final String MODID = "examplemod";

    public ExampleMod() {

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }


    // You can use SubscribeEvent and let the Event Bus discover methods to call
    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        // do something when the server starts
        LOGGER.info("HELLO from server starting");
    }
    
}

 

The game recognizes the examplemod:epic_music sound when I go to enter the /playsound command, but no sound is playing

 

 

Dont use static reference and try to use DeferredRegister, it should to be able to register Sounds.

https://mcforge.readthedocs.io/en/latest/effects/sounds/#playing-sounds

Edited by DragonITA

New in Modding? == Still learning!

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

 Share



×
×
  • Create New...

Important Information

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