Compare commits

..
3 Commits
5 changed files with 156 additions and 3 deletions

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [0.7.0] - 2026-11-05
### Changed
- Buffer zone visualization now merges overlapping buffer volumes of a claim link into disjoint boxes, so overlapping buffers no longer draw on top of each other.
+5 -1
View File
@@ -163,7 +163,11 @@ internal static class ClaimLinkVisualizerClient
foreach ((int groupId, ClaimLinkBufferEntryDto entry) in knownEntries) foreach ((int groupId, ClaimLinkBufferEntryDto entry) in knownEntries)
{ {
int color = HashToColor(groupId); int color = HashToColor(groupId);
foreach (ClaimLinkBufferCuboidDto cuboid in entry.Cuboids) List<Cuboidi> raw = new();
foreach (ClaimLinkBufferCuboidDto c in entry.Cuboids)
raw.Add(new Cuboidi(c.MinX, c.MinY, c.MinZ, c.MaxX, c.MaxY, c.MaxZ));
foreach (Cuboidi cuboid in CuboidUnion.Merge(raw))
{ {
positions.Add(new BlockPos(cuboid.MinX, cuboid.MinY, cuboid.MinZ)); positions.Add(new BlockPos(cuboid.MinX, cuboid.MinY, cuboid.MinZ));
positions.Add(new BlockPos(cuboid.MaxX, cuboid.MaxY, cuboid.MaxZ)); positions.Add(new BlockPos(cuboid.MaxX, cuboid.MaxY, cuboid.MaxZ));
+137
View File
@@ -0,0 +1,137 @@
using System;
using System.Collections.Generic;
using Vintagestory.API.MathTools;
namespace ClaimLink;
/// <summary>
/// Turns a set of possibly overlapping half-open cuboids into a set of disjoint cuboids covering
/// the same volume, so overlapping boxes render as one continuous shape.
/// </summary>
internal static class CuboidUnion
{
internal static List<Cuboidi> Merge(IEnumerable<Cuboidi> cuboids)
{
List<Cuboidi> result = new();
foreach (Cuboidi cuboid in cuboids)
{
List<Cuboidi> pieces = new() { Normalize(cuboid) };
foreach (Cuboidi existing in result)
{
List<Cuboidi> next = new();
foreach (Cuboidi piece in pieces)
Subtract(piece, existing, next);
pieces = next;
if (pieces.Count == 0)
break;
}
result.AddRange(pieces);
}
Coalesce(result);
return result;
}
private static Cuboidi Normalize(Cuboidi c) =>
new(c.MinX, c.MinY, c.MinZ, c.MaxX, c.MaxY, c.MaxZ);
// Appends the parts of `piece` not covered by `cut` (at most 6 boxes).
private static void Subtract(Cuboidi piece, Cuboidi cut, List<Cuboidi> output)
{
if (
piece.MaxX <= cut.MinX
|| piece.MinX >= cut.MaxX
|| piece.MaxY <= cut.MinY
|| piece.MinY >= cut.MaxY
|| piece.MaxZ <= cut.MinZ
|| piece.MinZ >= cut.MaxZ
)
{
output.Add(piece);
return;
}
int x0 = Math.Max(piece.MinX, cut.MinX);
int x1 = Math.Min(piece.MaxX, cut.MaxX);
int y0 = Math.Max(piece.MinY, cut.MinY);
int y1 = Math.Min(piece.MaxY, cut.MaxY);
int z0 = Math.Max(piece.MinZ, cut.MinZ);
int z1 = Math.Min(piece.MaxZ, cut.MaxZ);
if (piece.MinX < x0)
output.Add(new Cuboidi(piece.MinX, piece.MinY, piece.MinZ, x0, piece.MaxY, piece.MaxZ));
if (piece.MaxX > x1)
output.Add(new Cuboidi(x1, piece.MinY, piece.MinZ, piece.MaxX, piece.MaxY, piece.MaxZ));
if (piece.MinY < y0)
output.Add(new Cuboidi(x0, piece.MinY, piece.MinZ, x1, y0, piece.MaxZ));
if (piece.MaxY > y1)
output.Add(new Cuboidi(x0, y1, piece.MinZ, x1, piece.MaxY, piece.MaxZ));
if (piece.MinZ < z0)
output.Add(new Cuboidi(x0, y0, piece.MinZ, x1, y1, z0));
if (piece.MaxZ > z1)
output.Add(new Cuboidi(x0, y0, z1, x1, y1, piece.MaxZ));
}
// Joins face-adjacent boxes that share the same cross-section, to drop subtraction slivers.
private static void Coalesce(List<Cuboidi> boxes)
{
bool merged;
do
{
merged = false;
for (int i = 0; i < boxes.Count && !merged; i++)
for (int j = i + 1; j < boxes.Count && !merged; j++)
if (TryJoin(boxes[i], boxes[j], out Cuboidi joined))
{
boxes[i] = joined;
boxes.RemoveAt(j);
merged = true;
}
} while (merged);
}
private static bool TryJoin(Cuboidi a, Cuboidi b, out Cuboidi joined)
{
bool sameX = a.MinX == b.MinX && a.MaxX == b.MaxX;
bool sameY = a.MinY == b.MinY && a.MaxY == b.MaxY;
bool sameZ = a.MinZ == b.MinZ && a.MaxZ == b.MaxZ;
if (sameY && sameZ && (a.MaxX == b.MinX || b.MaxX == a.MinX))
joined = new Cuboidi(
Math.Min(a.MinX, b.MinX),
a.MinY,
a.MinZ,
Math.Max(a.MaxX, b.MaxX),
a.MaxY,
a.MaxZ
);
else if (sameX && sameZ && (a.MaxY == b.MinY || b.MaxY == a.MinY))
joined = new Cuboidi(
a.MinX,
Math.Min(a.MinY, b.MinY),
a.MinZ,
a.MaxX,
Math.Max(a.MaxY, b.MaxY),
a.MaxZ
);
else if (sameX && sameY && (a.MaxZ == b.MinZ || b.MaxZ == a.MinZ))
joined = new Cuboidi(
a.MinX,
a.MinY,
Math.Min(a.MinZ, b.MinZ),
a.MaxX,
a.MaxY,
Math.Max(a.MaxZ, b.MaxZ)
);
else
{
joined = null!;
return false;
}
return true;
}
}
+1 -1
View File
@@ -8,7 +8,7 @@
"anth64" "anth64"
], ],
"description": "Link claims together with groups.", "description": "Link claims together with groups.",
"version": "0.6.0", "version": "0.7.0",
"dependencies": { "dependencies": {
"game": "1.22.5" "game": "1.22.5"
} }
-1
View File
@@ -52,4 +52,3 @@ A vanilla claim can be made of multiple cuboid areas (grown one face-adjacent cu
Buffer permissions only cover the empty space around the linked claims, not the claims themselves. In that space, only members of the claim link's group, or anyone explicitly granted access via `allow`/`allowgroup`, can place, break, or use blocks; grant level (`use`/`build`/`all`) controls which. On the ground of a claim that's actually part of the claim link, normal vanilla permissions (owner, claim's group, explicit permission, `AllowUseEveryone`) decide access instead, same as any other claim. Buffer permissions only cover the empty space around the linked claims, not the claims themselves. In that space, only members of the claim link's group, or anyone explicitly granted access via `allow`/`allowgroup`, can place, break, or use blocks; grant level (`use`/`build`/`all`) controls which. On the ground of a claim that's actually part of the claim link, normal vanilla permissions (owner, claim's group, explicit permission, `AllowUseEveryone`) decide access instead, same as any other claim.
See the companion mod [ClaimLinkVisualizer](https://git.forlornoutpost.ca/anth64/ClaimLinkVisualizer) to actually see buffer zones rendered in-world.