Update Hydrazine library

This commit is contained in:
themode 2021-01-04 21:37:34 +01:00
parent 640521e6dc
commit 5c2b7f38f6
2 changed files with 17 additions and 4 deletions

View File

@ -143,7 +143,7 @@ dependencies {
api "org.spongepowered:mixin:${mixinVersion}"
// Path finding
api 'com.github.MadMartian:hydrazine-path-finding:1.5.1'
api 'com.github.MadMartian:hydrazine-path-finding:1.5.2'
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

View File

@ -86,10 +86,12 @@ public interface NavigableEntity {
* The position is cloned, if you want the entity to continually follow this position object
* you need to call this when you want the path to update.
*
* @param position the position to find the path to, null to reset the pathfinder
* @param position the position to find the path to, null to reset the pathfinder
* @param bestEffort whether to use the best-effort algorithm to the destination,
* if false then this method is more likely to return immediately
* @return true if a path has been found
*/
default boolean setPathTo(@Nullable Position position) {
default boolean setPathTo(@Nullable Position position, boolean bestEffort) {
if (position != null && getPathPosition() != null && position.isSimilar(getPathPosition())) {
// Tried to set path to the same target position
return false;
@ -122,7 +124,11 @@ public interface NavigableEntity {
final Position targetPosition = position.clone();
final IPath path = pathFinder.initiatePathTo(targetPosition.getX(), targetPosition.getY(), targetPosition.getZ());
final IPath path = pathFinder.initiatePathTo(
targetPosition.getX(),
targetPosition.getY(),
targetPosition.getZ(),
bestEffort);
setPath(path);
final boolean success = path != null;
@ -131,6 +137,13 @@ public interface NavigableEntity {
return success;
}
/**
* @see #setPathTo(Position, boolean) with {@code bestEffort} sets to {@code true}.
*/
default boolean setPathTo(@Nullable Position position) {
return setPathTo(position, true);
}
default void pathFindingTick(float speed) {
final Position pathPosition = getPathPosition();
if (pathPosition != null) {