Fix several off-by-one errors in view distance calculations
1. For NearbyPlayers, we need to be using the view distance, and not the load distance (which is +1 of the view distance). 2. Correctly clamp tick distance to view distance. Since load distance is +1 of view distance, we need to subtract one from the load distance when clamping. Additionally, add checks inside ViewDistances to ensure that the inputs are in range to catch future errors. Also, clamp simulation distance, as values < 0 or above MAX_VIEW_DISTANCE do not make sense to configure.
This commit is contained in:
@@ -2727,7 +2727,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ players[NearbyMapType.GENERAL_SMALL.ordinal()].update(chunk.x, chunk.z, GENERAL_SMALL_VIEW_DISTANCE);
|
||||
+ players[NearbyMapType.GENERAL_REALLY_SMALL.ordinal()].update(chunk.x, chunk.z, GENERAL_REALLY_SMALL_VIEW_DISTANCE);
|
||||
+ players[NearbyMapType.TICK_VIEW_DISTANCE.ordinal()].update(chunk.x, chunk.z, ChunkSystem.getTickViewDistance(player));
|
||||
+ players[NearbyMapType.VIEW_DISTANCE.ordinal()].update(chunk.x, chunk.z, ChunkSystem.getLoadViewDistance(player));
|
||||
+ players[NearbyMapType.VIEW_DISTANCE.ordinal()].update(chunk.x, chunk.z, ChunkSystem.getViewDistance(player));
|
||||
+ players[NearbyMapType.SPAWN_RANGE.ordinal()].update(chunk.x, chunk.z, ChunkTickConstants.PLAYER_SPAWN_TRACK_RANGE); // Moonrise - chunk tick iteration
|
||||
+ }
|
||||
+
|
||||
@@ -3582,15 +3582,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ }
|
||||
+
|
||||
+ public static int getSendViewDistance(final ServerPlayer player) {
|
||||
+ return getLoadViewDistance(player) - 1;
|
||||
+ return getViewDistance(player);
|
||||
+ }
|
||||
+
|
||||
+ public static int getLoadViewDistance(final ServerPlayer player) {
|
||||
+ public static int getViewDistance(final ServerPlayer player) {
|
||||
+ final ServerLevel level = player.serverLevel();
|
||||
+ if (level == null) {
|
||||
+ return org.bukkit.Bukkit.getViewDistance() + 1;
|
||||
+ return org.bukkit.Bukkit.getViewDistance();
|
||||
+ }
|
||||
+ return level.chunkSource.chunkMap.serverViewDistance + 1;
|
||||
+ return level.chunkSource.chunkMap.serverViewDistance;
|
||||
+ }
|
||||
+
|
||||
+ public static int getTickViewDistance(final ServerPlayer player) {
|
||||
@@ -6425,7 +6425,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+ @Override
|
||||
+ public int getViewDistance() {
|
||||
+ return ca.spottedleaf.moonrise.common.util.ChunkSystem.getLoadViewDistance(this.getHandle()) - 1;
|
||||
+ return ca.spottedleaf.moonrise.common.util.ChunkSystem.getViewDistance(this.getHandle());
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
|
||||
Reference in New Issue
Block a user