Merge pull request #3844 from gmfamily/v3.0

fix(chnk visibility) Use long to avoid int overflow
This commit is contained in:
mikeprimm 2022-11-29 15:39:40 -06:00 committed by GitHub
commit e15f3f8460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,7 +25,11 @@ public class RoundVisibilityLimit implements VisibilityLimit {
else else
chunk_corner_z = chunk_z * 16 + 15; 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 @Override