-
Notifications
You must be signed in to change notification settings - Fork 417
Fix horse hitbox falses #2041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.0
Are you sure you want to change the base?
Fix horse hitbox falses #2041
Conversation
src/main/java/ac/grim/grimac/events/packets/CheckManagerListener.java
Outdated
Show resolved
Hide resolved
Transactions are sent before flying, so we would reset the variable before we receive the new rotation, I don’t think this is the correct way to fix this |
bc85bf1
to
4eeab0e
Compare
Yes, the order per client tick is transactions, attacks/interacts, then flying, right?
The field only has to be true for a single client tick, starting from the point we receive the interact, ending after we checked reach. Resetting it as early as possible is important (to not allow attack hitbox bypasses in the next tick). Once we receive a flying or a transaction, we can reset it safely because we know a new tick has started (this new tick can already have player influenced rotation again). Also, we're very certain to get a rotation packet directly after interacting with the horse because of the forced rotation change. The single case where we don't receive a rotation but rather a transaction is in versions without the idle packet when the forced rotation change didn't actually modify the player's rotation (already oriented the same way as the horse!). Then we're at the beginning of the next tick and don't need to exempt anymore since the player could have already made some mouse input. If we need to exempt again the client will let us know by interacting with the horse again. Please let me know if I misunderstood something or should test this change with any other versions. As far as I can tell from my testing it works as intended on 1.8.9 and 1.13 clients. |
4eeab0e
to
58835ed
Compare
58835ed
to
0c65b28
Compare
0c65b28
to
0df4dbf
Compare
Tested this again with a vanilla 1.8 client on a 1.8 Paper server and a 1.21.4 Paper server, it still fixes the falses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good overall
after testing, I can confirm this does fix the hitbox false positives
what if the new rotation is still looking at the horse but is now out of range? |
0df4dbf
to
9969f6b
Compare
Ok I would have never thought of that. I tried it, and you're correct. There's still reach falses currently, the exact reproduction steps are:
The highest reach false I got during testing was 4.1 blocks. As for the fix, I have simply moved the exemption I previously added slightly so that it also covers reach flags. However, when thinking it through I found that it would allow one bypass:
To fix that, I execute the simple |
double optimalRotationMinDistance = ReachUtils.getMinReachToBox(player, targetBox); | ||
if (optimalRotationMinDistance > maxReach) { | ||
return new CheckResult(ResultType.REACH, String.format("%.5f", optimalRotationMinDistance) + " blocks"); | ||
} else { | ||
return NONE; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason for not just setting minDistance
here? If not this could be moved to where minDistance
is calculated as an if else to save performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's better we can save a lot of performance here. I have two suggestions for the implementation:
- Move the entire existing
minDistance
calculation into the else block of the horse condition and put thegetMinReachToBox
call in the if block (this would have less duplicate code for returning theCheckResult
) - Early exit by moving the existing horse condition block as it is right now before the beginning of the
minDistance
calculation (this would have less indention for theminDistance
calculation than the first suggestion)
Both have some advantages, which would you prefer?
Fixes the hitboxes falses when mounting a horse (mentioned in #1794). When interacting with a horse, the player's rotation is forcefully set to the horse's rotation on the client in 1.13 and below so we don't receive the actual rotation used to interact with the horse, meaning we can't check for hitboxes when interacting with horses. We can still check for reach though.
This fix uses the horseInteractCausedForcedRotation field introduced in #2033 (that PR also includes a more detailed explanation of the exact cause) in the reach check to exempt only the hitbox check for horses when the player has interacted with one in the current tick (this also exempts any attacks in the same tick since these false too). For this to work, I had to move the reset of the boolean field near the end of the
onPacketReceive
method inCheckManagerListener
so we can still access the true value in the reach check.I have included a detailed comment in the reach check code explaining the exemption, please let me know if I should shorten that and refer here instead.