Mojira Archive
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;
}