Fix player walking on contraption causes lag (#9598)#10570
Open
lzpoupl wants to merge 1 commit into
Open
Conversation
Author
|
@TqLxQuanZ Solution to your modpack lag issue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issues: #9153 #4646 #9598 #6855
The bug appears to be caused by the contraption step sound Mixin
Create/src/main/java/com/simibubi/create/foundation/mixin/client/EntityContraptionInteractionMixin.java
Line 104 in fdfde66
BlockPosintoplayStepSound(pos, state). For non-player entity like zombie, this method won't use the pos parameter, so nothing happens.However, for players this dispatches to
Player.playStepSound, which treats the position as a world position and performs additionallevel.getBlockState(...)lookups. Then, the server takes the local coordinates and interprets them as world coordinates, repeatedly querying a chunk near (0, 0) that is not loaded, which is an unnecessary cost and causes lag and extra memory usage.Example of the coordinate mismatch:
player world position: (10003, 58, 10007)
contraption-local position: (3, 1, 7)
queried world chunk: (0, 0)
My solution now is to fall back to the implementation of
Entity.playStepSound(). There might be a better solution, but I don't know much about minecraft sound engine and Mixin so I can't figure it out, though the cause of the bug is now clear.A temporary workaround for this bug: /forceload the chunks around (0, 0) to mitigate the lag caused by repeated chunk loading.
I have another question. The Mixin class is in
clientpackage, so in theory it shouldn't cause server thread to lag, but it indeed does.