Jump to content

[solved][1.18] Custom sounds don't work


ocome

Recommended Posts

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
Link to comment
Share on other sites

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"));
    }


}
Link to comment
Share on other sites

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

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();
    }

 

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.



×
×
  • Create New...

Important Information

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