From 61bfe6643012cd54c45603626b502101fdcf9030 Mon Sep 17 00:00:00 2001 From: gmfamily <83155813+gmfamily@users.noreply.github.com> Date: Wed, 31 Aug 2022 19:35:18 +0200 Subject: [PATCH] fix(chnk visibility) Use long to avoid int overflow Use long representation of the distance between tested chunk and center of tested limit to avoid int overflow while computing the distance compared to limit radius using square delta value --- .../main/java/org/dynmap/utils/RoundVisibilityLimit.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/DynmapCore/src/main/java/org/dynmap/utils/RoundVisibilityLimit.java b/DynmapCore/src/main/java/org/dynmap/utils/RoundVisibilityLimit.java index 5a0a7606..4e95c296 100644 --- a/DynmapCore/src/main/java/org/dynmap/utils/RoundVisibilityLimit.java +++ b/DynmapCore/src/main/java/org/dynmap/utils/RoundVisibilityLimit.java @@ -25,7 +25,11 @@ public class RoundVisibilityLimit implements VisibilityLimit { else chunk_corner_z = chunk_z * 16 + 15; - return (chunk_corner_x - x_center) * (chunk_corner_x - x_center) + (chunk_corner_z - z_center) * (chunk_corner_z - z_center) < radius * radius; + // By gmfamily - Use long representation of the distance between tested chunk and center of tested limit + // to avoid int overflow while computing the distance compared to limit radius using square delta value + long chunk_delta_x = chunk_corner_x - x_center; + long chunk_delta_z = chunk_corner_z - z_center; + return chunk_delta_x * chunk_delta_x + chunk_delta_z * chunk_delta_z < (long) radius * radius; } @Override