mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-26 12:46:04 +01:00
Propagate navigation targets down the mount stack
This commit is contained in:
parent
1a891ecd75
commit
f4c28e9085
@ -136,10 +136,12 @@ public class CitizensNavigator implements Navigator, Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
updateMountedStatus();
|
||||
if (!isNavigating() || !npc.isSpawned() || paused)
|
||||
return;
|
||||
if (updateStationaryStatus())
|
||||
return;
|
||||
|
||||
updatePathfindingRange();
|
||||
boolean finished = executing.update();
|
||||
if (!finished) {
|
||||
@ -274,6 +276,26 @@ public class CitizensNavigator implements Navigator, Runnable {
|
||||
Bukkit.getPluginManager().callEvent(new NavigationBeginEvent(this));
|
||||
}
|
||||
|
||||
private void updateMountedStatus() {
|
||||
if (!isNavigating())
|
||||
return;
|
||||
Entity vehicle = NMS.getBukkitVehicle(npc.getEntity());
|
||||
if (!(vehicle instanceof NPCHolder))
|
||||
return;
|
||||
cancelNavigation();
|
||||
NPC mount = ((NPCHolder) vehicle).getNPC();
|
||||
switch (getTargetType()) {
|
||||
case ENTITY:
|
||||
mount.getNavigator().setTarget(getEntityTarget().getTarget(), getEntityTarget().isAggressive());
|
||||
break;
|
||||
case LOCATION:
|
||||
mount.getNavigator().setTarget(getTargetAsLocation());
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePathfindingRange() {
|
||||
NMS.updatePathfindingRange(npc, localParams.range());
|
||||
}
|
||||
|
@ -66,8 +66,8 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity getTarget() {
|
||||
return (LivingEntity) target.getBukkitEntity();
|
||||
public org.bukkit.entity.Entity getTarget() {
|
||||
return target.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -123,9 +123,11 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
|
||||
NMS.look(handle, target);
|
||||
if (aggro && canAttack()) {
|
||||
AttackStrategy strategy = parameters.attackStrategy();
|
||||
if (strategy != null && strategy.handle((LivingEntity) handle.getBukkitEntity(), getTarget())) {
|
||||
if (strategy != null
|
||||
&& strategy.handle((LivingEntity) handle.getBukkitEntity(), (LivingEntity) getTarget())) {
|
||||
} else if (strategy != parameters.defaultAttackStrategy()) {
|
||||
parameters.defaultAttackStrategy().handle((LivingEntity) handle.getBukkitEntity(), getTarget());
|
||||
parameters.defaultAttackStrategy().handle((LivingEntity) handle.getBukkitEntity(),
|
||||
(LivingEntity) getTarget());
|
||||
}
|
||||
attackTicks = parameters.attackDelayTicks();
|
||||
}
|
||||
|
@ -365,6 +365,11 @@ public class NMS {
|
||||
entity.aG += entity.aF;
|
||||
}
|
||||
|
||||
public static org.bukkit.entity.Entity getBukkitVehicle(org.bukkit.entity.Entity entity) {
|
||||
Entity vehicle = getVehicle(entity);
|
||||
return vehicle == null ? null : vehicle.getBukkitEntity();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static Constructor<?> getCustomEntityConstructor(Class<?> clazz, EntityType type)
|
||||
throws SecurityException, NoSuchMethodException {
|
||||
@ -510,6 +515,10 @@ public class NMS {
|
||||
return navigation.n();
|
||||
}
|
||||
|
||||
public static boolean isPassenger(org.bukkit.entity.Entity entity) {
|
||||
return NMS.getHandle(entity).isPassenger();
|
||||
}
|
||||
|
||||
public static void loadPlugins() {
|
||||
((CraftServer) Bukkit.getServer()).enablePlugins(PluginLoadOrder.POSTWORLD);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user