Jump to content

[1.9] How to create & register a sound using the new registry system? [Solved]


HyperHamster

Recommended Posts

I tried that also, it still doesn't play my sounds

Json

{
  "entity.terrakon.bark": {"category": "neutral", "sounds": ["tetracraft:entity/terrakon/bark1", "tetracraft:entity/terrakon/bark2", "tetracraft:entity/terrakon/bark3"]},
  "entity.terrakon.growl": {"category": "neutral", "sounds": ["tetracraft:entity/terrakon/growl1", "tetracraft:entity/terrakon/growl2", "tetracraft:entity/terrakon/growl3"]},
  "entity.terrakon.hurt": {"category": "neutral", "sounds": ["tetracraft:entity/terrakon/hurt1", "tetracraft:entity/terrakon/hurt2", "tetracraft:entity/terrakon/hurt3"]},
  "entity.terrakon.pant": {"category": "neutral", "sounds": ["tetracraft:entity/terrakon/panting"]},
  "entity.terrakon.whine": {"category": "neutral", "sounds": ["tetracraft:entity/terrakon/whine"]},
  "entity.terrakon.death": {"category": "neutral", "sounds": ["tetracraft:entity/terrakon/death"]}
}

 

ModFile

package novaviper.tetracraft.common.lib;

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

/**
* @author NovaViper (Based on Choonster's code)
* Class Purpose: Registers this mod's {@link SoundEvent}s.
*/
@SuppressWarnings("WeakerAccess")
public class ModSoundEvents {

// Terrakon Sounds\\
public static SoundEvent terrakonBark;
public static SoundEvent terrakonGrowl;
public static SoundEvent terrakonHurt;
public static SoundEvent terrakonPanting;
public static SoundEvent terrakonWhine;
public static SoundEvent terrakonDeath;

/**
 * Register the {@link SoundEvent}s.
 */
public static void registerSounds() {
	terrakonBark = Registers.registerSound("entity.terrakon.bark");
	terrakonGrowl = Registers.registerSound("entity.terrakon.growl");
	terrakonHurt = Registers.registerSound("entity.terrakon.hurt");
	terrakonPanting = Registers.registerSound("entity.terrakon.pant");
	terrakonWhine = Registers.registerSound("entity.terrakon.whine");
	terrakonDeath = Registers.registerSound("entity.terrakon.death");
}
}

 

Registry

	/**
 * Register a {@link SoundEvent}.
 *
 * @param soundName The SoundEvent's name without the testmod3 prefix
 * @return The SoundEvent
 */
public static SoundEvent registerSound(String soundName) {
	final ResourceLocation soundID = new ResourceLocation(ModReference.modid, soundName);
	return GameRegistry.register(new SoundEvent(soundID).setRegistryName(soundID));
}

 

Entity

	@Override
protected SoundEvent getHurtSound() {
	return ModSoundEvents.terrakonHurt;
}

@Override
protected void playStepSound(BlockPos pos, Block blockIn) {
	playSound(SoundEvents.entity_wolf_step, 1.0f, 1.0f);
}

@Override
protected SoundEvent getDeathSound() {
	return ModSoundEvents.terrakonDeath;
}

@Override
protected SoundEvent getAmbientSound() {
	// if(!this.inFinalStage()){
	return isAngry() ? ModSoundEvents.terrakonGrowl : rand.nextInt(3) == 0
			? isTamed() && getHealth() <= Constants.lowHP ? ModSoundEvents.terrakonWhine
			: ModSoundEvents.terrakonPanting : ModSoundEvents.terrakonBark;
	/* }else{ return Sound.; } */
}

 

Your

sounds.json

and registering code looks correct as they are here.

 

My experience is that when you try to play a sound using the SoundEvent object returned from the registering method, it just doesn't work. I had to retrieve the SoundEvent directly from the registry using something like this (adapted for your mod):

playSound(entityName, entityName.getPosition(), SoundEvent.soundEventRegistry.getObject(new ResourceLocation(ModReference.modid, "entity.terrakon.bark")), SoundCategory.NEUTRAL, 1.0F, 1.0F);

 

Edit: Well nevermind then, I'm glad you got it working. I unfortunately have no clue how to implement sound subtitles as of yet.

Link to comment
Share on other sites

I tried that also, it still doesn't play my sounds

Json

