Trial manually calling aiStep for players with /npc ai turned on

This commit is contained in:
fullwall 2024-03-05 09:47:24 +08:00
parent 903ba91b4c
commit 8be9da5f04
14 changed files with 90 additions and 26 deletions

View File

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

View File

@ -161,7 +161,7 @@ public interface NMSBridge {
public void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to); public void playAnimation(PlayerAnimation animation, Player player, Iterable<Player> to);
public Runnable playerTicker(Player entity); public Runnable playerTicker(NPC npc, Player entity);
public void registerEntityClass(Class<?> clazz); public void registerEntityClass(Class<?> clazz);

View File

@ -965,8 +965,10 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public Runnable playerTicker(Player next) { public Runnable playerTicker(NPC npc, Player next) {
return () -> { return () -> {
if (!next.isValid())
return;
EntityPlayer entity = (EntityPlayer) getHandle(next); EntityPlayer entity = (EntityPlayer) getHandle(next);
boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist", boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());

View File

@ -1018,8 +1018,10 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public Runnable playerTicker(Player next) { public Runnable playerTicker(NPC npc, Player next) {
return () -> { return () -> {
if (!next.isValid())
return;
EntityPlayer entity = (EntityPlayer) getHandle(next); EntityPlayer entity = (EntityPlayer) getHandle(next);
boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist", boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());

View File

@ -1025,8 +1025,10 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public Runnable playerTicker(Player next) { public Runnable playerTicker(NPC npc, Player next) {
return () -> { return () -> {
if (!next.isValid())
return;
EntityPlayer entity = (EntityPlayer) getHandle(next); EntityPlayer entity = (EntityPlayer) getHandle(next);
boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist", boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());

View File

@ -1061,8 +1061,10 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public Runnable playerTicker(Player next) { public Runnable playerTicker(NPC npc, Player next) {
return () -> { return () -> {
if (!next.isValid())
return;
EntityPlayer entity = (EntityPlayer) getHandle(next); EntityPlayer entity = (EntityPlayer) getHandle(next);
boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist", boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());

View File

@ -1130,8 +1130,16 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public Runnable playerTicker(Player entity) { public Runnable playerTicker(NPC npc, Player entity) {
return ((EntityPlayer) getHandle(entity))::playerTick; EntityPlayer player = (EntityPlayer) getHandle(entity);
return () -> {
if (!entity.isValid())
return;
if (npc != null && npc.useMinecraftAI()) {
player.movementTick();
}
player.playerTick();
};
} }
@Override @Override

View File

@ -1147,8 +1147,16 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public Runnable playerTicker(Player entity) { public Runnable playerTicker(NPC npc, Player entity) {
return ((EntityPlayer) getHandle(entity))::playerTick; EntityPlayer player = (EntityPlayer) getHandle(entity);
return () -> {
if (!entity.isValid())
return;
if (npc != null && npc.useMinecraftAI()) {
player.movementTick();
}
player.playerTick();
};
} }
@Override @Override

View File

@ -1171,8 +1171,16 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public Runnable playerTicker(Player entity) { public Runnable playerTicker(NPC npc, Player entity) {
return ((EntityPlayer) getHandle(entity))::playerTick; EntityPlayer player = (EntityPlayer) getHandle(entity);
return () -> {
if (!entity.isValid())
return;
if (npc != null && npc.useMinecraftAI()) {
player.movementTick();
}
player.playerTick();
};
} }
@Override @Override

View File

@ -1177,8 +1177,16 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public Runnable playerTicker(Player entity) { public Runnable playerTicker(NPC npc, Player entity) {
return ((ServerPlayer) getHandle(entity))::doTick; ServerPlayer player = (ServerPlayer) getHandle(entity);
return () -> {
if (!entity.isValid())
return;
if (npc != null && npc.useMinecraftAI()) {
player.aiStep();
}
player.doTick();
};
} }
@Override @Override

View File

@ -1186,8 +1186,16 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public Runnable playerTicker(Player entity) { public Runnable playerTicker(NPC npc, Player entity) {
return ((ServerPlayer) getHandle(entity))::doTick; ServerPlayer player = (ServerPlayer) getHandle(entity);
return () -> {
if (!entity.isValid())
return;
if (npc != null && npc.useMinecraftAI()) {
player.aiStep();
}
player.doTick();
};
} }
@Override @Override

View File

@ -1313,8 +1313,16 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public Runnable playerTicker(Player entity) { public Runnable playerTicker(NPC npc, Player entity) {
return ((ServerPlayer) getHandle(entity))::doTick; ServerPlayer player = (ServerPlayer) getHandle(entity);
return () -> {
if (!entity.isValid())
return;
if (npc != null && npc.useMinecraftAI()) {
player.aiStep();
}
player.doTick();
};
} }
@Override @Override

View File

@ -1285,8 +1285,16 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public Runnable playerTicker(Player entity) { public Runnable playerTicker(NPC npc, Player entity) {
return ((ServerPlayer) getHandle(entity))::doTick; ServerPlayer player = (ServerPlayer) getHandle(entity);
return () -> {
if (!entity.isValid())
return;
if (npc != null && npc.useMinecraftAI()) {
player.aiStep();
}
player.doTick();
};
} }
@Override @Override

View File

@ -901,12 +901,17 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public Runnable playerTicker(Player next) { public Runnable playerTicker(NPC npc, Player next) {
return () -> { return () -> {
if (!next.isValid())
return;
EntityPlayer entity = (EntityPlayer) getHandle(next); EntityPlayer entity = (EntityPlayer) getHandle(next);
boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist", boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
entity.l(); entity.l();
if (npc != null && npc.useMinecraftAI()) {
entity.m();
}
if (!removeFromPlayerList) if (!removeFromPlayerList)
return; return;
if (!entity.dead) { if (!entity.dead) {