Slimefun4
Slimefun4 copied to clipboard
Fix: solve teleportation time overflow problem.
Description
In TP time calculation, $\rm complexity \times complexity$ may result in int overflow when complexity is higher than $4\times 10^{4}$, not difficult to achieve with several popular addons.
Compared with original solution based on Math
function, it is better to avoid overflow directly.
Proposed changes
Use long
to storage temporary speed variable, which hardly overflow in TP time calculation.
If $\rm speed > distance$, time cost must be 1 tick, so we can skip calculation.
Otherwise, $\rm \dfrac {distance}{speed} \geq 1$, while speed must be in range of int
.
Therefore we can simply convert speed to int variable to calculate ultimate time cost.
Related Issues (if applicable)
Checklist
- [x] I have fully tested the proposed changes and promise that they will not break everything into chaos.
- [ ] I have also tested the proposed changes in combination with various popular addons and can confirm my changes do not break them.
- [x] I have made sure that the proposed changes do not break compatibility across the supported Minecraft versions (1.16.* - 1.20.*).
- [ ] I followed the existing code standards and didn't mess up the formatting.
- [x] I did my best to add documentation to any public classes or methods I added.
- [x] I have added
Nonnull
andNullable
annotations to my methods to indicate their behaviour for null values - [ ] I added sufficient Unit Tests to cover my code.
Pro Tip! You can help us label your Pull Requests by using the following branch naming convention next time you create a pull request. ❤️
Branch naming convention | Label |
---|---|
feature/** |
🎈 Feature |
fix/** |
✨ Fix |
chore/** |
🧹 Chores |
api/** |
🔧 API |
performance/** |
💡 Performance Optimization |
compatibility/** |
🤝 Compatibility |
If your changes do not fall into any of these categories, don't worry. You can just ignore this message in that case! 👀
Slimefun preview build
A Slimefun preview build is available for testing! Commit: afc73256
https://preview-builds.walshy.dev/download/Slimefun/4163/afc73256
Note: This is not a supported build and is only here for the purposes of testing. Do not run this on a live server and do not report bugs anywhere but this PR!
Why are we moving it to a long? Aren’t we delaying the issue then, this isn’t solving the issue.
should limit it to a value instead of moving the problem in my opinion
Why are we moving it to a long? Aren’t we delaying the issue then, this isn’t solving the issue.
should limit it to a value instead of moving the problem in my opinion
Though it may be more robust, I have no idea what will be happening in future overflow bug.
If long
was not enough for complexity², int
might not be suitable for complexity as well, which meant a thorough rework would be needed.
Besides, I have another subject to work at present, so my solution ends here.
Why are we moving it to a long? Aren’t we delaying the issue then, this isn’t solving the issue.
should limit it to a value instead of moving the problem in my opinion
@J3fftw1 As you wish.