Search in sources :

Example 1 with NMSEntity

use of thpmc.engine.api.nms.entity.NMSEntity 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);
        });
    });
}
Also used : EnginePlayerEntity(thpmc.engine.api.entity.EnginePlayerEntity) EntityFollowGoal(thpmc.engine.api.entity.ai.navigation.goal.EntityFollowGoal) Player(org.bukkit.entity.Player) NMSEntityPlayer(thpmc.engine.api.nms.entity.NMSEntityPlayer) GameProfile(com.mojang.authlib.GameProfile) CollideOption(thpmc.engine.api.util.collision.CollideOption) NMSEntity(thpmc.engine.api.nms.entity.NMSEntity) INMSHandler(thpmc.engine.api.nms.INMSHandler) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)1 Location (org.bukkit.Location)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 EnginePlayerEntity (thpmc.engine.api.entity.EnginePlayerEntity)1 EntityFollowGoal (thpmc.engine.api.entity.ai.navigation.goal.EntityFollowGoal)1 INMSHandler (thpmc.engine.api.nms.INMSHandler)1 NMSEntity (thpmc.engine.api.nms.entity.NMSEntity)1 NMSEntityPlayer (thpmc.engine.api.nms.entity.NMSEntityPlayer)1 CollideOption (thpmc.engine.api.util.collision.CollideOption)1