Fix player ticking

This commit is contained in:
fullwall 2023-01-05 22:51:42 +08:00
parent 98c5c48c23
commit ffac34f734
16 changed files with 28 additions and 27 deletions

View File

@ -80,7 +80,7 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
public boolean update() { public boolean update() {
if (plan == null) { if (plan == null) {
if (planner == null) { if (planner == null) {
planner = new AStarPlanner(params, npc.getStoredLocation(), destination); planner = new AStarPlanner(params, npc.getEntity().getLocation(NPC_LOCATION), destination);
} }
CancelReason reason = planner.tick(Setting.ASTAR_ITERATIONS_PER_TICK.asInt(), CancelReason reason = planner.tick(Setting.ASTAR_ITERATIONS_PER_TICK.asInt(),
Setting.MAXIMUM_ASTAR_ITERATIONS.asInt()); Setting.MAXIMUM_ASTAR_ITERATIONS.asInt());
@ -98,7 +98,7 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
} }
Location loc = npc.getEntity().getLocation(NPC_LOCATION); Location loc = npc.getEntity().getLocation(NPC_LOCATION);
/* Proper door movement - gets stuck on corners at times /* Proper door movement - gets stuck on corners at times
Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
if (MinecraftBlockExaminer.isDoor(block.getType())) { if (MinecraftBlockExaminer.isDoor(block.getType())) {
Door door = (Door) block.getState().getData(); Door door = (Door) block.getState().getData();
@ -169,16 +169,14 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
return PassableState.IGNORE; return PassableState.IGNORE;
} }
}); });
VectorGoal goal = new VectorGoal(to, (float) params.pathDistanceMargin());
state = ASTAR.getStateFor(goal,
new VectorNode(goal, from, new NMSChunkBlockSource(from, params.range()), params.examiners()));
} }
public CancelReason tick(int iterationsPerTick, int maxIterations) { public CancelReason tick(int iterationsPerTick, int maxIterations) {
if (plan != null) if (this.plan != null)
return null; return null;
if (state == null) {
VectorGoal goal = new VectorGoal(to, (float) params.pathDistanceMargin());
state = ASTAR.getStateFor(goal,
new VectorNode(goal, from, new NMSChunkBlockSource(from, params.range()), params.examiners()));
}
Path plan = ASTAR.run(state, iterationsPerTick); Path plan = ASTAR.run(state, iterationsPerTick);
if (plan == null) { if (plan == null) {
if (state.isEmpty()) { if (state.isEmpty()) {

View File

@ -498,7 +498,12 @@ public class NMS {
} }
public static Runnable playerTicker(Player entity) { public static Runnable playerTicker(Player entity) {
return BRIDGE.playerTicker(entity); Runnable tick = BRIDGE.playerTicker(entity);
return () -> {
if (entity.isValid()) {
tick.run();
}
};
} }
public static void registerEntityClass(Class<?> clazz) { public static void registerEntityClass(Class<?> clazz) {

View File

@ -59,11 +59,7 @@ public class PlayerUpdateTask extends BukkitRunnable {
} }
public PlayerTick(Player player) { public PlayerTick(Player player) {
this(player, () -> { this(player, NMS.playerTicker(player));
if (player.isValid()) {
NMS.playerTicker(player);
}
});
} }
@Override @Override

View File

@ -376,7 +376,7 @@ citizens.editors.waypoints.guided.added-guide=Added a [[guide]] waypoint which t
citizens.editors.waypoints.guided.added-available=Added a [[destination]] waypoint which the NPC will randomly pathfind between. citizens.editors.waypoints.guided.added-available=Added a [[destination]] waypoint which the NPC will randomly pathfind between.
citizens.editors.waypoints.guided.already-taken=There is already a waypoint here. citizens.editors.waypoints.guided.already-taken=There is already a waypoint here.
citizens.editors.waypoints.linear.added-waypoint=[[Added]] a waypoint at ({0}) ([[{1}]] total). citizens.editors.waypoints.linear.added-waypoint=[[Added]] a waypoint at ({0}) ([[{1}]] total).
citizens.editors.waypoints.linear.begin=<green>=== [[Linear Waypoint Editor]] ===<br> [[Left click]] to add a waypoint, [[right click]] to remove it.<br> You can right click while sneaking to select and remove specific points.<br> Type [[markers]] to hide waypoints,<br> [[triggers]] to enter the trigger editor,<br> [[clear]] to clear all waypoints,<br> [[cycle]] to make NPCs cycle through waypoints instead of looping. citizens.editors.waypoints.linear.begin=<green>=== [[Linear Waypoint Editor]] ===<br> [[Left click]] to add a waypoint, [[right click]] to remove it.<br> Right click while sneaking to select and remove points.<br> Type [[markers]] to hide waypoints,<br> [[triggers]] to enter the trigger editor,<br> [[clear]] to clear all waypoints,<br> [[cycle]] to make NPCs cycle through waypoints instead of looping.
citizens.editors.waypoints.linear.selected-waypoint=Selected waypoint at {0}. Sneak + right click again to remove this waypoint. citizens.editors.waypoints.linear.selected-waypoint=Selected waypoint at {0}. Sneak + right click again to remove this waypoint.
citizens.editors.waypoints.linear.end=Exited the linear waypoint editor. citizens.editors.waypoints.linear.end=Exited the linear waypoint editor.
citizens.editors.waypoints.linear.not-showing-markers=[[Stopped]] showing waypoint markers. citizens.editors.waypoints.linear.not-showing-markers=[[Stopped]] showing waypoint markers.

View File

@ -309,7 +309,8 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
moveOnCurrentHeading(); moveOnCurrentHeading();
} }
NMSImpl.updateAI(this);
updateAI();
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
cs(); cs();

View File

@ -370,7 +370,8 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
moveOnCurrentHeading(); moveOnCurrentHeading();
} }
NMSImpl.updateAI(this);
updateAI();
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
ct(); ct();

View File

@ -396,7 +396,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
moveOnCurrentHeading(); moveOnCurrentHeading();
} }
NMSImpl.updateAI(this); updateAI();
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
cB(); cB();

View File

@ -374,7 +374,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
moveOnCurrentHeading(); moveOnCurrentHeading();
} }
NMSImpl.updateAI(this); updateAI();
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
cN(); cN();

View File

@ -379,7 +379,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
moveOnCurrentHeading(); moveOnCurrentHeading();
} }
NMSImpl.updateAI(this); updateAI();
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
collideNearby(); collideNearby();

View File

@ -378,7 +378,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
moveOnCurrentHeading(); moveOnCurrentHeading();
} }
NMSImpl.updateAI(this); updateAI();
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
collideNearby(); collideNearby();

View File

@ -408,7 +408,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
moveOnCurrentHeading(); moveOnCurrentHeading();
} }
NMSImpl.updateAI(this); updateAI();
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
collideNearby(); collideNearby();

View File

@ -189,7 +189,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
} }
moveOnCurrentHeading(); moveOnCurrentHeading();
} }
NMSImpl.updateAI(this); updateAI();
if (isSpectator()) { if (isSpectator()) {
this.noPhysics = true; this.noPhysics = true;

View File

@ -190,7 +190,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
} }
moveOnCurrentHeading(); moveOnCurrentHeading();
} }
NMSImpl.updateAI(this); updateAI();
if (isSpectator()) { if (isSpectator()) {
this.noPhysics = true; this.noPhysics = true;

View File

@ -196,7 +196,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
moveOnCurrentHeading(); moveOnCurrentHeading();
} }
NMSImpl.updateAI(this); updateAI();
if (isSpectator()) { if (isSpectator()) {
this.noPhysics = true; this.noPhysics = true;

View File

@ -103,7 +103,6 @@ public class PlayerMoveControl extends MoveControl {
@Override @Override
public void tick() { public void tick() {
this.entity.zza = 0; this.entity.zza = 0;
if (this.moving) { if (this.moving) {
this.moving = false; this.moving = false;

View File

@ -312,7 +312,8 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
moveOnCurrentHeading(); moveOnCurrentHeading();
} }
NMSImpl.updateAI(this);
updateAI();
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
bL(); bL();