Skip to content

Commit d9f2a26

Browse files
committed
Fix issue where NonEuclid could pick a path for a connecting user that
puts them into a wall.
1 parent 4c9c057 commit d9f2a26

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Diff for: src/main/java/tech/macil/minecraft/noneuclid/Intersection.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,24 @@ boolean isLocationClose(Location loc) {
115115
center.distanceSquared(loc) < maxDistanceSquared;
116116
}
117117

118-
public boolean isInIntersection(Location loc) {
119-
return Math.abs(loc.getX() - center.getX()) <= (double) width / 2 + 1 &&
120-
Math.abs(loc.getZ() - center.getZ()) <= (double) width / 2 + 1;
118+
public boolean isInIntersection(Location loc, boolean includeWalls) {
119+
double maxDistance = (double) width / 2;
120+
if (includeWalls) {
121+
maxDistance += 1;
122+
}
123+
return Math.abs(loc.getX() - center.getX()) <= maxDistance &&
124+
Math.abs(loc.getZ() - center.getZ()) <= maxDistance;
121125
}
122126

123127
public Path getPathForLocation(Location loc, Path previousPath) {
124128
if (!isLocationClose(loc)) {
125129
return null;
126130
}
127131
assert loc.getWorld() == center.getWorld();
128-
if (isInIntersection(loc)) {
132+
// If we don't have a previous path, then don't consider the walls as
133+
// part of the intersection, so that way players connecting will never
134+
// be started inside of a wall.
135+
if (isInIntersection(loc, previousPath != null)) {
129136
return previousPath == null ? getDefaultPath() : previousPath;
130137
}
131138
boolean a1 = loc.getZ() > loc.getX() + center.getZ() - center.getX();

Diff for: src/main/java/tech/macil/minecraft/noneuclid/NonEuclidPlugin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private void renderForPlayer(Player player, boolean forceRender) {
215215
disablePacketRewriting = false;
216216
}
217217

218-
boolean newInIntersection = newPath != null && intersection.isInIntersection(playerLoc);
218+
boolean newInIntersection = newPath != null && intersection.isInIntersection(playerLoc, true);
219219
boolean exitedIntersection = playersInIntersection.contains(player) && (
220220
oldPath != newPath || !newInIntersection
221221
);

0 commit comments

Comments
 (0)