Posted December 21, 20213 yr 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 December 21, 20213 yr by ocome
December 21, 20213 yr you need to register the SoundEvent via DeferredRegister or via RegistryEvent Edited December 21, 20213 yr by Luis_ST
December 21, 20213 yr 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")); } }
December 21, 20213 yr Author After some research, I found that using DeferredRegister is the best choice for now. I'll give it a try.
December 21, 20213 yr Author I'm busy so I'll fill in the solution later, but it's solved. Thanks Luis_ST
December 25, 20213 yr 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.