Compare commits
3
Commits
main
..
7200980a23
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7200980a23 | ||
|
|
7c2722d84c | ||
|
|
09ced98505 |
@@ -16,6 +16,10 @@
|
|||||||
<HintPath>$(VINTAGE_STORY)/Lib/protobuf-net.dll</HintPath>
|
<HintPath>$(VINTAGE_STORY)/Lib/protobuf-net.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="ClaimLink">
|
||||||
|
<HintPath>$(CLAIMLINK)/ClaimLink.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -10,15 +10,13 @@ internal static class ClaimLinkVisualizerClient
|
|||||||
private const int HighlightSlotId = 8341;
|
private const int HighlightSlotId = 8341;
|
||||||
private static ICoreClientAPI capi = null!;
|
private static ICoreClientAPI capi = null!;
|
||||||
private static bool visible;
|
private static bool visible;
|
||||||
private static ClaimLinkVisualizerConfig config = null!;
|
|
||||||
|
|
||||||
internal static void Start(ICoreClientAPI api)
|
internal static void Start(ICoreClientAPI api)
|
||||||
{
|
{
|
||||||
capi = api;
|
capi = api;
|
||||||
config = api.LoadModConfig<ClaimLinkVisualizerConfig>("claimlinkvisualizer.json") ?? new ClaimLinkVisualizerConfig();
|
|
||||||
api.StoreModConfig(config, "claimlinkvisualizer.json");
|
|
||||||
|
|
||||||
api.Network.RegisterChannel(ClaimLinkVisualizerModSystem.ChannelName)
|
api.Network
|
||||||
|
.RegisterChannel(ClaimLinkVisualizerModSystem.ChannelName)
|
||||||
.RegisterMessageType<ClaimLinkBufferRequest>()
|
.RegisterMessageType<ClaimLinkBufferRequest>()
|
||||||
.RegisterMessageType<ClaimLinkBufferResponse>()
|
.RegisterMessageType<ClaimLinkBufferResponse>()
|
||||||
.SetMessageHandler<ClaimLinkBufferResponse>(OnBufferResponse);
|
.SetMessageHandler<ClaimLinkBufferResponse>(OnBufferResponse);
|
||||||
@@ -26,7 +24,7 @@ internal static class ClaimLinkVisualizerClient
|
|||||||
api.Input.RegisterHotKey(
|
api.Input.RegisterHotKey(
|
||||||
"claimlinkvisualizertoggle",
|
"claimlinkvisualizertoggle",
|
||||||
"Toggle ClaimLink buffer visualization",
|
"Toggle ClaimLink buffer visualization",
|
||||||
GlKeys.R,
|
GlKeys.J,
|
||||||
HotkeyType.CharacterControls,
|
HotkeyType.CharacterControls,
|
||||||
ctrlPressed: true
|
ctrlPressed: true
|
||||||
);
|
);
|
||||||
@@ -37,7 +35,8 @@ internal static class ClaimLinkVisualizerClient
|
|||||||
{
|
{
|
||||||
visible = !visible;
|
visible = !visible;
|
||||||
if (visible)
|
if (visible)
|
||||||
capi.Network.GetChannel(ClaimLinkVisualizerModSystem.ChannelName)
|
capi.Network
|
||||||
|
.GetChannel(ClaimLinkVisualizerModSystem.ChannelName)
|
||||||
.SendPacket(new ClaimLinkBufferRequest());
|
.SendPacket(new ClaimLinkBufferRequest());
|
||||||
else
|
else
|
||||||
Clear();
|
Clear();
|
||||||
@@ -56,11 +55,11 @@ internal static class ClaimLinkVisualizerClient
|
|||||||
{
|
{
|
||||||
int color = HashToColor(entry.GroupId);
|
int color = HashToColor(entry.GroupId);
|
||||||
foreach (BufferCuboidDto cuboid in entry.Cuboids)
|
foreach (BufferCuboidDto cuboid in entry.Cuboids)
|
||||||
{
|
foreach (BlockPos corner in Corners(cuboid))
|
||||||
positions.Add(new BlockPos(cuboid.MinX, cuboid.MinY, cuboid.MinZ));
|
{
|
||||||
positions.Add(new BlockPos(cuboid.MaxX, cuboid.MaxY, cuboid.MaxZ));
|
positions.Add(corner);
|
||||||
colors.Add(color);
|
colors.Add(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
capi.World.HighlightBlocks(
|
capi.World.HighlightBlocks(
|
||||||
@@ -69,7 +68,7 @@ internal static class ClaimLinkVisualizerClient
|
|||||||
positions,
|
positions,
|
||||||
colors,
|
colors,
|
||||||
EnumHighlightBlocksMode.Absolute,
|
EnumHighlightBlocksMode.Absolute,
|
||||||
EnumHighlightShape.Cubes
|
EnumHighlightShape.Arbitrary
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,11 +80,23 @@ internal static class ClaimLinkVisualizerClient
|
|||||||
new List<int>()
|
new List<int>()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private static IEnumerable<BlockPos> Corners(BufferCuboidDto c)
|
||||||
|
{
|
||||||
|
yield return new BlockPos(c.MinX, c.MinY, c.MinZ);
|
||||||
|
yield return new BlockPos(c.MaxX, c.MinY, c.MinZ);
|
||||||
|
yield return new BlockPos(c.MinX, c.MaxY, c.MinZ);
|
||||||
|
yield return new BlockPos(c.MinX, c.MinY, c.MaxZ);
|
||||||
|
yield return new BlockPos(c.MaxX, c.MaxY, c.MinZ);
|
||||||
|
yield return new BlockPos(c.MaxX, c.MinY, c.MaxZ);
|
||||||
|
yield return new BlockPos(c.MinX, c.MaxY, c.MaxZ);
|
||||||
|
yield return new BlockPos(c.MaxX, c.MaxY, c.MaxZ);
|
||||||
|
}
|
||||||
|
|
||||||
private static int HashToColor(int groupId)
|
private static int HashToColor(int groupId)
|
||||||
{
|
{
|
||||||
unchecked
|
unchecked
|
||||||
{
|
{
|
||||||
uint h = (uint)groupId * config.ColorHashSeed;
|
uint h = (uint)groupId * 2654435761u;
|
||||||
int r = (byte)(h >> 16);
|
int r = (byte)(h >> 16);
|
||||||
int g = (byte)(h >> 8);
|
int g = (byte)(h >> 8);
|
||||||
int b = (byte)h;
|
int b = (byte)h;
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace ClaimLinkVisualizer;
|
|
||||||
|
|
||||||
internal class ClaimLinkVisualizerConfig
|
|
||||||
{
|
|
||||||
public uint ColorHashSeed = 2654435761u;
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Vintagestory.API.Client;
|
using Vintagestory.API.Client;
|
||||||
using Vintagestory.API.Common;
|
using Vintagestory.API.Common;
|
||||||
|
using Vintagestory.API.Server;
|
||||||
|
|
||||||
namespace ClaimLinkVisualizer;
|
namespace ClaimLinkVisualizer;
|
||||||
|
|
||||||
@@ -7,6 +8,9 @@ public class ClaimLinkVisualizerModSystem : ModSystem
|
|||||||
{
|
{
|
||||||
internal const string ChannelName = "claimlinkvisualizer";
|
internal const string ChannelName = "claimlinkvisualizer";
|
||||||
|
|
||||||
|
public override void StartServerSide(ICoreServerAPI api) =>
|
||||||
|
ClaimLinkVisualizerServer.Start(api);
|
||||||
|
|
||||||
public override void StartClientSide(ICoreClientAPI api) =>
|
public override void StartClientSide(ICoreClientAPI api) =>
|
||||||
ClaimLinkVisualizerClient.Start(api);
|
ClaimLinkVisualizerClient.Start(api);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using ClaimLink;
|
||||||
|
using Vintagestory.API.MathTools;
|
||||||
|
using Vintagestory.API.Server;
|
||||||
|
|
||||||
|
namespace ClaimLinkVisualizer;
|
||||||
|
|
||||||
|
internal static class ClaimLinkVisualizerServer
|
||||||
|
{
|
||||||
|
internal static void Start(ICoreServerAPI api)
|
||||||
|
{
|
||||||
|
api.Network
|
||||||
|
.RegisterChannel(ClaimLinkVisualizerModSystem.ChannelName)
|
||||||
|
.RegisterMessageType<ClaimLinkBufferRequest>()
|
||||||
|
.RegisterMessageType<ClaimLinkBufferResponse>()
|
||||||
|
.SetMessageHandler<ClaimLinkBufferRequest>((fromPlayer, _) =>
|
||||||
|
SendBuffers(api, fromPlayer)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SendBuffers(ICoreServerAPI api, IServerPlayer toPlayer)
|
||||||
|
{
|
||||||
|
ClaimLinkBufferResponse response = new();
|
||||||
|
|
||||||
|
foreach (var (groupId, cuboids) in ClaimLinkAPI.BufferMap)
|
||||||
|
{
|
||||||
|
ClaimLinkBufferEntryDto entry = new() { GroupId = groupId };
|
||||||
|
foreach (Cuboidi cuboid in cuboids)
|
||||||
|
entry.Cuboids.Add(
|
||||||
|
new BufferCuboidDto
|
||||||
|
{
|
||||||
|
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(ClaimLinkVisualizerModSystem.ChannelName)
|
||||||
|
.SendPacket(response, toPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,13 +3,14 @@
|
|||||||
"type": "Code",
|
"type": "Code",
|
||||||
"modid": "claimlinkvisualizer",
|
"modid": "claimlinkvisualizer",
|
||||||
"name": "ClaimLinkVisualizer",
|
"name": "ClaimLinkVisualizer",
|
||||||
"side": "Client",
|
"side": "Universal",
|
||||||
"authors": [
|
"authors": [
|
||||||
"anth64"
|
"anth64"
|
||||||
],
|
],
|
||||||
"description": "Visualizes ClaimLink buffer zones client-side.",
|
"description": "Visualizes ClaimLink buffer zones client-side.",
|
||||||
"version": "0.1.0",
|
"version": "0.0.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"game": "1.22.5"
|
"game": "1.22.5",
|
||||||
|
"claimlink": "0.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user