Search in sources :

Example 1 with NMSEntityPlayer

use of thpmc.engine.api.nms.entity.NMSEntityPlayer in project THP-Engine by TheHollowPlanetMC.

the class TestListener method onPlayerClick.

@EventHandler
public void onPlayerClick(PlayerAnimationEvent event) {
    Player player = event.getPlayer();
    if (!player.isSneaking())
        return;
    /*
        List<EngineBoundingBox> list = new ArrayList<>();
        EngineWorld world = AsyncWorldCache.getAsyncWorld(player.getWorld().getName());
        
        Location loc = player.getLocation();
        
        INMSHandler nmsHandler = THPEngineAPI.getInstance().getNMSHandler();
        
        for(int x = loc.getBlockX() - 10; x < loc.getBlockX() + 10; x++){
            for(int y = loc.getBlockY() - 10; y < loc.getBlockY() + 10; y++){
                for(int z = loc.getBlockZ() - 10; z < loc.getBlockZ() + 10; z++){
                    EngineChunk chunk = world.getChunkAt(x >> 4, z >> 4);
                    Object iBlockData = chunk.getNMSBlockData(x, y, z);
                    if(iBlockData == null) continue;
                    
                    EngineBlock block = new EngineBlock(world, chunk, x, y, z, iBlockData);
                    nmsHandler.collectBlockCollisions(block, list, new CollideOption(FluidCollisionMode.ALWAYS, true));
                }
            }
        }
        
        for(EngineBoundingBox boundingBox : list){
            player.spawnParticle(Particle.FLAME, boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), 0);
            player.spawnParticle(Particle.FLAME, boundingBox.getMinX(), boundingBox.getMaxY(), boundingBox.getMinZ(), 0);
            player.spawnParticle(Particle.FLAME, boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMaxZ(), 0);
            player.spawnParticle(Particle.FLAME, boundingBox.getMinX(), boundingBox.getMaxY(), boundingBox.getMaxZ(), 0);
            player.spawnParticle(Particle.FLAME, boundingBox.getMaxX(), boundingBox.getMinY(), boundingBox.getMinZ(), 0);
            player.spawnParticle(Particle.FLAME, boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMinZ(), 0);
            player.spawnParticle(Particle.FLAME, boundingBox.getMaxX(), boundingBox.getMinY(), boundingBox.getMaxZ(), 0);
            player.spawnParticle(Particle.FLAME, boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ(), 0);
        }*/
    TaskHandler.runAsync(() -> {
        EngineWorld world = AsyncWorldCache.getAsyncWorld(player.getWorld().getName());
        CollideOption collideOption = new CollideOption(FluidCollisionMode.ALWAYS, false);
        collideOption.setCollideBlockFunction(engineBlock -> {
            return engineBlock.getMaterial() != Material.OAK_LEAVES;
        });
        collideOption.setBoundingBoxGrow(0.2);
        EngineRayTraceResult rayTraceResult = world.rayTraceEntities(player.getEyeLocation().toVector(), player.getEyeLocation().getDirection(), 20, collideOption);
        if (rayTraceResult == null) {
            player.sendMessage("NOT HIT!");
        } else {
            Vector hitPosition = rayTraceResult.getHitPosition();
            BlockFace hitFace = rayTraceResult.getHitFace();
            player.spawnParticle(Particle.FLAME, hitPosition.getX(), hitPosition.getY(), hitPosition.getZ(), 0);
            player.sendMessage("Hit face : " + hitFace);
        }
    });
/*
        for (int index = 0; index < 100; index++) {
            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());
    
            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));
                tickRunner.addEntity(npc);
            });
    
            count++;
            
            player.sendMessage("PlayerNPC -> " + count);
        }*/
}
Also used : Player(org.bukkit.entity.Player) NMSEntityPlayer(thpmc.engine.api.nms.entity.NMSEntityPlayer) BlockFace(org.bukkit.block.BlockFace) CollideOption(thpmc.engine.api.util.collision.CollideOption) EngineWorld(thpmc.engine.api.world.cache.EngineWorld) EngineRayTraceResult(thpmc.engine.api.world.cache.EngineRayTraceResult) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Example 2 with NMSEntityPlayer

use of thpmc.engine.api.nms.entity.NMSEntityPlayer 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

Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 NMSEntityPlayer (thpmc.engine.api.nms.entity.NMSEntityPlayer)2 CollideOption (thpmc.engine.api.util.collision.CollideOption)2 GameProfile (com.mojang.authlib.GameProfile)1 Location (org.bukkit.Location)1 BlockFace (org.bukkit.block.BlockFace)1 Vector (org.bukkit.util.Vector)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 EngineRayTraceResult (thpmc.engine.api.world.cache.EngineRayTraceResult)1 EngineWorld (thpmc.engine.api.world.cache.EngineWorld)1