Compare commits
3
Commits
c110ee2604
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
636a7dee98 | ||
|
|
1e4400555c | ||
|
|
0dfcc5396a |
@@ -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;
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
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();
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
MinX = cuboid.MinX,
|
||||||
|
MinY = cuboid.MinY,
|
||||||
|
MinZ = cuboid.MinZ,
|
||||||
|
MaxX = cuboid.MaxX,
|
||||||
|
MaxY = cuboid.MaxY,
|
||||||
|
MaxZ = cuboid.MaxZ,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
"anth64"
|
"anth64"
|
||||||
],
|
],
|
||||||
"description": "Link claims together with groups.",
|
"description": "Link claims together with groups.",
|
||||||
"version": "0.1.0",
|
"version": "0.3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"game": "1.22.5",
|
"game": "1.22.5",
|
||||||
"commandhook": "2.1.0"
|
"commandhook": "2.1.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user