mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-23 02:55:45 +01:00
Add a separation mechanic to /npc follow
This commit is contained in:
parent
52a004fcaf
commit
65d02398fb
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user