Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 52 additions & 5 deletions common/src/main/java/dev/ryanhcode/sable/ActiveSableCompanion.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,20 @@ public <S extends SubLevelAccess> boolean findIncludingSubLevels(final Level lev
);
}

@Override
public double distanceSquaredWithSubLevels(final Level level, final Vector3dc a, final Vector3dc b) {
final Vector3dc globalA = this.projectOutOfSubLevel(level, a, new Vector3d());
final Vector3dc globalB = this.projectOutOfSubLevel(level, b, new Vector3d());

return globalA.distanceSquared(globalB);
}

@Override
public double distanceSquaredWithSubLevels(final Level level, final Position a, final Position b) {
final Vec3 globalA = this.projectOutOfSubLevel(level, a);
final Vec3 globalB = this.projectOutOfSubLevel(level, b);
final Vector3dc globalA = this.projectOutOfSubLevel(level, JOMLConversion.toJOML(a));
final Vector3dc globalB = this.projectOutOfSubLevel(level, JOMLConversion.toJOML(b));

return globalA.distanceToSqr(globalB);
return globalA.distanceSquared(globalB);
}

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

private static double rectilinearDistance(final Vector3dc a, final Vector3dc b) {
final double d0 = Math.abs(b.x() - a.x());
final double d1 = Math.abs(b.y() - a.y());
final double d2 = Math.abs(b.z() - a.z());
return Math.max(d0, Math.max(d1, d2));
}

@Override
public double distanceSquaredWithSubLevels(final Level level, final Vector3dc a, final Vector3dc b) {
public double rectilinearDistanceWithSubLevels(final Level level, final Vector3dc a, final Vector3dc b) {
final Vector3dc globalA = this.projectOutOfSubLevel(level, a, new Vector3d());
final Vector3dc globalB = this.projectOutOfSubLevel(level, b, new Vector3d());

return globalA.distanceSquared(globalB);
return rectilinearDistance(globalA, globalB);
}

@Override
public double rectilinearDistanceWithSubLevels(final Level level, final Position a, final Position b) {
final Vector3dc globalA = this.projectOutOfSubLevel(level, JOMLConversion.toJOML(a));
final Vector3dc globalB = this.projectOutOfSubLevel(level, JOMLConversion.toJOML(b));

return rectilinearDistance(globalA, globalB);
}

@Override
public double rectilinearDistanceWithSubLevels(final Level level, final Vector3dc a, final double bX, final double bY, final double bZ) {
final Vector3dc globalA = this.projectOutOfSubLevel(level, a, new Vector3d());
final Vector3dc globalB = this.projectOutOfSubLevel(level, new Vector3d(bX, bY, bZ));

return rectilinearDistance(globalA, globalB);
}

@Override
public double rectilinearDistanceWithSubLevels(final Level level, final Position a, final double bX, final double bY, final double bZ) {
final Vector3dc globalA = this.projectOutOfSubLevel(level, JOMLConversion.toJOML(a));
final Vector3dc globalB = this.projectOutOfSubLevel(level, new Vector3d(bX, bY, bZ));

return rectilinearDistance(globalA, globalB);
}

@Override
public double rectilinearDistanceWithSubLevels(final Level level, final double aX, final double aY, final double aZ, final double bX, final double bY, final double bZ) {
final Vector3dc globalA = this.projectOutOfSubLevel(level, new Vector3d(aX, aY, aZ));
final Vector3dc globalB = this.projectOutOfSubLevel(level, new Vector3d(bX, bY, bZ));

return rectilinearDistance(globalA, globalB);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ neoforge_version=21.1.219
neoforge_loader_version_range=[4,)

# Dependencies
sable_companion_version=1.5.0
sable_companion_version=1.6.0
forgeconfigapiport_version=21.1.3
veil_version=3.6.2

Expand Down
Loading