Posted June 15, 20169 yr 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); } }
June 15, 20169 yr Author 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...
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.