{
  "entity.terrakon.bark": {"category": "neutral", "sounds": ["tetracraft:entity/terrakon/bark1", "tetracraft:entity/terrakon/bark2", "tetracraft:entity/terrakon/bark3"]},
  "entity.terrakon.growl": {"category": "neutral", "sounds": ["tetracraft:entity/terrakon/growl1", "tetracraft:entity/terrakon/growl2", "tetracraft:entity/terrakon/growl3"]},
  "entity.terrakon.hurt": {"category": "neutral", "sounds": ["tetracraft:entity/terrakon/hurt1", "tetracraft:entity/terrakon/hurt2", "tetracraft:entity/terrakon/hurt3"]},
  "entity.terrakon.pant": {"category": "neutral", "sounds": ["tetracraft:entity/terrakon/panting"]},
  "entity.terrakon.whine": {"category": "neutral", "sounds": ["tetracraft:entity/terrakon/whine"]},
  "entity.terrakon.death": {"category": "neutral", "sounds": ["tetracraft:entity/terrakon/death"]}
}

 

ModFile

package novaviper.tetracraft.common.lib;

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

/**
* @author NovaViper (Based on Choonster's code)
* Class Purpose: Registers this mod's {@link SoundEvent}s.
*/
@SuppressWarnings("WeakerAccess")
public class ModSoundEvents {

// Terrakon Sounds\\
public static SoundEvent terrakonBark;
public static SoundEvent terrakonGrowl;
public static SoundEvent terrakonHurt;
public static SoundEvent terrakonPanting;
public static SoundEvent terrakonWhine;
public static SoundEvent terrakonDeath;

/**
 * Register the {@link SoundEvent}s.
 */
public static void registerSounds() {
	terrakonBark = Registers.registerSound("entity.terrakon.bark");
	terrakonGrowl = Registers.registerSound("entity.terrakon.growl");
	terrakonHurt = Registers.registerSound("entity.terrakon.hurt");
	terrakonPanting = Registers.registerSound("entity.terrakon.pant");
	terrakonWhine = Registers.registerSound("entity.terrakon.whine");
	terrakonDeath = Registers.registerSound("entity.terrakon.death");
}
}

 

Registry

	/**
 * Register a {@link SoundEvent}.
 *
 * @param soundName The SoundEvent's name without the testmod3 prefix
 * @return The SoundEvent
 */
public static SoundEvent registerSound(String soundName) {
	final ResourceLocation soundID = new ResourceLocation(ModReference.modid, soundName);
	return GameRegistry.register(new SoundEvent(soundID).setRegistryName(soundID));
}

 

Entity

	@Override
protected SoundEvent getHurtSound() {
	return ModSoundEvents.terrakonHurt;
}

@Override
protected void playStepSound(BlockPos pos, Block blockIn) {
	playSound(SoundEvents.entity_wolf_step, 1.0f, 1.0f);
}

@Override
protected SoundEvent getDeathSound() {
	return ModSoundEvents.terrakonDeath;
}

@Override
protected SoundEvent getAmbientSound() {
	// if(!this.inFinalStage()){
	return isAngry() ? ModSoundEvents.terrakonGrowl : rand.nextInt(3) == 0
			? isTamed() && getHealth() <= Constants.lowHP ? ModSoundEvents.terrakonWhine
			: ModSoundEvents.terrakonPanting : ModSoundEvents.terrakonBark;
	/* }else{ return Sound.; } */
}

 

Your

sounds.json

and registering code looks correct as they are here.

 

My experience is that when you try to play a sound using the SoundEvent object returned from the registering method, it just doesn't work. I had to retrieve the SoundEvent directly from the registry using something like this (adapted for your mod):

playSound(entityName, entityName.getPosition(), SoundEvent.soundEventRegistry.getObject(new ResourceLocation(ModReference.modid, "entity.terrakon.bark")), SoundCategory.NEUTRAL, 1.0F, 1.0F);

 

That wasn't the reason why it didn't work, I simply forgot to put the registering method in my main class.

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Link to comment
Share on other sites

To give a sound event a subtitle, set the

"subtitle"

key of the sound event in sounds.json to a string containing the translation key. An example from the vanilla sounds.json file:

  "item.shovel.flatten": {
    "sounds": [
      "item/shovel/flatten1",
      "item/shovel/flatten2",
      "item/shovel/flatten3",
      "item/shovel/flatten4"
    ],
    "subtitle": "subtitles.item.shovel.flatten"
  },

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

To give a sound event a subtitle, set the

"subtitle"

key of the sound event in sounds.json to a string containing the translation key. An example from the vanilla sounds.json file:

  "item.shovel.flatten": {
    "sounds": [
      "item/shovel/flatten1",
      "item/shovel/flatten2",
      "item/shovel/flatten3",
      "item/shovel/flatten4"
    ],
    "subtitle": "subtitles.item.shovel.flatten"
  },

 

That worked, thanks!

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

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.