mojira.dev
MC-306152

The "/xp add @s <amount> points" command does not correctly calculate levels when adding an exact level’s worth of experience points

Bug Description:

I tested this issue in Minecraft 1.21.5 and 1.21.11, and it occurs in both versions. For example, instead of using /xp add @s 17 levels, I used /xp add @s 394 points, where 394 points is the amount of experience required to reach level 17 according to the formula provided on Minecraft Wiki.

However, after running the command, it only reached level 16 with a full experience bar, and /xp query @s points returned 41 experience points. Since level 16 requires 352 points, this results in a total of 352 + 41 = 393 points, which is 1 point less than the amount added. Use “/xp add @s -393 points“ and query experience levels/points again, it will return 0 level and 0 experience point. This indicates that “/xp add points” does not correctly handle cases where the added experience exactly matches certain levels.

After testing, I found some of the levels that may cause this issue. These levels are 12, 13, 17, 20, 21, 22, 26, 32, 36, 38, 40, 41, 42, 44, 49…

Steps to reproduce the issue:

  1. Use command “/xp add @s 394 points” when having no experience (394 can be any amount of exp points required by the levels listed above);

  2. Instead of reaching 17 levels, you only gain level 16 with a filled experience bar;

  3. Use command “/xp query @s points“. It will return 41 experience points;

  4. Use command “/xp add @s -393 points“. While the experience bar shows there is still remaining experience, “/xp query @s points“ command return 0 points.

Linked issues

Attachments

Comments 2

Reproduced in 26.1-snapshot-5.

Ohmin Young

(Unassigned)

Confirmed

(Unassigned)

1.21.11

Retrieved