The Bug:
The experience bar disappears when too many levels are given to the player.
Steps to Reproduce:
Give yourself lots of levels by using the command provided below.
/xp add @s 1232323232 levels
Look at your experience bar.
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
is duplicated by 6
relates to 2
Attachments
Comments 18
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)
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