Skip to content

Commit dce0e4d

Browse files
authored
Update sable companion to 1.6.0 (#426)
Adds support for rectilinear distance (the maximum of x, y, or z distance). Some mods prefer this distance over cartesian distance. **This requires sable companion `1.6.0` to be published to the maven before it can be merged**
1 parent 7b3abe9 commit dce0e4d

2 files changed

Lines changed: 53 additions & 6 deletions

File tree

common/src/main/java/dev/ryanhcode/sable/ActiveSableCompanion.java

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,20 @@ public <S extends SubLevelAccess> boolean findIncludingSubLevels(final Level lev
269269
);
270270
}
271271

272+
@Override
273+
public double distanceSquaredWithSubLevels(final Level level, final Vector3dc a, final Vector3dc b) {
274+
final Vector3dc globalA = this.projectOutOfSubLevel(level, a, new Vector3d());
275+
final Vector3dc globalB = this.projectOutOfSubLevel(level, b, new Vector3d());
276+
277+
return globalA.distanceSquared(globalB);
278+
}
279+
272280
@Override
273281
public double distanceSquaredWithSubLevels(final Level level, final Position a, final Position b) {
274-
final Vec3 globalA = this.projectOutOfSubLevel(level, a);
275-
final Vec3 globalB = this.projectOutOfSubLevel(level, b);
282+
final Vector3dc globalA = this.projectOutOfSubLevel(level, JOMLConversion.toJOML(a));
283+
final Vector3dc globalB = this.projectOutOfSubLevel(level, JOMLConversion.toJOML(b));
276284

277-
return globalA.distanceToSqr(globalB);
285+
return globalA.distanceSquared(globalB);
278286
}
279287

280288
@Override
@@ -301,12 +309,51 @@ public double distanceSquaredWithSubLevels(final Level level, final double aX, f
301309
return globalA.distanceSquared(globalB);
302310
}
303311

312+
private static double rectilinearDistance(final Vector3dc a, final Vector3dc b) {
313+
final double d0 = Math.abs(b.x() - a.x());
314+
final double d1 = Math.abs(b.y() - a.y());
315+
final double d2 = Math.abs(b.z() - a.z());
316+
return Math.max(d0, Math.max(d1, d2));
317+
}
318+
304319
@Override
305-
public double distanceSquaredWithSubLevels(final Level level, final Vector3dc a, final Vector3dc b) {
320+
public double rectilinearDistanceWithSubLevels(final Level level, final Vector3dc a, final Vector3dc b) {
306321
final Vector3dc globalA = this.projectOutOfSubLevel(level, a, new Vector3d());
307322
final Vector3dc globalB = this.projectOutOfSubLevel(level, b, new Vector3d());
308323

309-
return globalA.distanceSquared(globalB);
324+
return rectilinearDistance(globalA, globalB);
325+
}
326+
327+
@Override
328+
public double rectilinearDistanceWithSubLevels(final Level level, final Position a, final Position b) {
329+
final Vector3dc globalA = this.projectOutOfSubLevel(level, JOMLConversion.toJOML(a));
330+
final Vector3dc globalB = this.projectOutOfSubLevel(level, JOMLConversion.toJOML(b));
331+
332+
return rectilinearDistance(globalA, globalB);
333+
}
334+
335+
@Override
336+
public double rectilinearDistanceWithSubLevels(final Level level, final Vector3dc a, final double bX, final double bY, final double bZ) {
337+
final Vector3dc globalA = this.projectOutOfSubLevel(level, a, new Vector3d());
338+
final Vector3dc globalB = this.projectOutOfSubLevel(level, new Vector3d(bX, bY, bZ));
339+
340+
return rectilinearDistance(globalA, globalB);
341+
}
342+
343+
@Override
344+
public double rectilinearDistanceWithSubLevels(final Level level, final Position a, final double bX, final double bY, final double bZ) {
345+
final Vector3dc globalA = this.projectOutOfSubLevel(level, JOMLConversion.toJOML(a));
346+
final Vector3dc globalB = this.projectOutOfSubLevel(level, new Vector3d(bX, bY, bZ));
347+
348+
return rectilinearDistance(globalA, globalB);
349+
}
350+
351+
@Override
352+
public double rectilinearDistanceWithSubLevels(final Level level, final double aX, final double aY, final double aZ, final double bX, final double bY, final double bZ) {
353+
final Vector3dc globalA = this.projectOutOfSubLevel(level, new Vector3d(aX, aY, aZ));
354+
final Vector3dc globalB = this.projectOutOfSubLevel(level, new Vector3d(bX, bY, bZ));
355+
356+
return rectilinearDistance(globalA, globalB);
310357
}
311358

312359
@Override

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ neoforge_version=21.1.219
3030
neoforge_loader_version_range=[4,)
3131

3232
# Dependencies
33-
sable_companion_version=1.5.0
33+
sable_companion_version=1.6.0
3434
forgeconfigapiport_version=21.1.3
3535
veil_version=3.6.2
3636

0 commit comments

Comments
 (0)