Add a separation mechanic to /npc follow

This commit is contained in:
fullwall 2021-02-04 16:34:20 +08:00
parent 52a004fcaf
commit 65d02398fb

View File

@ -12,6 +12,9 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.ai.flocking.Flocker;
import net.citizensnpcs.api.ai.flocking.RadiusNPCFlock;
import net.citizensnpcs.api.ai.flocking.SeparationBehavior;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
@ -23,6 +26,7 @@ import net.citizensnpcs.api.trait.TraitName;
public class FollowTrait extends Trait {
@Persist("active")
private boolean enabled = false;
private Flocker flock;
@Persist
private UUID followingUUID;
private Player player;
@ -48,6 +52,11 @@ public class FollowTrait extends Trait {
return enabled;
}
@Override
public void onAttach() {
flock = new Flocker(npc, new RadiusNPCFlock(4, 20), new SeparationBehavior(1));
}
@EventHandler
private void onEntityDamage(EntityDamageByEntityEvent event) {
if (isActive() && protect && event.getEntity().equals(player)) {
@ -83,6 +92,8 @@ public class FollowTrait extends Trait {
}
if (!npc.getNavigator().isNavigating()) {
npc.getNavigator().setTarget(player, false);
} else {
flock.run();
}
}