mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-07 00:48:28 +01:00
Updated FollowTargetGoal.java
This commit is contained in:
parent
30abfce554
commit
d522730cd7
@ -6,12 +6,13 @@ import net.minestom.server.entity.ai.GoalSelector;
|
|||||||
import net.minestom.server.entity.pathfinding.Navigator;
|
import net.minestom.server.entity.pathfinding.Navigator;
|
||||||
import net.minestom.server.utils.MathUtils;
|
import net.minestom.server.utils.MathUtils;
|
||||||
import net.minestom.server.utils.Position;
|
import net.minestom.server.utils.Position;
|
||||||
import net.minestom.server.utils.time.UpdateOption;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
public class FollowTargetGoal extends GoalSelector {
|
public class FollowTargetGoal extends GoalSelector {
|
||||||
|
|
||||||
private final UpdateOption pathUpdateOption;
|
private final Duration pathDuration;
|
||||||
private long lastUpdateTime = 0;
|
private long lastUpdateTime = 0;
|
||||||
private boolean forceEnd = false;
|
private boolean forceEnd = false;
|
||||||
private Position lastTargetPos;
|
private Position lastTargetPos;
|
||||||
@ -21,10 +22,24 @@ public class FollowTargetGoal extends GoalSelector {
|
|||||||
*
|
*
|
||||||
* @param entityCreature the entity
|
* @param entityCreature the entity
|
||||||
* @param pathUpdateOption the time between each path update (to check if the target moved)
|
* @param pathUpdateOption the time between each path update (to check if the target moved)
|
||||||
|
*
|
||||||
|
* @deprecated Replaced by {@link #FollowTargetGoal(EntityCreature, Duration)}
|
||||||
*/
|
*/
|
||||||
public FollowTargetGoal(@NotNull EntityCreature entityCreature, @NotNull UpdateOption pathUpdateOption) {
|
@SuppressWarnings("removal")
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
|
public FollowTargetGoal(@NotNull EntityCreature entityCreature, @NotNull net.minestom.server.utils.time.UpdateOption pathUpdateOption) {
|
||||||
|
this(entityCreature, pathUpdateOption.toDuration());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a follow target goal object.
|
||||||
|
*
|
||||||
|
* @param entityCreature the entity
|
||||||
|
* @param pathDuration the time between each path update (to check if the target moved)
|
||||||
|
*/
|
||||||
|
public FollowTargetGoal(@NotNull EntityCreature entityCreature, @NotNull Duration pathDuration) {
|
||||||
super(entityCreature);
|
super(entityCreature);
|
||||||
this.pathUpdateOption = pathUpdateOption;
|
this.pathDuration = pathDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -64,8 +79,8 @@ public class FollowTargetGoal extends GoalSelector {
|
|||||||
@Override
|
@Override
|
||||||
public void tick(long time) {
|
public void tick(long time) {
|
||||||
if (forceEnd ||
|
if (forceEnd ||
|
||||||
pathUpdateOption.getValue() == 0 ||
|
pathDuration.isZero() ||
|
||||||
pathUpdateOption.getTimeUnit().toMilliseconds(pathUpdateOption.getValue()) + lastUpdateTime > time) {
|
pathDuration.toMillis() + lastUpdateTime > time) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Position targetPos = entityCreature.getTarget() != null ? entityCreature.getTarget().getPosition() : null;
|
Position targetPos = entityCreature.getTarget() != null ? entityCreature.getTarget().getPosition() : null;
|
||||||
|
Loading…
Reference in New Issue
Block a user