mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-30 06:33:56 +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 org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
|
|
||||||
import net.citizensnpcs.Settings.Setting;
|
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.persistence.Persist;
|
||||||
import net.citizensnpcs.api.trait.Trait;
|
import net.citizensnpcs.api.trait.Trait;
|
||||||
import net.citizensnpcs.api.trait.TraitName;
|
import net.citizensnpcs.api.trait.TraitName;
|
||||||
@ -23,6 +26,7 @@ import net.citizensnpcs.api.trait.TraitName;
|
|||||||
public class FollowTrait extends Trait {
|
public class FollowTrait extends Trait {
|
||||||
@Persist("active")
|
@Persist("active")
|
||||||
private boolean enabled = false;
|
private boolean enabled = false;
|
||||||
|
private Flocker flock;
|
||||||
@Persist
|
@Persist
|
||||||
private UUID followingUUID;
|
private UUID followingUUID;
|
||||||
private Player player;
|
private Player player;
|
||||||
@ -48,6 +52,11 @@ public class FollowTrait extends Trait {
|
|||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach() {
|
||||||
|
flock = new Flocker(npc, new RadiusNPCFlock(4, 20), new SeparationBehavior(1));
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
private void onEntityDamage(EntityDamageByEntityEvent event) {
|
private void onEntityDamage(EntityDamageByEntityEvent event) {
|
||||||
if (isActive() && protect && event.getEntity().equals(player)) {
|
if (isActive() && protect && event.getEntity().equals(player)) {
|
||||||
@ -83,6 +92,8 @@ public class FollowTrait extends Trait {
|
|||||||
}
|
}
|
||||||
if (!npc.getNavigator().isNavigating()) {
|
if (!npc.getNavigator().isNavigating()) {
|
||||||
npc.getNavigator().setTarget(player, false);
|
npc.getNavigator().setTarget(player, false);
|
||||||
|
} else {
|
||||||
|
flock.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user