Rework mounted pathfinding

This commit is contained in:
fullwall 2020-05-12 20:28:41 +08:00
parent a044eed988
commit c1a89984a3
18 changed files with 36 additions and 37 deletions

View File

@ -433,7 +433,7 @@ public class NPCCommands {
throw new NoPermissionsException();
npc = CitizensAPI.getNPCRegistry().createNPC(type, name);
String msg = "You created [[" + npc.getName() + "]]";
String msg = "You created [[" + npc.getName() + "]] (ID [[" + npc.getId() + "]])";
int age = 0;
if (args.hasFlag('b')) {
@ -857,11 +857,11 @@ public class NPCCommands {
}
Paginator paginator = new Paginator().header("NPCs").console(sender instanceof ConsoleCommandSender);
paginator.addLine("<e>Key: <a>ID <b>Name");
paginator.addLine("<b>Key: <e>ID <a>Name");
for (int i = 0; i < npcs.size(); i += 2) {
String line = "<a>" + npcs.get(i).getId() + "<b> " + npcs.get(i).getName();
String line = "<e>" + npcs.get(i).getId() + "<a> " + npcs.get(i).getName();
if (npcs.size() >= i + 2)
line += " " + "<a>" + npcs.get(i + 1).getId() + "<b> " + npcs.get(i + 1).getName();
line += " " + "<e>" + npcs.get(i + 1).getId() + "<a> " + npcs.get(i + 1).getName();
paginator.addLine(line);
}

View File

@ -345,13 +345,17 @@ public class CitizensNavigator implements Navigator, Runnable {
}
private void updateMountedStatus() {
if (!isNavigating())
// TODO: this method seems to break assumptions: better to let the NPC pathfind for itself rather than
// "commanding" the NPC below on the stack
if (!isNavigating() || true)
return;
Entity vehicle = NMS.getVehicle(npc.getEntity());
if (!(vehicle instanceof NPCHolder)) {
return;
}
NPC mount = ((NPCHolder) vehicle).getNPC();
if (mount.getNavigator().isNavigating())
return;
switch (getTargetType()) {
case ENTITY:
mount.getNavigator().setTarget(getEntityTarget().getTarget(), getEntityTarget().isAggressive());
@ -373,7 +377,7 @@ public class CitizensNavigator implements Navigator, Runnable {
if (localParams.stationaryTicks() < 0)
return false;
Location current = npc.getEntity().getLocation(STATIONARY_LOCATION);
if (current.getY() < -5) {
if (current.getY() < -6) {
stopNavigating(CancelReason.STUCK);
return true;
}

View File

@ -70,8 +70,9 @@ public class TabListRemover {
skinnable.getSkinTracker().notifyRemovePacketCancelled(player.getUniqueId());
}
if (entry.toRemove.isEmpty())
if (entry.toRemove.isEmpty()) {
pending.remove(player.getUniqueId());
}
}
private PlayerEntry getEntry(Player player) {

View File

@ -195,7 +195,7 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
if (!enabled || !npc.isSpawned())
return;
List<Entity> passengers = NMS.getPassengers(npc.getEntity());
if (passengers.size() == 0 || !(passengers.get(0) instanceof Player))
if (passengers.size() == 0 || !(passengers.get(0) instanceof Player) || npc.getNavigator().isNavigating())
return;
controller.run((Player) passengers.get(0));
}

View File

@ -137,7 +137,7 @@ citizens.commands.npc.pathopt.stationary-ticks-set=[[{0}]]''s maximum stationary
citizens.commands.npc.pathopt.distance-margin-set=[[{0}]]''s pathfinding distance margin set to [[{1}]].
citizens.commands.npc.pathopt.path-distance-margin-set=[[{0}]]''s pathfinding path distance margin set to [[{1}]].
citizens.commands.npc.pathopt.attack-range-set=[[{0}]]''s attack range set to [[{1}]].
citizens.commands.npc.pathopt.use-new-finder=[[{0}]]'' use new finder set to [[{1}]].
citizens.commands.npc.pathopt.use-new-finder=[[{0}]]''s use new finder set to [[{1}]].
citizens.commands.npc.playerlist.added=Added [[{0}]] to the player list.
citizens.commands.npc.playerlist.removed=Removed [[{0}]] from the player list.
citizens.commands.npc.pose.added=Pose added.
@ -307,7 +307,7 @@ citizens.editors.waypoints.guided.added-guide=Added a [[guide]] waypoint. This w
citizens.editors.waypoints.guided.added-available=Added a [[destination]] waypoint. This will be available for NPCs to path to.
citizens.editors.waypoints.guided.already-taken=There is already a waypoint here.
citizens.editors.waypoints.linear.added-waypoint=[[Added]] a waypoint at ({0}) ([[{1}]], [[{2}]]).
citizens.editors.waypoints.linear.begin=<b>Entered the linear waypoint editor!<br> [[Left click]] to add a waypoint, [[right click]] to remove.<br> Type [[toggle path]] to toggle showing entities at waypoints, [[triggers]] to enter the trigger editor and [[clear]] to clear all waypoints.
citizens.editors.waypoints.linear.begin=<b>Entered the <l>linear waypoint editor!<br> [[Left click]] to add a waypoint, [[right click]] to remove.<br> Type [[toggle path]] to toggle showing entities at waypoints,<br> [[triggers]] to enter the trigger editor,<br> [[clear]] to clear all waypoints.
citizens.editors.waypoints.linear.edit-slot-set=Editing slot set to [[{0}]] ({1}).
citizens.editors.waypoints.linear.end=Exited the linear waypoint editor.
citizens.editors.waypoints.linear.not-showing-markers=[[Stopped]] showing waypoint markers.

View File

@ -45,9 +45,7 @@ public class HorseDonkeyController extends MobEntityController {
public static class EntityHorseDonkeyNPC extends EntityHorseDonkey implements NPCHolder {
private double baseMovementSpeed;
private final CitizensNPC npc;
private boolean riding;
public EntityHorseDonkeyNPC(World world) {

View File

@ -45,9 +45,7 @@ public class HorseSkeletonController extends MobEntityController {
public static class EntityHorseSkeletonNPC extends EntityHorseSkeleton implements NPCHolder {
private double baseMovementSpeed;
private final CitizensNPC npc;
private boolean riding;
public EntityHorseSkeletonNPC(World world) {

View File

@ -45,9 +45,7 @@ public class HorseZombieController extends MobEntityController {
public static class EntityHorseZombieNPC extends EntityHorseZombie implements NPCHolder {
private double baseMovementSpeed;
private final CitizensNPC npc;
private boolean riding;
public EntityHorseZombieNPC(World world) {

View File

@ -233,8 +233,8 @@ public class HorseController extends MobEntityController {
riding = false;
}
if (riding) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
if (basePassenger instanceof NPCHolder) {
if (npc.getNavigator().isNavigating()) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
NMS.look(basePassenger, yaw, pitch);
}
d(4, true); // datawatcher method

View File

@ -232,8 +232,8 @@ public class HorseDonkeyController extends MobEntityController {
riding = false;
}
if (riding) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
if (basePassenger instanceof NPCHolder) {
if (npc.getNavigator().isNavigating()) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
NMS.look(basePassenger, yaw, pitch);
}
d(4, true); // datawatcher method

View File

@ -232,8 +232,8 @@ public class HorseMuleController extends MobEntityController {
riding = false;
}
if (riding) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
if (basePassenger instanceof NPCHolder) {
if (npc.getNavigator().isNavigating()) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
NMS.look(basePassenger, yaw, pitch);
}
d(4, true); // datawatcher method

View File

@ -233,8 +233,8 @@ public class HorseSkeletonController extends MobEntityController {
riding = false;
}
if (riding) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
if (basePassenger instanceof NPCHolder) {
if (npc.getNavigator().isNavigating()) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
NMS.look(basePassenger, yaw, pitch);
}
d(4, true); // datawatcher method

View File

@ -233,8 +233,8 @@ public class HorseZombieController extends MobEntityController {
riding = false;
}
if (riding) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
if (basePassenger instanceof NPCHolder) {
if (npc.getNavigator().isNavigating()) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
NMS.look(basePassenger, yaw, pitch);
}
d(4, true); // datawatcher method

View File

@ -63,7 +63,7 @@ public class HorseController extends MobEntityController {
NMSImpl.clearGoals(npc, goalSelector, targetSelector);
Horse horse = (Horse) getBukkitEntity();
horse.setDomestication(horse.getMaxDomestication());
baseMovementSpeed = this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue() * 0.8;
baseMovementSpeed = this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue();
}
}
@ -236,8 +236,8 @@ public class HorseController extends MobEntityController {
riding = false;
}
if (riding) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
if (basePassenger instanceof NPCHolder) {
if (npc.getNavigator().isNavigating()) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
NMS.look(basePassenger, yaw, pitch);
}
d(4, true); // datawatcher method

View File

@ -234,8 +234,8 @@ public class HorseDonkeyController extends MobEntityController {
riding = false;
}
if (riding) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
if (basePassenger instanceof NPCHolder) {
if (npc.getNavigator().isNavigating()) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
NMS.look(basePassenger, yaw, pitch);
}
d(4, true); // datawatcher method

View File

@ -234,8 +234,8 @@ public class HorseMuleController extends MobEntityController {
riding = false;
}
if (riding) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
if (basePassenger instanceof NPCHolder) {
if (npc.getNavigator().isNavigating()) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
NMS.look(basePassenger, yaw, pitch);
}
d(4, true); // datawatcher method

View File

@ -235,8 +235,8 @@ public class HorseSkeletonController extends MobEntityController {
riding = false;
}
if (riding) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
if (basePassenger instanceof NPCHolder) {
if (npc.getNavigator().isNavigating()) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
NMS.look(basePassenger, yaw, pitch);
}
d(4, true); // datawatcher method

View File

@ -235,8 +235,8 @@ public class HorseZombieController extends MobEntityController {
riding = false;
}
if (riding) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
if (basePassenger instanceof NPCHolder) {
if (npc.getNavigator().isNavigating()) {
org.bukkit.entity.Entity basePassenger = passengers.get(0).getBukkitEntity();
NMS.look(basePassenger, yaw, pitch);
}
d(4, true); // datawatcher method