Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi there,

I've added a custom entity (called a Nils) to my 1.12.2 mod and I'm trying to override the getAmbientSound(), getHurtSound() and getDeathSound() methods in the entity's class.

 

I have multiple of each sound saved in this folder:

MODNAME\src\main\resources\assets\MODNAME\sounds\entity\nils\

 

This is my sounds.json (located in 

MODNAME\src\main\resources\assets\MODNAME\sounds\

)

 

sounds.json:

{
    "entity.nils.ambient" : {
        "category" : "entity",
        "subtitle" : "entity.nils.ambient",
        "sounds" : [
            {"name" : "MODNAME:entity/nils/ambient_0", "stream" : true},
            {"name" : "MODNAME:entity/nils/ambient_1", "stream" : true},
            {"name" : "MODNAME:entity/nils/ambient_2", "stream" : true},
            {"name" : "MODNAME:entity/nils/ambient_3", "stream" : true}
        ]
    },
    "entity.nils.hurt" : {
        "category" : "entity",
        "subtitle" : "entity.nils.hurt",
        "sounds" : [
            {"name" : "MODNAME:entity/nils/hurt_0", "stream" : true},
            {"name" : "MODNAME:entity/nils/hurt_1", "stream" : true}
        ]
    },
    "entity.nils.death" : {
        "category" : "entity",
        "subtitle" : "entity.nils.death",
        "sounds" : [
            {"name" : "MODNAME:entity/nils/death_0", "stream" : true},
            {"name" : "MODNAME:entity/nils/death_1", "stream" : true},
            {"name" : "MODNAME:entity/nils/death_2", "stream" : true},
            {"name" : "MODNAME:entity/nils/death_3", "stream" : true}
        ]
    }
}

 

I have also tried replacing each dictionary element in "sounds" to just the name. ie. 

        "sounds" : [
            "MODNAME:entity/nils/hurt_0",
            "MODNAME:entity/nils/hurt_1"
         ]

 

The method overrides are just simple two-liners, all like this:

int index = (new Random()).nextInt(SoundsHandler.ENTITY_NILS_AMBIENT.size());
return SoundsHandler.ENTITY_NILS_AMBIENT.get(index);

(but obviously replacing ..._AMBIENT with ..._HURT and ..._DEATH for the other events).

 

The class SoundsHandler looks like this:

package mod.loizouca.MODNAME.util.handlers;

import java.util.ArrayList;
import java.util.List;

import mod.loizouca.MODNAME.util.Reference;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;

public class SoundsHandler {
	public static final int NUM_AMBIENT = 4, NUM_HURT = 2, NUM_DEATH = 4;
	public static List<SoundEvent> ENTITY_NILS_AMBIENT = new ArrayList<SoundEvent>();
	public static List<SoundEvent> ENTITY_NILS_HURT = new ArrayList<SoundEvent>();
	public static List<SoundEvent> ENTITY_NILS_DEATH = new ArrayList<SoundEvent>();
	
	public static void registerSounds() {
		for (int i=0; i<NUM_AMBIENT; i++) ENTITY_NILS_AMBIENT.add(registerSound("entity/nils/ambient_"+Integer.toString(i)));
		for (int i=0; i<NUM_HURT; i++) ENTITY_NILS_HURT.add(registerSound("entity/nils/hurt_"+Integer.toString(i)));
		for (int i=0; i<NUM_DEATH; i++) ENTITY_NILS_DEATH.add(registerSound("entity/nils/death_"+Integer.toString(i)));
	}
	
	private static SoundEvent registerSound(String name) {
		ResourceLocation location = new ResourceLocation(Reference.MOD_ID, name);
		SoundEvent event = new SoundEvent(location);
		event.setRegistryName(name);
		ForgeRegistries.SOUND_EVENTS.register(event);
		return event;
	}	
}

 

My problem is that after the game has loaded and I'm in the world (no problems thus far), the sounds don't work.I just get these errors in the Eclipse console:

[main/WARN] [minecraft/SoundManager]: Unable to play unknown soundEvent: MODNAME:entity/nils/ambient_0

This happens for every event (ambient, hurt and death) and for all the different files.

I'm aware that it is probably to do with where the files are, but I have changed their locations, I have changed the path I parse into registerSound(), and nothing has worked. If I leave it to super off the Entity I have inherited from, the sounds work (I get the cow moo, hurt and death sounds).

 

Please let me know if you need any more information / code / etc. and thanks in advance for any help :). This has been bugging me for days now.

 

(PS. I have replaced my mod's name with MODNAME in all the paths, so my code actually has a name there, not just a placeholder).

Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.