Improve xp calculation to avoid stack overflow and int overflow issues #329
No reviewers
Labels
No labels
Area-Assets
Area-Backend
Area-Conduits
Area-Datapacks
Area-Lang
Area-Mod Compat
Area-Parity
Area-Rendering
Good first issue
MC-1.19.2
MC-1.20.1
MC-1.20.4
MC-1.20.6
MC-1.21
MC-1.21.1
Modtoberfest
P-0-High
P-1-Medium
P-2-Low
Status-Awaiting Response
Status-Behind-Flag
Status-Blocked
Status-Cannot Reproduce
Status-Duplicate
Status-Help Wanted
Status-Incomplete Report
Status-Invalid
Status-Needs LTS Backport
Status-Needs Updating
Status-Stale
Status-To Implement
Status-Triage
Status-Wontfix
Status-Wontmerge
Type-Backport
Type-Bug
Type-Documentation
Type-Enhancement
Type-Question
Type-RFC
Type-Suggestion
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: Team-EnderIO/EnderIO#329
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "dev/1.20.1"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
Improved calculation of XP to avoid long loops and some overflow issues in more critical areas.
Closes #313
Checklist:
@ -70,0 +22,4 @@long xpNeededToStop = getExpFromLevel(stopLevel);if (totalXp >= xpNeededToStop) {int leftoverXP = (int) Math.min(totalXp - xpNeededToStop, Integer.MAX_VALUE);return new Vector2i(stopLevel, leftoverXP);note: depending on needs it might be good idea to return here something that can handle bigger leftover values, but I don't think its an issue for now
Sorry; been rather busy and am only just getting to this PR.
I'm not really sure the changes to use
longis worth it. The binary search fix for the actual calculation is definitely the right fix for the problem, but if we're going to truncate the results to integers everywhere, we might as well do that in the method and just return an int, as I don't really see a scenario where we need to handle such a significant amount of XP.CC @agnor99 - feel free to disagree with me here :)
I'm not going to mark this as a Request changes, as my opinion may not be the best way forward :)
@Rover656 Well best option would be to actually propagate this long to other places too, but didn't want to spend hours on touching half of the files in the project. Currently it still helps avoiding any overflows during calculations, as you still can change big amount of XP into small amount of levels and small leftover.
With all the crazy mods out there I don't think its really overkill. Ints cause a lot of issues in all of the mods because people just keep going crazy with their mods and constructions - especially power.
In this case overflows will start happen when dealing with levels above 21863, so sure, its quite a lot, but I don't think its out of modded minecraft reach. And with using longs the limit can be raised to 960383883 levels.
Speaking of what... I've noticed a small mistake in my code so pushing a small fix.
Thanks for your contribution, however we've opted to design this in a different manner in #547 (feel free to review this PR if you have any feedback on this variant) - thanks for taking the time to help us investigate this issue however!
Pull request closed