Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-90198

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 1.15.2
    • Minecraft 15w41b, Minecraft 15w45a, Minecraft 15w46a, Minecraft 15w47c, Minecraft 1.9.2, Minecraft 16w36a, Minecraft 1.11, Minecraft 1.12, Minecraft 1.12.2, Minecraft 18w05a, Minecraft 1.13, Minecraft 1.13.1-pre1, Minecraft 1.13.1, Minecraft 1.13.2, Minecraft 18w43b, Minecraft 18w45a, Minecraft 18w46a, Minecraft 18w48a, Minecraft 18w48b, Minecraft 18w49a, Minecraft 19w04b, Minecraft 19w07a, Minecraft 19w12b, Minecraft 19w13b, Minecraft 19w14a, Minecraft 19w14b, Minecraft 1.14.3
    • Confirmed
    • (Unassigned)

      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);
              }
          }
      }
      

            Unassigned Unassigned
            Asteraoth [Mod] Asteraoth
            Votes:
            4 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: