feat: add client-visualizer network endpoint for buffer geometry
This commit is contained in:
@@ -35,6 +35,7 @@ public class ClaimLinkModSystem : ModSystem
|
||||
GroupCmdListener = new GroupCommandListener();
|
||||
CommandHookModSystem.Register(GroupCmdListener);
|
||||
ClaimLinkChatCommand.Register(api);
|
||||
ClaimLinkVisualizerNetwork.Start(api);
|
||||
|
||||
api.Event.PlayerDisconnect += CommandListener.OnPlayerDisconnect;
|
||||
api.Event.PlayerDisconnect += GroupCommandListener.OnPlayerDisconnect;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user