Your experience level overflows once it exceeds the integer limit
Resolved
Fixed
50
The bug
The XP level can overflow causing the experience bar to disappear.
How to reproduce
Type /xp set @s 2147483647 levels. Now your level is 2147483647.
Type /xp add @s 1 levels. XP disappears from display.
Type /xp add @s 1 levels again. Now your level is 1.
So, maximum player's level is 2^31 - 1, after which the level overflows and is treated as 0. The possible solution (suggested by @unknown) is to cap maximum level.
Is this still a concern in the current Minecraft version? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.
Is this still a concern in the latest Minecraft version 14w30c? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.
Still present in 18w16a. Might want to update the Steps to reproduce to 1.13-format, this renders the first point useless (as with the new command you can set the level) Here's the updated version: 1.Type /xp set @s 2147483647 levels. Now your level is 2147483647. 2. Type /xp add @s 1 levels. XP disappears from display. 3. Type /xp add @s 1 levels again. Now your level is 1.
You could turn the signed 32-bit integer into a signed 64-bit integer, but this requires 4 bytes more per player in the player data. Sure, this might be a bit small-minded, but is it really necessary to have such a high-level number? This is hardly playable in Survival? A solution would be a BigInt which is then saved as a string in the world file. Unfortunately Java does not support unsigned integer, so you would have to write a wrapper around the integer to only cut the negative range.
Java already has Math.addExact, which doesn't allow overflows. The fix is just to use that. Using a bigger number type would not fix the problem, just postpone it.
@@unknown, Math.addExact throws an exception on overflow which would not be helpful here. Capping the value at the maximum positive value sounds reasonable especially since such high XP levels can likely not be obtained in Survival anyways.
@Marcono1234, In survival, the maximum level is much less than 2^31-1, as the amount of xp points (not levels) is capped at the 32-bit limit, restricting you to level 21863. Rays Works on youtube has demonstrated this in vanilla survival on the ProtoTech server, using a very powerful XP farm which he ran for multiple weeks.
this is because of the 32 signed bit integer limit (2,147,483,647) after this number the game automaticly resets your level to 1. this happends because of the way how the xp level is stored
@unknown Could you please not go through tons of tickets, making either obvious/redundant (MC-201, MC-1531, MC-3266, MC-1673, …) or incorrect (MC-180, MC-212, MC-2157, MC-2112, MC-2791, MC-1297, …) statements? I got lots of mails from your comments over night, followed by a bunch of mails of people correcting you. Please only contribute if you actually have new and relevant information, not baseless speculation. Also, if you want go through all currently open bugs, prepare some meals first, because you'll need a really long time for 8375 reports…
I think the solution here is not to make this an unsigned int, but to simply cap the max level so it doesn't happen.