Cancel follow navigation if parameters are changed
This commit is contained in:
parent
95d678312b
commit
a5fea96114
|
@ -37,15 +37,19 @@ public class FollowTrait extends Trait {
|
||||||
super("followtrait");
|
super("followtrait");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void cancelNavigationIfActive() {
|
||||||
|
if (npc.getNavigator().isNavigating() && this.entity != null && npc.getNavigator().getEntityTarget() != null
|
||||||
|
&& this.entity == npc.getNavigator().getEntityTarget().getTarget()) {
|
||||||
|
npc.getNavigator().cancelNavigation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the {@link Entity} to follow
|
* Sets the {@link Entity} to follow
|
||||||
*/
|
*/
|
||||||
public void follow(Entity entity) {
|
public void follow(Entity entity) {
|
||||||
followingUUID = entity == null ? null : entity.getUniqueId();
|
followingUUID = entity == null ? null : entity.getUniqueId();
|
||||||
if (npc.getNavigator().isNavigating() && this.entity != null && npc.getNavigator().getEntityTarget() != null
|
cancelNavigationIfActive();
|
||||||
&& this.entity == npc.getNavigator().getEntityTarget().getTarget()) {
|
|
||||||
npc.getNavigator().cancelNavigation();
|
|
||||||
}
|
|
||||||
this.entity = null;
|
this.entity = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +93,7 @@ public class FollowTrait extends Trait {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSpawn() {
|
public void onSpawn() {
|
||||||
flock = new Flocker(npc, new RadiusNPCFlock(4, 0), new SeparationBehavior(1));
|
flock = new Flocker(npc, new RadiusNPCFlock(4, 4), new SeparationBehavior(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -125,6 +129,7 @@ public class FollowTrait extends Trait {
|
||||||
|
|
||||||
public void setFollowingMargin(double margin) {
|
public void setFollowingMargin(double margin) {
|
||||||
this.margin = margin;
|
this.margin = margin;
|
||||||
|
cancelNavigationIfActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,5 +137,6 @@ public class FollowTrait extends Trait {
|
||||||
*/
|
*/
|
||||||
public void setProtect(boolean protect) {
|
public void setProtect(boolean protect) {
|
||||||
this.protect = protect;
|
this.protect = protect;
|
||||||
|
cancelNavigationIfActive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue