mojira.dev
MC-79545

The experience bar disappears when too many levels are given to the player

The Bug:

The experience bar disappears when too many levels are given to the player.

Steps to Reproduce:

  1. Give yourself lots of levels by using the command provided below.

    /xp add @s 1232323232 levels
  2. Look at your experience bar.

  3. Take note as to whether or not the experience bar disappears when too many levels are given to the player.

Observed Behavior:

The experience bar disappears.

Expected Behavior:

The experience bar would not disappear.

Code Analysis:

Code analysis by @unknown can be found in this comment.

Linked issues

Attachments

Comments 18

Confirmed for

  • 1.8.5

It seems to start always with these (and maybe more numbers):

  • 238610000

  • 715827901

  • 1200000000

  • 1670265078

The end however seems to vary depending on which number you add

confirmed for 1.8.7

Confirmed for

  • 16w05b

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 problem here is rather that the method net.minecraft.entity.player.EntityPlayer.xpBarCap() limits the xp value. Adding experience (not level) after that has no effect or will not work correctly anymore. This limit is however not respected when adding levels. In 1.9 this maximum experience amount for a level is calculated like this

if (this.experienceLevel >= 30) {
    return 112 + (this.experienceLevel - 30) * 9;
}
else if (this.experienceLevel >= 15) {
    return 37 + (this.experienceLevel - 15) * 5;
}
else {
    return 7 + this.experienceLevel * 2;
}

The returned number can have values between -2^31 and 2^31 - 1. This means if the experience level is higher than 238609311 the required experience amount to level up is invalid, because it will overflow and become negative:

((2^31 - 1) - 112) / 9 + 30 = 238609311.66666666666666666666667

Relates to MC-122715 (command argument limit gone)

8 more comments

can confirm for 1.17.1 as i accidentally made a dupe report lol

this number is very close to the 32-bit integer limit maybe that's the problem

But it didnt overflow yet

Can confirm this behavior in 21w44a

can confirm in 1.19.4

pie595

Avoma

(Unassigned)

Confirmed

UI

Minecraft 1.8.3, Minecraft 1.8.4, Minecraft 1.8.5, Minecraft 1.8.7, Minecraft 1.8.9, ..., 1.21.4, 25w08a, 1.21.5, 1.21.6, 1.21.7

Retrieved