Skip to content

Commit ac5002a

Browse files
committed
Change dynmap claim grouping to use the same algorithm as the other maps
1 parent 5218c9a commit ac5002a

2 files changed

Lines changed: 29 additions & 133 deletions

File tree

src/main/java/io/icker/factions/util/ClaimGrouper.java

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -249,103 +249,4 @@ public static List<List<Vector2i>> convertLineSegmentsToOutlines(
249249

250250
return holes;
251251
}
252-
253-
/**
254-
* Takes a list of all claims in a level and groups them using BFS. While doing that it measures
255-
* all the sides of all the claims that are on a border from claimed territory and wilderness.
256-
*
257-
* <p>The returned segments are directional.
258-
*
259-
* <p>As opposed to @see ClaimGrouper#convertClaimsToLineSegmentGroups(), this function also
260-
* creates line segments to bridge the gap between the outside outline and any inner holes. This
261-
* is need by dymap because dynmap doesn't support holes in markers.
262-
*
263-
* @param claims A set of vectors that represents the coordinates of a claim (@see
264-
* ClaimGrouper#separateClaimsByLevel())
265-
* @return A list of edges. The edges are returned as a map where the entries represent one
266-
* corner of a claim and the values are other corners in connects too. The list has either
267-
* one or two elements.
268-
*/
269-
public static List<Map<Vector2i, Vector2i[]>> convertClaimsToLineSegmentGroupsWithoutHoles(
270-
Set<Vector2i> claims) {
271-
Set<Vector2i> remaining_claims = new HashSet<>(claims);
272-
Queue<Vector2i> queue = new LinkedList<>();
273-
List<Map<Vector2i, Vector2i[]>> groups = new ArrayList<>();
274-
275-
while (!remaining_claims.isEmpty()) {
276-
Iterator<Vector2i> iter = remaining_claims.iterator();
277-
Vector2i item = iter.next();
278-
queue.add(item);
279-
remaining_claims.remove(item);
280-
281-
Map<Vector2i, Vector2i[]> lines = new HashMap<>();
282-
283-
while (!queue.isEmpty()) {
284-
Vector2i claim = queue.remove();
285-
286-
for (Vector2i dir :
287-
new Vector2i[] {
288-
new Vector2i(1, 0),
289-
new Vector2i(-1, 0),
290-
new Vector2i(0, 1),
291-
new Vector2i(0, -1)
292-
}) {
293-
Vector2i new_claim = claim.add(dir);
294-
// The BFS part
295-
if (remaining_claims.contains(new_claim)) {
296-
queue.add(new_claim);
297-
remaining_claims.remove(new_claim);
298-
} else {
299-
Vector2i start; // both of these are in block coordinates
300-
Vector2i end;
301-
302-
if (dir.getX() == 0) {
303-
// the y component is being used as the x component so that the
304-
// direction is correct
305-
start = claim.mul(16).add(new Vector2i(dir.getY(), dir.getY()).mul(8));
306-
end = claim.mul(16).add(new Vector2i(-dir.getY(), dir.getY()).mul(8));
307-
} else {
308-
start = claim.mul(16).add(new Vector2i(dir.getX(), -dir.getX()).mul(8));
309-
end = claim.mul(16).add(new Vector2i(dir.getX(), dir.getX()).mul(8));
310-
}
311-
312-
start =
313-
start.add(
314-
new Vector2i(
315-
8,
316-
8)); // offset to match how minecraft converts chunk
317-
// coords to block coords
318-
end = end.add(new Vector2i(8, 8));
319-
320-
boolean has_opposite_line = false;
321-
322-
if (lines.containsKey(end)) {
323-
for (Vector2i possible_start : lines.get(end)) {
324-
if (possible_start.equals(start)) {
325-
has_opposite_line = true;
326-
}
327-
}
328-
}
329-
330-
if (!has_opposite_line
331-
&& claims.contains(new_claim)
332-
&& !(queue.contains(new_claim)
333-
|| remaining_claims.contains(new_claim))) {
334-
continue;
335-
}
336-
337-
if (lines.containsKey(start)) {
338-
lines.put(start, new Vector2i[] {lines.get(start)[0], end});
339-
} else {
340-
lines.put(start, new Vector2i[] {end});
341-
}
342-
}
343-
}
344-
}
345-
346-
groups.add(lines);
347-
}
348-
349-
return groups;
350-
}
351252
}

src/main/java/io/icker/factions/util/DynmapWrapper.java

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -125,42 +125,37 @@ private void generateMarkers() {
125125
ClaimGrouper.separateClaimsByLevel(faction).entrySet()) {
126126
String level = entry.getKey();
127127
for (Map<Vector2i, Vector2i[]> group :
128-
ClaimGrouper.convertClaimsToLineSegmentGroupsWithoutHoles(
128+
ClaimGrouper.convertClaimsToLineSegmentGroups(
129129
entry.getValue())) {
130-
List<List<Vector2i>> outlines =
131-
ClaimGrouper.convertLineSegmentsToOutlines(group);
132-
if (outlines.size() > 1) {
133-
FactionsMod.LOGGER.error(
134-
"The claim chunking algorithm used for dynmap has failed, please"
135-
+ " report this asap.");
136-
}
137-
outlines.getFirst().add(outlines.getFirst().getFirst());
138-
double[] x_coords =
139-
outlines.getFirst().stream()
140-
.mapToDouble((point) -> (double) point.getX())
141-
.toArray();
142-
double[] z_coords =
143-
outlines.getFirst().stream()
144-
.mapToDouble((point) -> (double) point.getY())
145-
.toArray();
146-
double[] y_coords =
147-
outlines.getFirst().stream().mapToDouble((point) -> 320.0).toArray();
130+
for (List<Vector2i> outline : ClaimGrouper.convertLineSegmentsToOutlines(group)) {
131+
outline.add(outline.get(0));
132+
double[] x_coords =
133+
outline.stream()
134+
.mapToDouble((point) -> (double) point.getX())
135+
.toArray();
136+
double[] z_coords =
137+
outline.stream()
138+
.mapToDouble((point) -> (double) point.getY())
139+
.toArray();
140+
double[] y_coords =
141+
outline.stream().mapToDouble((point) -> 320.0).toArray();
148142

149-
PolyLineMarker marker =
150-
markerSet.createPolyLineMarker(
151-
UUID.randomUUID().toString(),
152-
"",
153-
false,
154-
dimensionTagToID(level),
155-
x_coords,
156-
y_coords,
157-
z_coords,
158-
true);
159-
if (marker != null) {
160-
marker.setLineStyle(
161-
marker.getLineWeight(),
162-
marker.getLineOpacity(),
163-
faction.getColor().getColorValue());
143+
PolyLineMarker marker =
144+
markerSet.createPolyLineMarker(
145+
UUID.randomUUID().toString(),
146+
"",
147+
false,
148+
dimensionTagToID(level),
149+
x_coords,
150+
y_coords,
151+
z_coords,
152+
true);
153+
if (marker != null) {
154+
marker.setLineStyle(
155+
marker.getLineWeight(),
156+
marker.getLineOpacity(),
157+
faction.getColor().getColorValue());
158+
}
164159
}
165160
}
166161
}

0 commit comments

Comments
 (0)