From 636a7dee9856032557b506b3052aae58ea9abc28 Mon Sep 17 00:00:00 2001 From: anth64 Date: Fri, 31 Jul 2026 07:38:56 +0200 Subject: [PATCH] feat: filter buffer data sent to visualizer clients by view distance --- ClaimLink/ClaimLinkVisualizerNetwork.cs | 20 +++++++++++++++++++- ClaimLink/modinfo.json | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ClaimLink/ClaimLinkVisualizerNetwork.cs b/ClaimLink/ClaimLinkVisualizerNetwork.cs index a553a48..2ecb0e7 100644 --- a/ClaimLink/ClaimLinkVisualizerNetwork.cs +++ b/ClaimLink/ClaimLinkVisualizerNetwork.cs @@ -66,10 +66,17 @@ internal static class ClaimLinkVisualizerNetwork { ClaimLinkBufferResponse response = new(); + BlockPos playerPos = toPlayer.Entity.Pos.AsBlockPos; + int radius = toPlayer.WorldData.LastApprovedViewDistance; + foreach (int groupId in ClaimLinkModSystem.Registry.All) { ClaimLinkBufferEntryDto entry = new() { GroupId = groupId }; foreach (Cuboidi cuboid in ClaimLinkBuffer.GetBuffer(groupId)) + { + if (!IsNearby(cuboid, playerPos, radius)) + continue; + entry.Cuboids.Add( new ClaimLinkBufferCuboidDto { @@ -81,9 +88,20 @@ internal static class ClaimLinkVisualizerNetwork MaxZ = cuboid.MaxZ, } ); - response.Entries.Add(entry); + } + + if (entry.Cuboids.Count > 0) + response.Entries.Add(entry); } api.Network.GetChannel(ChannelName).SendPacket(response, toPlayer); } + + private static bool IsNearby(Cuboidi cuboid, BlockPos playerPos, int radius) => + cuboid.MinX <= playerPos.X + radius + && cuboid.MaxX >= playerPos.X - radius + && cuboid.MinY <= playerPos.Y + radius + && cuboid.MaxY >= playerPos.Y - radius + && cuboid.MinZ <= playerPos.Z + radius + && cuboid.MaxZ >= playerPos.Z - radius; } diff --git a/ClaimLink/modinfo.json b/ClaimLink/modinfo.json index 33d3556..65ce703 100644 --- a/ClaimLink/modinfo.json +++ b/ClaimLink/modinfo.json @@ -8,7 +8,7 @@ "anth64" ], "description": "Link claims together with groups.", - "version": "0.2.0", + "version": "0.3.0", "dependencies": { "game": "1.22.5", "commandhook": "2.1.0"