Jump to content

[1.19] Registering Sounds


Luckydel

Recommended Posts

Hello, sorry to disturb you. I can't hear the sound in the game.
I tried to register.

@Mod(Main.MODID)
public class Main
{   
	public static final String MODID = "mymod";
    public Main() {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
        ForgeModSounds.REGISTRY.register(modEventBus);
    }
}
@Mod.EventBusSubscriber(modid = Main.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ForgeModSounds {
    public static final DeferredRegister<SoundEvent> REGISTRY = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, Main.MODID);
    public static final RegistryObject<SoundEvent> empty = REGISTRY.register("empty",
            () -> new SoundEvent(new ResourceLocation(Main.MODID, "empty")));
}

 

I use in Range item.
 

public static BulletEntity shoot(Level world, LivingEntity entity, float power, double damage, int knockback, String soundName) {
		...
        world.playSound(null, entity.getX(), entity.getY(), entity.getZ(),
                ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(Main.MODID, "empty")), SoundSource.PLAYERS, 1, 1.0F / 		  		     (world.getRandom().nextFloat() * 0.4F + 1.2F) * 0.5F);

		//OR


        //world.playSound(null, entity.getX(), entity.getY(), entity.getZ(),
        //        ForgeModSounds.empty.get(), SoundSource.PLAYERS, 1, 1.0F / (world.getRandom().nextFloat() * 0.4F + 1.2F) * 0.5F);
        //return entitybullet;
    }

assets/mymod/sounds.json

{
  "empty": {
    "category": "neutral",
    "sounds": [
      {
        "name": "warmod_perekur:empty",
        "stream": false
      }
    ]
  }
}


assets/mymod/sounds/empty.ogg

 

Edited by Luckydel
Link to comment
Share on other sites

It's difficult to say since you only post source snippets without context.

Whether your configuration is correct (e.g. typos or files in the wrong place in the filesystem), only you will know since you don't show what it really is, including you modifying it before posting.

 

Passing null as the player (first parameter) is intended for broadcasting to all players in range of the sound, it only works on the server.

On the client you need to pass in the player and it must match Minecraft.getInstance().player otherwise the sound won't play.

 

As a test, try replacing your sound with a vanilla one, e.g. SoundEvents.ARROW_SHOOT

If that works, you know the problem is with your sound config or the sound itself.

If it doesn't work, you know the problem is with the logic/parameters of the method call. Debuggers are your friend. 🙂 

 

Finally, whenever you have something that is not working as expected look at your run/logs/debug.log and look for errors/warnings.

You should post a link to it here as well if you don't understand what it is telling you, or maybe we can spot something you didn't notice.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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.