Posted March 12, 20196 yr Hi, I'm trying to work with the PlaySoundAtEntityEvent to catch a certain sound being made. Then I want to get the entity that made this sound. This is what the piece of code looks like: @SubscribeEvent public void playSound(PlaySoundAtEntityEvent evt) { if (evt.getEntity() instanceof EntityPig && evt.getSound() == SoundEvents.ENTITY_PIG_AMBIENT) { evt.getEntity().getEntityId(); } } The problem is that it never finds anything. I've even gone as far to check for if (evt.getEntity() != null) but even this never yields any result. Only if (evt.getEntity() == null) actually triggers, but I don't understand why this is the case. I'd very much appreciate a solution to getting the entity that makes a certain sound.
March 12, 20196 yr I've actually been looking into the same thing for a server-side system, but unfortunately the existing systems don't track the entity that made the sound (except for one circumstance which only ever allows for instances of EntityPlayer to be tracked). In Entity.java: public void playSound(SoundEvent soundIn, float volume, float pitch) { if (!this.isSilent()) { this.world.playSound((EntityPlayer)null, this.posX, this.posY, this.posZ, soundIn, this.getSoundCategory(), volume, pitch); } } Edit: I've just finished implementing a workaround in my library; custom event which actually includes the entity the sound came from. When I finish the current version of the library I'll post a link in case you decide to use it. Edited March 13, 20196 yr by Laike_Endaril
March 13, 20196 yr https://minecraft.curseforge.com/projects/fantastic-lib/files/2686512 The world events mentioned in the changelog there include a few for sounds. The event you'd want from the library is DSoundEvent Feel free to ping me if you decide to use it and find an issue / need more information
March 14, 20196 yr Author Thanks a lot for your response. I'll definitely be taking a look at your library sometime soon.
March 16, 20196 yr @Fusseel Not sure if you already tried it or not, but I just got around to doing more testing and it seems the trigger I based my DSoundEvent on doesn't catch all sound events. I need to do more R&D. To be more specific, I noticed it not catching block breaking sounds from myself while in single player mode. I haven't gotten to do much testing yet. In any case, the current version of DSoundEvent is not a catch-all, unfortunately
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.