use of thpmc.engine.api.entity.ai.navigation.goal.EntityFollowGoal in project THP-Engine by TheHollowPlanetMC.
the class TestListener method onChat.
@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
if (!event.getMessage().equals("spawn"))
return;
TaskHandler.runSync(() -> {
Location location = player.getLocation();
INMSHandler nmsHandler = THPEngineAPI.getInstance().getNMSHandler();
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "NPC");
NMSEntity entityPlayer = nmsHandler.createNMSEntity(location.getWorld(), location.getX(), location.getY(), location.getZ(), EntityType.PLAYER, gameProfile);
entityPlayer.setPositionRaw(location.getX(), location.getY(), location.getZ());
CollideOption collideOption = new CollideOption(FluidCollisionMode.ALWAYS, false);
collideOption.setCollideBlockFunction(engineBlock -> {
return engineBlock.getMaterial() != Material.GLASS;
});
THPEngineAPI.getInstance().getTickRunnerPool().spawn(tickRunner -> {
EnginePlayerEntity npc = new EnginePlayerEntity(tickRunner.getThreadLocalCache().getWorld(location.getWorld().getName()), (NMSEntityPlayer) entityPlayer, tickRunner, true);
npc.getGoalSelector().registerGoal(0, new EntityFollowGoal(player));
npc.setMovementCollideOption(collideOption);
tickRunner.addEntity(npc);
});
});
}
Aggregations