Potentially fix render distance issues

This commit is contained in:
Camotoy 2024-06-20 21:57:48 -04:00
parent 78642db3ad
commit de0d87f713
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
2 changed files with 33 additions and 2 deletions

View file

@ -268,7 +268,6 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
@Setter
private Vector2i lastChunkPosition = null;
@Setter
private int clientRenderDistance = -1;
private int serverRenderDistance = -1;
@ -1422,11 +1421,36 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
sendDownstreamGamePacket(new ServerboundChatCommandSignedPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), 0, new BitSet()));
}
public void setClientRenderDistance(int clientRenderDistance) {
boolean oldSquareToCircle = this.clientRenderDistance < this.serverRenderDistance;
this.clientRenderDistance = clientRenderDistance;
boolean newSquareToCircle = this.clientRenderDistance < this.serverRenderDistance;
if (this.serverRenderDistance != -1 && oldSquareToCircle != newSquareToCircle) {
recalculateBedrockRenderDistance();
}
}
public void setServerRenderDistance(int renderDistance) {
// Ensure render distance is not above 96 as sending a larger value at any point crashes mobile clients and 96 is the max of any bedrock platform
renderDistance = Math.min(renderDistance, 96);
this.serverRenderDistance = renderDistance;
recalculateBedrockRenderDistance();
}
/**
* Ensures that the ChunkRadiusUpdatedPacket uses the correct render distance for whatever the client distance is set as.
* If the server render distance is larger than the client's, then account for this and add some extra padding.
* We don't want to apply this for every render distance, if at all possible, because
*/
private void recalculateBedrockRenderDistance() {
int renderDistance;
if (this.clientRenderDistance < this.serverRenderDistance) {
renderDistance = ChunkUtils.squareToCircle(this.serverRenderDistance);
} else {
renderDistance = this.serverRenderDistance;
}
ChunkRadiusUpdatedPacket chunkRadiusUpdatedPacket = new ChunkRadiusUpdatedPacket();
chunkRadiusUpdatedPacket.setRadius(renderDistance);
upstream.sendPacket(chunkRadiusUpdatedPacket);

View file

@ -99,13 +99,20 @@ public class ChunkUtils {
chunkPublisherUpdatePacket.setPosition(position);
// Mitigates chunks not loading on 1.17.1 Paper and 1.19.3 Fabric. As of Bedrock 1.19.60.
// https://github.com/GeyserMC/Geyser/issues/3490
chunkPublisherUpdatePacket.setRadius(GenericMath.ceil((session.getServerRenderDistance() + 1) * MathUtils.SQRT_OF_TWO) << 4);
chunkPublisherUpdatePacket.setRadius(squareToCircle(session.getServerRenderDistance()) << 4);
session.sendUpstreamPacket(chunkPublisherUpdatePacket);
session.setLastChunkPosition(newChunkPos);
}
}
/**
* Converts a Java render distance number to the equivalent in Bedrock.
*/
public static int squareToCircle(int renderDistance) {
return GenericMath.ceil((renderDistance + 1) * MathUtils.SQRT_OF_TWO);
}
/**
* Sends a block update to the Bedrock client. If the platform is not Spigot, this also
* adds that block to the cache.