Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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 by Laike_Endaril

  • Author

Thanks a lot for your response. I'll definitely be taking a look at your library sometime soon. 

@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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.