mojira.dev
MC-44936

Extending a potion effect that you already have can cause the timer to display wrongly

The bug

Normally, when getting an effect with a duration of or longer than 1639 seconds, '**:**' is displayed in the HUD. However, if the effect is applied while you already had it (but for a shorter duration), that doesn't happen instead a duration higher than 27 minutes is displayed.

Leaving and re-entering the world fixes it.

Expected behavior

'**:**' be displayed.

Actual behavior

'27:18' is displayed.

How to reproduce

  1. Use the following command

    /effect give @s minecraft:speed 10
  2. While the effect is still active, use

    /effect give @s minecraft:speed 1000000

Code analysis

The following is based on a decompiled version of Minecraft 1.9 using MCP 9.24 beta, applies to 1.12.2 as well.

The reason why this happens is because the method net.minecraft.potion.PotionEffect.combine(PotionEffect) (and others as well) are not using the value of the net.minecraft.potion.PotionEffect.isPotionDurationMax field of the other potion.

public void combine(PotionEffect other)
{
    if (this.field_188420_b != other.field_188420_b)
    {
        LOGGER.warn("This method should only be called for matching effects!");
    }

    if (other.amplifier > this.amplifier)
    {
        this.amplifier = other.amplifier;
        this.duration = other.duration;
        // Added this
        this.isPotionDurationMax = other.isPotionDurationMax;
    }
    else if (other.amplifier == this.amplifier && this.duration < other.duration)
    {
        this.duration = other.duration;
        // Added this
        this.isPotionDurationMax = other.isPotionDurationMax;
    }
    else if (!other.isAmbient && this.isAmbient)
    {
        this.isAmbient = other.isAmbient;
    }

    this.field_188421_h = other.field_188421_h;
}

Linked issues

Comments

kumasasa

Confirmed.

marcono1234

Confirmed for

  • 14w30c

  • 14w31a

  • Minecraft 1.8-pre 1

migrated

Confirmed for 1.8.

marcono1234

Please link to this comment in the description

The following is based on a decompiled version of Minecraft 1.9 using MCP 9.24 beta.

The reason why this happens is because the method net.minecraft.potion.PotionEffect.combine(PotionEffect) (and others as well) are not using the value of the net.minecraft.potion.PotionEffect.isPotionDurationMax field of the other potion.

public void combine(PotionEffect other)
{
    if (this.field_188420_b != other.field_188420_b)
    {
        LOGGER.warn("This method should only be called for matching effects!");
    }

    if (other.amplifier > this.amplifier)
    {
        this.amplifier = other.amplifier;
        this.duration = other.duration;
        // Added this
        this.isPotionDurationMax = other.isPotionDurationMax;
    }
    else if (other.amplifier == this.amplifier && this.duration < other.duration)
    {
        this.duration = other.duration;
        // Added this
        this.isPotionDurationMax = other.isPotionDurationMax;
    }
    else if (!other.isAmbient && this.isAmbient)
    {
        this.isAmbient = other.isAmbient;
    }

    this.field_188421_h = other.field_188421_h;
}
migrated

Confirmed for 1.13.1.

j_p_smith

Confirmed in 1.15.2, but fixed in 20w20b or earlier.

migrated

(Unassigned)

Confirmed

UI

/effect, effect

Minecraft 1.7.4, Minecraft 14w02c, Minecraft 14w05b, Minecraft 14w30c, Minecraft 14w31a, ..., Minecraft 17w45b, Minecraft 1.13.1, Minecraft 1.13.2, Minecraft 19w08b, Minecraft 19w09a

20w20b

Retrieved