55import net .minecraft .network .packet .s2c .play .ChunkLoadDistanceS2CPacket ;
66import net .minecraft .server .world .ServerWorld ;
77import net .minecraft .util .Identifier ;
8- import net .minecraft .util .math .BlockPos ;
98import net .minecraft .util .math .ChunkPos ;
109import net .minecraft .util .math .MathHelper ;
11- import net .minecraft .util .registry .Registry ;
1210
1311import java .util .Map ;
1412import java .util .UUID ;
@@ -66,7 +64,7 @@ public void updateRenderDistance(ServerWorld world) {
6664 var config = worldSpecific ().get (world .getRegistryKey ().getValue ());
6765 if (config == null ) config = this .config ();
6866 if (config .dynamic .renderDistance ) {
69- int distance = getEffectiveRenderDistance (world );
67+ int distance = getEffectiveRenderDistance (world , true );
7068 if (((MixinThreadedAnvilChunkStorage ) world .getChunkManager ().threadedAnvilChunkStorage ).getWatchDistance () != distance ) {
7169 world .getChunkManager ().applyViewDistance (distance - 1 );
7270 world .getServer ().getPlayerManager ().sendToAll (new ChunkLoadDistanceS2CPacket (distance - 1 ));
@@ -95,7 +93,7 @@ else if (performanceLevel == 1)
9593 return config .tickDistance ;
9694 }
9795
98- public int getEffectiveRenderDistance (ServerWorld world ) {
96+ public int getEffectiveRenderDistance (ServerWorld world , boolean messages ) {
9997 var config = worldSpecific ().get (world .getRegistryKey ().getValue ());
10098 if (config == null ) config = this .config ();
10199
@@ -107,14 +105,20 @@ public int getEffectiveRenderDistance(ServerWorld world) {
107105
108106 if (avgTickTime > config .dynamic .targetMSPT && currentDistance - 1 > config .dynamic .minTickDistance ) {
109107 currentDistance --;
110- TickTools .LOGGER .info (String .format ("Avg MSPT: %.2f above %d. Decreasing view distance in %s to %d" ,
111- avgTickTime , config .dynamic .targetMSPT , world .getRegistryKey ().getValue (), currentDistance - 1
112- ));
108+ if (messages ) {
109+ TickTools .LOGGER .info (String .format ("Avg MSPT: %.2f above %d. Decreasing view distance in %s to %d" ,
110+ // We cast target MSPT to int to make it look better
111+ // In reality this value is a double, like in the config
112+ avgTickTime , (int ) config .dynamic .targetMSPT , world .getRegistryKey ().getValue (), currentDistance - 1
113+ ));
114+ }
113115 } else if (avgTickTime < config .dynamic .targetMSPT && currentDistance - 1 < config .dynamic .maxRenderDistance ) {
114116 currentDistance ++;
115- TickTools .LOGGER .info (String .format ("Avg MSPT: %.2f below %d. Increasing view distance in %s to to %d" ,
116- avgTickTime , config .dynamic .targetMSPT , world .getRegistryKey ().getValue (), currentDistance - 1
117- ));
117+ if (messages ) {
118+ TickTools .LOGGER .info (String .format ("Avg MSPT: %.2f below %d. Increasing view distance in %s to to %d" ,
119+ avgTickTime , (int ) config .dynamic .targetMSPT , world .getRegistryKey ().getValue (), currentDistance - 1
120+ ));
121+ }
118122 }
119123
120124 return currentDistance ;
0 commit comments