-
-
Notifications
You must be signed in to change notification settings - Fork 837
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
Fix left click on air being ignored and right click on block being handled twice #2153
Conversation
fb7e392
to
b62f817
Compare
Has the performance impact of this been measured? I remember previously doing this for CraftBook in the past, purely with sign clicks that would sometimes be duplicated and found that there was actually a measurable impact on some servers. |
I haven't measured the performance yet. The deduplication is just a map, a specialized fastutil map, so it should have a really low cpu and memory footprint. In fact, the deduplication, would probably avoid some extra processing of double clicks so it will slightly improve performance on this side. About the swing arm packet to detect a left click on air, this is what has been used by Bukkit and Sponge for years and afaik no one has ever reported a performance issue on this part. Moreover, the implementation here is much simpler and lighter (no raytracing needed). Just in case, I will do some measures in-game with Spark's profiler but I doubt I will see anything noticeable. |
b62f817
to
efa6834
Compare
I rebased on latest version/7.2.x commit. I did some benchmarks in-game using Spark and an auto-clicker. Results: As expected the performance impact is negligible on all platforms. The benchmark procedure is manual and not rigorous but I doubt we would see a different result with another approach. |
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.
Overall the way the debounce is handled is fine, but I don't like having the code repeated in every platform. Why not do this in we.handleXClick
instead?
I also think that the fix for LCA in Forge/Fabric should be separated from this PR.
worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java
Outdated
Show resolved
Hide resolved
worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java
Outdated
Show resolved
Hide resolved
...fabric/src/main/java/com/sk89q/worldedit/fabric/mixin/MixinServerGamePacketListenerImpl.java
Outdated
Show resolved
Hide resolved
There is some platform specific stuff related to deduplication. LCA -> always deduplicated. It's been a while since I've worked on this, I will probably check again if the Bukkit-specific stuff is really needed.
LCA is detected using the swing arm packet which is also present for some other click scenarios. In this case, LCA always happen last, so we must deduplicate it. Since LCA is heavily relying on deduplication I don't think we should move it into another PR. LCA without deduplication would trigger a lot of false positives. |
efa6834
to
8eb989c
Compare
I applied your suggestions!
* I added a |
Would it be possible to please rebase this due to conflicts? (involves 1.20 update too) |
Sure I will do ASAP but I'm really busy this week |
8eb989c
to
0f269fe
Compare
Rebased and retested. |
Thanks for this :) |
Left click on air
Bukkit: Left click on air was already detected properly.
Sponge: Added a listener for
InteractItemEvent.Primary
.Forge and Fabric: The click is detected using the swing arm packet. Sponge and Spigot are using this same technique. Sponge and Spigot are doing raytracing to ensure it's a click on air and not on a block but in our case we don't need to do raytracing, just deduplication.
There was a workaround on Forge where the mod if installed on the client would notify the server about the click. This workaround is no longer needed and has been removed.
Right click on block
The right click on a block was handled twice because a RightClickBlock event is always followed by a RightClickAir event on all platforms. To fix this, Event handlers store the tick number during which the last interaction occured and ignore air interactions that are too close (tick delta <= 1).
This mechanism is active for both left and righ clicks.