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

Alright... I'm fairly new to the modding community but I need some help with something...

 

I was able to make a custom ender pearl, which is supposed to play a sound to all entities near the impact upon colliding with either a block or a player. Now, it does play the sound; that isn't my issue. The problem is if I teleport too far with my custom pearl, the sound doesn't play at all. I tested with a LAN world, but it didn't even play for the second player.

 

I tested the distance at which the sound would cut out, and it turned out to be 17 blocks.

 

My Ender Pearl's code is quite similar to that of the in-game ender pearl, but I will copy paste some of the code anyways. The class is extending entityEnderPearl, so feel free to check that class out if you need any more.

 

This is the section that triggers on the projectiles impact. I am aware that the line where the sound gets trigger is below where the section where the particles are triggered, but I have moved this line of code around and it doesn't make a difference.

 

 

[embed=425,349]@Override

protected void onImpact(MovingObjectPosition p_70184_1_)

    {

        if (p_70184_1_.entityHit != null)

        {

            p_70184_1_.entityHit.setFire(10);;

           

        }

 

        for (int i = 0; i < 32; ++i)

        {

       

            this.worldObj.spawnParticle("lava", this.posX, this.posY + this.rand.nextDouble() * 2.0D, this.posZ, this.rand.nextGaussian(), 0.0D, this.rand.nextGaussian());

           

        }

 

        if (!this.worldObj.isRemote)

        {

            if (this.getThrower() != null && this.getThrower() instanceof EntityPlayerMP)

            {

                EntityPlayerMP entityplayermp = (EntityPlayerMP)this.getThrower();

 

                if (entityplayermp.playerNetServerHandler.func_147362_b().isChannelOpen() && entityplayermp.worldObj == this.worldObj)

                {

               

                    EnderTeleportEvent event = new EnderTeleportEvent(entityplayermp, this.posX, this.posY, this.posZ, 5.0F);

                    this.worldObj.playSoundEffect(posX, posY, posX, "MyMod:teleportfwoop", 0.75F, 0.95F);

                    if (!MinecraftForge.EVENT_BUS.post(event))

                    { // Don't indent to lower patch size

                    if (this.getThrower().isRiding())

                    {

                        this.getThrower().mountEntity((Entity)null);

                    }

 

                    this.getThrower().setPositionAndUpdate(event.targetX, event.targetY, event.targetZ);

                    this.getThrower().fallDistance = 0.0F;

                   

                    }

                }

            }

 

            this.setDead();

        }

    }[/embed]

 

If anyone could help with this, or tell me a better way to call the sound, please let me know.

 

-Wekio

The volume you play the sound at using

World#playSoundEffect

determines how far around the position the sound can be heard. If you look at

WorldManager#playSound

(the server-side

IWorldAccess

implementation called by

World#playSoundEffect

), you'll see that the

S29PacketSoundEffect

(the packet that plays the sound on the client) is sent to all players in a radius of

16 * volume

blocks around the target position (minimum radius is 16).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

Thank you, that is very helpful!

 

All my sound issues are solved!  ;D

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.