feat: add client-visualizer network endpoint for buffer geometry

This commit is contained in:
2026-07-30 23:14:06 +02:00
parent c110ee2604
commit 0dfcc5396a
2 changed files with 90 additions and 0 deletions
+1
View File
@@ -35,6 +35,7 @@ public class ClaimLinkModSystem : ModSystem
GroupCmdListener = new GroupCommandListener(); GroupCmdListener = new GroupCommandListener();
CommandHookModSystem.Register(GroupCmdListener); CommandHookModSystem.Register(GroupCmdListener);
ClaimLinkChatCommand.Register(api); ClaimLinkChatCommand.Register(api);
ClaimLinkVisualizerNetwork.Start(api);
api.Event.PlayerDisconnect += CommandListener.OnPlayerDisconnect; api.Event.PlayerDisconnect += CommandListener.OnPlayerDisconnect;
api.Event.PlayerDisconnect += GroupCommandListener.OnPlayerDisconnect; api.Event.PlayerDisconnect += GroupCommandListener.OnPlayerDisconnect;
+89
View File
@@ -0,0 +1,89 @@
using System.Collections.Generic;
using ProtoBuf;
using Vintagestory.API.MathTools;
using Vintagestory.API.Server;
namespace ClaimLink;
[ProtoContract]
public class ClaimLinkBufferRequest { }
[ProtoContract]
public class ClaimLinkBufferCuboidDto
{
[ProtoMember(1)]
public int MinX;
[ProtoMember(2)]
public int MinY;
[ProtoMember(3)]
public int MinZ;
[ProtoMember(4)]
public int MaxX;
[ProtoMember(5)]
public int MaxY;
[ProtoMember(6)]
public int MaxZ;
}
[ProtoContract]
public class ClaimLinkBufferEntryDto
{
[ProtoMember(1)]
public int GroupId;
[ProtoMember(2)]
public List<ClaimLinkBufferCuboidDto> Cuboids = new();
}
[ProtoContract]
public class ClaimLinkBufferResponse
{
[ProtoMember(1)]
public List<ClaimLinkBufferEntryDto> Entries = new();
}
internal static class ClaimLinkVisualizerNetwork
{
internal const string ChannelName = "claimlinkvisualizer";
internal static void Start(ICoreServerAPI api)
{
api.Network
.RegisterChannel(ChannelName)
.RegisterMessageType<ClaimLinkBufferRequest>()
.RegisterMessageType<ClaimLinkBufferResponse>()
.SetMessageHandler<ClaimLinkBufferRequest>((fromPlayer, _) =>
SendBuffers(api, fromPlayer)
);
}
private static void SendBuffers(ICoreServerAPI api, IServerPlayer toPlayer)
{
ClaimLinkBufferResponse response = new();
foreach (int groupId in ClaimLinkModSystem.Registry.All)
{
ClaimLinkBufferEntryDto entry = new() { GroupId = groupId };
foreach (Cuboidi cuboid in ClaimLinkBuffer.GetBuffer(groupId))
entry.Cuboids.Add(
new ClaimLinkBufferCuboidDto
{
MinX = cuboid.MinX,
MinY = cuboid.MinY,
MinZ = cuboid.MinZ,
MaxX = cuboid.MaxX,
MaxY = cuboid.MaxY,
MaxZ = cuboid.MaxZ,
}
);
response.Entries.Add(entry);
}
api.Network.GetChannel(ChannelName).SendPacket(response, toPlayer);
}
}