diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index 8bdcfd7a2..d49371c40 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -409,8 +409,9 @@ public class CitizensNavigator implements Navigator, Runnable { stopNavigating(CancelReason.STUCK); return true; } - } else + } else { stationaryTicks = 0; + } lastX = current.getBlockX(); lastY = current.getBlockY(); lastZ = current.getBlockZ(); diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java b/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java index db3a10fa1..31b73ecea 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java @@ -226,7 +226,9 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { if (parameters.straightLineTargetingDistance() > 0) { double distance = npc.getStoredLocation().distance(location); if (distance < parameters.straightLineTargetingDistance()) { - active = new StraightLineNavigationStrategy(npc, location, parameters); + if (active == null) { + active = new StraightLineNavigationStrategy(npc, target, parameters); + } return; } } diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/StraightLineNavigationStrategy.java b/main/src/main/java/net/citizensnpcs/npc/ai/StraightLineNavigationStrategy.java index 9f653de5e..2be57d0d3 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/StraightLineNavigationStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/StraightLineNavigationStrategy.java @@ -4,6 +4,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.util.Vector; @@ -17,9 +18,18 @@ import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; public class StraightLineNavigationStrategy extends AbstractPathStrategy { - private final Location destination; + private Location destination; private final NPC npc; private final NavigatorParameters params; + private Entity target; + + public StraightLineNavigationStrategy(NPC npc, Entity target, NavigatorParameters params) { + super(TargetType.LOCATION); + this.params = params; + this.target = target; + this.npc = npc; + this.destination = params.entityTargetLocationMapper().apply(target); + } public StraightLineNavigationStrategy(NPC npc, Location dest, NavigatorParameters params) { super(TargetType.LOCATION); @@ -51,6 +61,9 @@ public class StraightLineNavigationStrategy extends AbstractPathStrategy { if (currLoc.distance(destination) <= params.distanceMargin()) { return true; } + if (target != null) { + destination = params.entityTargetLocationMapper().apply(target); + } Vector destVector = npc.getStoredLocation().toVector() .add(destination.toVector().subtract(npc.getStoredLocation().toVector()).normalize()); Location point = destVector.toLocation(destination.getWorld());