From 65d02398fb927992f79492954e9d39a3376dd929 Mon Sep 17 00:00:00 2001 From: fullwall Date: Thu, 4 Feb 2021 16:34:20 +0800 Subject: [PATCH] Add a separation mechanic to /npc follow --- .../main/java/net/citizensnpcs/trait/FollowTrait.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main/src/main/java/net/citizensnpcs/trait/FollowTrait.java b/main/src/main/java/net/citizensnpcs/trait/FollowTrait.java index 5ac688f37..fa38f7e87 100644 --- a/main/src/main/java/net/citizensnpcs/trait/FollowTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/FollowTrait.java @@ -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(); } }