mojira.dev
MC-90198

Applying effect with amplifier higher than 127 before current potion effect ends causes timer to stay at 0:00

The bug

Applying the same effect you already have but with an amplifier higher than 127 causes the timer to reach 0:00 and remain like this but you still have the potion effect.

How to reproduce

  1. Type the command

    /effect give @s minecraft:strength 10
  2. Before the timer of the effect reaches 0:00, type the command

    /effect give @s minecraft:strength 30 128

    → The effect's timer should remain at 0:00, but you would still have the effect

Code analysis

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

This is a valid report because the method net.minecraft.client.network.NetHandlerPlayClient.handleEntityEffect(SPacketEntityEffect) is not reading the amplifier correctly. The packet stores the amplifier as unsigned byte (0 to 255), however the client reads it as signed byte (-128 to 127). Because of this the client thinks the amplifier is lower and does not extend the duration of the effect. The effect remains however as the client does not receive a SPacketRemoveEntityEffect packet, because for the server, the potion duration was extended.

public void handleEntityEffect(SPacketEntityEffect packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);
    Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId());

    if (entity instanceof EntityLivingBase)
    {
        Potion potion = Potion.getPotionById(packetIn.getEffectId());

        if (potion != null)
        {
            // Replaced this
            //PotionEffect potioneffect = new PotionEffect(potion, packetIn.getDuration(), packetIn.getAmplifier(), packetIn.func_186984_g(), packetIn.func_179707_f());
            PotionEffect potioneffect = new PotionEffect(potion, packetIn.getDuration(), Byte.toUnsignedInt(packetIn.getAmplifier()), packetIn.func_186984_g(), packetIn.func_179707_f());
            
            potioneffect.setPotionDurationMax(packetIn.func_149429_c());
            ((EntityLivingBase)entity).addPotionEffect(potioneffect);
        }
    }
}

Linked issues

Attachments

Comments 14

[Mod] redstonehelper

Is this still an issue in 15w45a? If so, please explain the issue in detail and provide steps to reproduce it. Please also update the list of affected versions.

Confirmed for

  • 15w47c

Just have a repeating command block running a /testfor command and then a conditional chain command block that gives you the effect.

testfor command

/testfor @p {ActiveEffects:[{Duration:1}]}

It looks like this is caused only by the high amplifier but not by the duration

Please change the summary (title) of the report to something like "Potion effects with high amplifiers remain displayed in inventory after timer reaches 0:00"

[Mod] redstonehelper

So regular amplifiers are not an issue?

Luke Finn Zamponi

redstonehelper, yes it is.

4 more comments

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.

This is a valid report because the method net.minecraft.client.network.NetHandlerPlayClient.handleEntityEffect(SPacketEntityEffect) is not reading the amplifier correctly. The packet stores the amplifier as unsigned byte (0 to 255), however the client reads it as signed byte (-128 to 127). Because of this the client thinks the amplifier is lower and does not extend the duration of the effect. The effect remains however as the client does not receive a SPacketRemoveEntityEffect packet, because for the server, the potion duration was extended.

public void handleEntityEffect(SPacketEntityEffect packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);
    Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId());

    if (entity instanceof EntityLivingBase)
    {
        Potion potion = Potion.getPotionById(packetIn.getEffectId());

        if (potion != null)
        {
            // Replaced this
            //PotionEffect potioneffect = new PotionEffect(potion, packetIn.getDuration(), packetIn.getAmplifier(), packetIn.func_186984_g(), packetIn.func_179707_f());
            PotionEffect potioneffect = new PotionEffect(potion, packetIn.getDuration(), Byte.toUnsignedInt(packetIn.getAmplifier()), packetIn.func_186984_g(), packetIn.func_179707_f());
            
            potioneffect.setPotionDurationMax(packetIn.func_149429_c());
            ((EntityLivingBase)entity).addPotionEffect(potioneffect);
        }
    }
}

Is this still an issue in the latest snapshot 16w44a? If so please update the affected versions.

This is an automated comment on any open or reopened issue with out-of-date affected versions.

Confirmed for 1.13.1-pre1

Fixed in 1.15.2. The effect doesn't remain at 0:00 when the 10 seconds potion ends.

Probably fixed due to the fix for MC-1541.

Luke Finn Zamponi

Asteraoth

(Unassigned)

Confirmed

(Unassigned)

effect, effect-amplifier, effect-duration

Minecraft 15w41b, Minecraft 15w45a, Minecraft 15w46a, Minecraft 15w47c, Minecraft 1.9.2, ..., Minecraft 19w12b, Minecraft 19w13b, Minecraft 19w14a, Minecraft 19w14b, Minecraft 1.14.3

1.15.2

Retrieved