mojira.dev
MC-112133

Eating chorus fruit does not reset fall distance

The bug

Unlike ender pearls chorus fruits do not reset the fall distance and therefor the fall damage is applied after you were teleported.

How to reproduce

  1. Teleport yourself multiple hundreds of blocks in the air

  2. While falling eat a chorus fruit

Related issues

Attachments

Comments

migrated
[media][media][media]
migrated

Confirmed for 1.13.1.

gaspoweredpick

Confirmed for 19w14b

migrated

Confirmed for 1.15.2

pulpetti

Still in 1.16.1 and 20w29a

j_p_smith

Related to MC-109060 - same issue, but the teleportation method is different.

Avoma

Can confirm in 21w03a.

Avoma

Can confirm in 21w05b.

Avoma

Can confirm in 21w06a.

Avoma

Can confirm in 21w17a.

Avoma

I can confirm this in 1.18.1. Here's a code analysis of this issue. 🙂

Code Analysis:

The following is based on a decompiled version of Minecraft 1.19.2 using MCP-Reborn.

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

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

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

            Vec3 vec3 = livingEntity.position();
            if (livingEntity.randomTeleport(d3, d4, d5, true)) {
               level.gameEvent(GameEvent.TELEPORT, vec3, GameEvent.Context.of(livingEntity));
               SoundEvent soundevent = livingEntity instanceof Fox ? SoundEvents.FOX_TELEPORT : SoundEvents.CHORUS_FRUIT_TELEPORT;
               level.playSound((Player)null, d0, d1, d2, soundevent, SoundSource.PLAYERS, 1.0F, 1.0F);
               livingEntity.playSound(soundevent, 1.0F, 1.0F);
               livingEntity.resetFallDistance();
               break;
            }
         }

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

      return itemstack;
   }
   ...

If we look at the above class, we can see that the resetFallDistance() method is never called throughout this piece of code, therefore resulting in your fall distance not being reset upon eating chorus fruit.

Fix:

Simply calling the resetFallDistance() method where appropriate within this piece of code will resolve this problem. The following line of code can be used to fix this:

livingEntity.resetFallDistance();
Avoma

Can confirm in 1.18.2.

Avoma

I can confirm this behavior in 1.19.2.

Following on from my code analysis, I've double-checked my proposed fix and I can confidently confirm that it's fully functioning and works as expected, so I've attached two screenshots to this report, one of which shows the current code and the other that shows the fixed code. I feel this information may be quite insightful hence my reasoning for providing it. 🙂

[media][media]

marcono1234

Timur Nazarov

Confirmed

Normal

Player

chorus_fruit, distance-fallen, fall-damage

Minecraft 1.11.2, Minecraft 1.12.1, Minecraft 1.12.2 Pre-Release 1, Minecraft 1.12.2 Pre-Release 2, Minecraft 1.13.1, ..., 1.19.2, 1.19.4, 1.20 Pre-release 1, 1.20.1, 23w32a

23w33a

Retrieved