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

It is possible to play sounds in playsound, but no sound is played from the Mob

 

TutorialZombie

    protected SoundEvent getAmbientSound() {
        return ModSoundEvents.TUTORIALSOUND;
    }

    protected SoundEvent getHurtSound(DamageSource p_34327_) {
        return ModSoundEvents.TUTORIALSOUND;
    }

    protected SoundEvent getDeathSound() {
        return ModSoundEvents.TUTORIALSOUND;
    }

    protected SoundEvent getStepSound() {
        return ModSoundEvents.TUTORIALSOUND;
    }

ModSoundEvents.java

@Mod.EventBusSubscriber(modid = TutorialMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModSoundEvents {
    public static final SoundEvent TUTORIALSOUND= new SoundEvent(new ResourceLocation("entity.tutorial_sound"));
    }

 

resources/assets/sounds.json

{
  "tutorial_sound": {
    "category": "tutorialmod:tutorial",
    "subtitle": "tutorialmod:tutorial_sound",
    "sounds": [
      {
        "name": "tutorialmod:tutorial_sound",
        "stream": true
      }
    ]
  }
}

resources/assets/tutorialmod/sounds

tutorial_sound.ogg

 

No particular kind of error occurs.
It's just silent.

Thank you in advance.

Edited by ocome

you need to register the SoundEvent via DeferredRegister or via RegistryEvent

Edited by Luis_ST

  • Author
1 hour ago, Luis_ST said:

you need to register the SoundEvent via DeferredRegister or via RegistryEvent

I added the blocks by referring to the code to add them, but it didn't work very well.

Is there anything else that needs to be done?

ModSoundEvents

@Mod.EventBusSubscriber(modid = TutorialMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModSoundEvents {
    public static final SoundEvent TUTORIALSOUND= new SoundEvent(new ResourceLocation("tutorial_sound"));

    @SubscribeEvent
    public static void  registerSounds(RegistryEvent.Register<SoundEvent> event){
        event.getRegistry().register(TUTORIALSOUND.setRegistryName("tutorial_sound"));
    }


}
  • Author

After some research, I found that using DeferredRegister is the best choice for now. I'll give it a try.

  • Author

I'm busy so I'll fill in the solution later, but it's solved.
Thanks Luis_ST :)

  • ocome changed the title to [solved][1.18] Custom sounds don't work
  • Author

Solved Code

SoundEvents

public class ModSoundEvents {
    public static final DeferredRegister<SoundEvent> SOUNDS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, TutorialMod.MOD_ID);

    public static final RegistryObject<SoundEvent> TUTORIALSOUND=
            SOUNDS.register("tutorial_sound", () -> new SoundEvent(new ResourceLocation(TutorialMod.MOD_ID, "tutorial_sound")));

}

main

    public TutorialMod() {

        IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
        ModSoundEvents.SOUNDS.register(eventBus);
      ...........

Mob

    protected SoundEvent getStepSound() {
        return ModSoundEvents.TUTORIALSOUND.get();
    }

 

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

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.