3

In Minecraft, some potion effects seem to get weird effects if you use level 128.

This seems to happen with:

  • Haste, some block will be insta-mined, some blocks are unable to be mined. The hand-swing animation is also very slow.
  • Mining Fatigue, while you can't mine anything like with level 127, the hand-swing animation is gone.
  • Jump boost, you are unable to jump.
  • Regeneration, it seems much slower then level 127.
  • Wither, it seems much slower then level 127.
  • Levitation, it seems to increase gravity. As soon as you jump or fall, you are much faster on the ground then normal.

Why does potion level 128 give some potions weird effects and why doesn't it happen with all potions?

2
  • 1
    Just a guess, so I won't put it as an answer, but this sounds like an issue with the datatype used to store the potion modifier. For instance, a signed 8-bit datatype has a range of -127 to 127, so if you try to store a 128, it loops back to -127. In this case, it sounds like the potion level is displayed correctly, but when that level is applied to the effect modifier, it overflows.
    – Liesmith
    May 13 '16 at 6:01
  • 1
    @Liesmith 's guess is very likely, though someone needs to look into game's code to say for sure. According to wiki, enchantment levels are stored on Short numbers, which gives a range of -32768 to 32767 (hence you are able to assign 128 at all), so the conversion to Byte (-128 to 127) happens somewhere during effect calculation.
    – Orc JMR
    May 13 '16 at 6:45
2

Each potion effect is handled differently, but the important thing to note is storage size.

Internally the amplifier is stored as an integer (minimum of -2,147,483,648, maximum of 2,147,483,647), but when writing the amplifier to NBT it gets saved as a byte (minimum of -128, maximum of 127). If the value provided is outside of that range, it will be forced back into that range.

As such, when attempting to set the amplifier via NBT (e.g. with /give or /summon), you are restricted to that range and trying to exceed 127 will cause it to overflow to negative values (128 becomes -128). You cannot achieve an amplifier of 128 with NBT.

But the /effect command doesn't go through NBT to assign an effect. It directly sets the amplifier (which is stored as an integer) and is allowed to exceed the maximum. However, if the entity is saved to NBT, the effect is saved which will cause the value to overflow appropriately, potentially changing what the effect does due to the negative value.


When attempting to use /effect to apply a higher amplifier than 127 on a player, the client is sent an amplifier typecasted to byte via the SPacketEntityEffect packet, which reduces the amplifier into the byte range. The client and server are fighting over what the value is meant to be.

For example, with the following:

/effect @p minecraft:levitation 1 255

The server says "255" (since it's saved internally as an integer) but the client is saying "0" (since it's sent via packet as a byte). The result is the client seeing itself not moving. Some issues come as a result, such as taking damage will cause the player to shoot high into the air in an attempt to resync.

This is what causes oddities with players, but this doesn't work the same way with non-player entities. Their amplifier is internally stored as an integer and no packets are interfering, allowing the server full control. If the entity is saved to NBT, such as by chunk unloading, the effect will then overflow into byte range:

/effect @e[type=Creeper,c=1] minecraft:levitation 1 255
2
  • But why doesn't this actually happen on every potion? Health boost for example doesn't seem to do any weird things from 128-255.
    – nelson2tm
    May 14 '16 at 6:25
  • @nelson2tm It sets the player's attribute modifier a single time based on the amplifier server-side and never sets it again. The client doesn't care about the effect itself at that point until its duration expires. The same goes for all attribute-based effects (strength, weakness, speed, slowness, luck, unluck).
    – Skylinerw
    May 14 '16 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.