mojira.dev
MC-219293

When teleporting via Chorus Fruit, the burping and teleporting sounds play at the wrong location

The Bug

When finishing eating a Chorus Fruit, the burping and teleporting sounds are played at the wrong location.

Expected Result

The sound should play at the location the player is teleported to.

Observed Result

The sound plays at the location the player is teleported from.

How to reproduce

  1. Eat Chorus Fruit

  2. Listen closely to it.

Code analysis

Code analysis by @unknown can be found in this comment.

Linked issues

Attachments

Comments 8

It plays in the spot where you get teleported away from. You can test it by flying over the void for example in the end.

I can confirm that this is an issue though no elytra is needed to reproduce this. After eating chorus fruit, the burp sound will play at the position you teleported from and not the position you were teleported to. Also affects 1.17.1.

Can confirm in 1.18.1. Please note that this same concept can also be seen with the "Player teleports" (minecraft:item.chorus_fruit.teleport) sound as well as isn't exclusive to the "burp" sound.

Here's a code analysis of this issue. The following is based on a decompiled version of Minecraft 1.18.1 using MCP-Reborn. Please note that I'm quite tentative about this analysis, although I'm persuaded to believe that this is likely the cause of the problem. This ticket also relates to MC-94481.

Code Analysis (tentative):

net.minecraft.world.level.item.ChorusFruitItem.java

public class ChorusFruitItem extends Item {
   ...
   public ItemStack finishUsingItem(ItemStack $is, Level $l, LivingEntity $le) {
      ItemStack itemstack = super.finishUsingItem($is, $l, $le);
      if (!$l.isClientSide) {
         double d0 = $le.getX();
         double d1 = $le.getY();
         double d2 = $le.getZ();

         for(int i = 0; i < 16; ++i) {
            double d3 = $le.getX() + ($le.getRandom().nextDouble() - 0.5D) * 16.0D;
            double d4 = Mth.clamp($le.getY() + (double)($le.getRandom().nextInt(16) - 8), (double)$l.getMinBuildHeight(), (double)($l.getMinBuildHeight() + ((ServerLevel)$l).getLogicalHeight() - 1));
            double d5 = $le.getZ() + ($le.getRandom().nextDouble() - 0.5D) * 16.0D;
            if ($le.isPassenger()) {
               $le.stopRiding();
            }

            if ($le.randomTeleport(d3, d4, d5, true)) {
               SoundEvent soundevent = $le instanceof Fox ? SoundEvents.FOX_TELEPORT : SoundEvents.CHORUS_FRUIT_TELEPORT;
               $l.playSound((Player)null, d0, d1, d2, soundevent, SoundSource.PLAYERS, 1.0F, 1.0F);
               $le.playSound(soundevent, 1.0F, 1.0F);
               break;
            }
         }

         if ($le instanceof Player) {
            ((Player)$le).getCooldowns().addCooldown(this, 20);
         }
      }

      return itemstack;
   }
}

If we look at the above class, we can see that the CHORUS_FRUIT_TELEPORT sound always plays at the player's position. This is evident through the following line of code:

$l.playSound((Player)null, d0, d1, d2, soundevent, SoundSource.PLAYERS, 1.0F, 1.0F);

The result of this problem is that the game plays the CHORUS_FRUIT_TELEPORT sound only after the player has teleported, resulting in the sound being produced at the position where they were teleported to, and not from. This same concept also applies to the PLAYER_BURP sound.

Can confirm in 1.19.2.

Confirmed for 1.20.2.

As for the code analysis, in the highlighted line, just replace d0, d1, and d2 with d3, d4, and d5 respectively and this issue is fixed (at least, the teleport sound).

messyez

Fantastime

Confirmed

Sound

1.16.5, 1.17.1, 1.18.1, 22w05a, 22w18a, 1.19.2, 1.19.4, 23w14a, 1.20.1, 1.20.2

23w44a

Retrieved