
Sending duplicate chunks to player
solonovamax opened this issue ยท 4 comments
Testing lines 135-149 in ThreadedAnvilStorageMixin
from commit d24cb7e, I received the following result: (duplicate chunks underlined with unique colours) (note: for the test, I set watchDistance
to 1
.)
For reference, here is the code that I executed:
jshell> int watchDistance = 1
watchDistance ==> 1
jshell> for (int d = 0; d <= watchDistance; d++) {
...> for (int curX = 0 - d - 1; curX <= 0 + d + 1; curX++) {
...> ChunkPosition posTop = new ChunkPosition(curX, 0);
...> ChunkPosition posBottom = new ChunkPosition(curX, 0 + d + 1);
...> System.out.printf("pos top: %s, pos bottom: %s%n", posTop, posBottom);
...> }
...> for (int curZ = 0 - d - 1; curZ <= 0 + d + 1; ++curZ) {
...> ChunkPosition posLeft = new ChunkPosition(0, curZ);
...> ChunkPosition posRight = new ChunkPosition(0 + d + 1, curZ);
...> System.out.printf("pos left: %s, pos right: %s%n", posLeft, posRight);
...> }
...> }
This commit was introduced as a fix to #69, but it seems to introduce further issues.
Unless sendWatchPackets
contains code to avoid sending duplicate chunks, several chunks are being sent multiple times. I also believe the number of duplicate chunks increases linearly as watchDistance
increases. (Though, I could be incorrect as I did not spend a lot of time examining the code)
Looking up some algorithms for performing a loop spiraling outwards, you'd want to use an algorithm similar to those demonstrated here:
- https://www.baeldung.com/cs/looping-spiral
- https://stackoverflow.com/a/398302
- https://stackoverflow.com/a/19287714
- https://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/
- https://stackoverflow.com/a/3706260
I could look at opening a PR with some code later, if you'd like
Partially fixed with 3b66408, at least for teleporting into a new area. I could also apply this for the other case of moving nearby but the server would need to track the chunks it thinks the client should be seeing.
You didn't examine too much on this - Mojang really is sending chunks multiple times!
You didn't examine too much on this
Yeah, I didn't
I was on my laptop & couldn't bring up a yarn env or anything.
But, because krypton is a network optimization mod, it should avoid sending chunks multiple times.
I'll test the latest krypton snapshot to see if I can find any issues with it