Jump to content

[1.9.4] Problem playing sound when player dies


American2050

Recommended Posts

I'm having problems playing a sound when the player dies.

 

The sound is registered correctly, the event is registered correctly and getting fired, but for some reason, the sound wont play.

 

I'm not sure what the problem could be here.

 

	@SubscribeEvent
  public void onPlayerDie(PlayerDropsEvent event) {

	World world = event.getEntity().getEntityWorld();
	EntityPlayer player = event.getEntityPlayer();
	BlockPos pos = player.getPosition();

	world.playSound(player, pos, ModSounds.PLAYER_DEAD, SoundCategory.BLOCKS, 1.0F, 1.0F);


}

 

I tried the sound firing in on other events and it works ok, but inside the PlayerDropsEvent it wont do anything.

 

PS: Also tried this, with no success

 

	@SubscribeEvent
  public void onPlayerDie(LivingDeathEvent event) {

	Entity entity = event.getEntity();

	if(entity instanceof EntityPlayer){			

		World world = event.getEntity().getEntityWorld();
		BlockPos pos = entity.getPosition();

	world.playSound((EntityPlayer)entity, pos, ModSounds.PLAYER_DEAD, SoundCategory.BLOCKS, 1.0F, 1.0F);

	}


}

Link to comment
Share on other sites

Thanks a lot man, it's working perfectly now.

 

Now my question is... Why it's wrong to track when a player dies using the PlayerDropsEvent?

 

Isn't it better to subscribe to an event that will triggers only when a player dies, and not use LivingDeathEvent that gets triggered every time something dies in the game?

 

In my head it makes sense using PlayerDropsEvent better over LivingDeathEvent but dunno...

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.