Search in sources :

Example 21 with EntityInsentient

use of net.minecraft.server.v1_14_R1.EntityInsentient in project Citizens2 by CitizensDev.

the class NMSImpl method updatePathfindingRange.

@Override
public void updatePathfindingRange(NPC npc, float pathfindingRange) {
    if (!npc.isSpawned() || !npc.getEntity().getType().isAlive())
        return;
    EntityLiving en = NMSImpl.getHandle((LivingEntity) npc.getEntity());
    if (!(en instanceof EntityInsentient)) {
        if (en instanceof EntityHumanNPC) {
            ((EntityHumanNPC) en).updatePathfindingRange(pathfindingRange);
        }
        return;
    }
    if (PATHFINDING_RANGE == null)
        return;
    EntityInsentient handle = (EntityInsentient) en;
    NavigationAbstract navigation = handle.getNavigation();
    try {
        AttributeInstance inst = (AttributeInstance) PATHFINDING_RANGE.get(navigation);
        inst.setValue(pathfindingRange);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : EntityLiving(net.minecraft.server.v1_8_R3.EntityLiving) AttributeInstance(net.minecraft.server.v1_8_R3.AttributeInstance) EntityInsentient(net.minecraft.server.v1_8_R3.EntityInsentient) NavigationAbstract(net.minecraft.server.v1_8_R3.NavigationAbstract) EntityHumanNPC(net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC)

Example 22 with EntityInsentient

use of net.minecraft.server.v1_14_R1.EntityInsentient in project Citizens2 by CitizensDev.

the class NMSImpl method setShouldJump.

@Override
public void setShouldJump(org.bukkit.entity.Entity entity) {
    Entity handle = NMSImpl.getHandle(entity);
    if (handle == null)
        return;
    if (handle instanceof EntityInsentient) {
        ControllerJump controller = ((EntityInsentient) handle).getControllerJump();
        controller.a();
    } else if (handle instanceof EntityHumanNPC) {
        ((EntityHumanNPC) handle).setShouldJump();
    }
}
Also used : PathEntity(net.minecraft.server.v1_8_R3.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) Entity(net.minecraft.server.v1_8_R3.Entity) CraftEntity(org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) EntityInsentient(net.minecraft.server.v1_8_R3.EntityInsentient) ControllerJump(net.minecraft.server.v1_8_R3.ControllerJump) EntityHumanNPC(net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC)

Example 23 with EntityInsentient

use of net.minecraft.server.v1_14_R1.EntityInsentient in project Citizens2 by CitizensDev.

the class NMSImpl method look.

@Override
public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, boolean immediate) {
    Entity handle = NMSImpl.getHandle(entity);
    if (immediate || headOnly || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType()) || (!(handle instanceof EntityInsentient) && !(handle instanceof EntityHumanNPC))) {
        Location fromLocation = entity.getLocation(FROM_LOCATION);
        double xDiff, yDiff, zDiff;
        xDiff = to.getX() - fromLocation.getX();
        yDiff = to.getY() - fromLocation.getY();
        zDiff = to.getZ() - fromLocation.getZ();
        double distanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
        double distanceY = Math.sqrt(distanceXZ * distanceXZ + yDiff * yDiff);
        double yaw = Math.toDegrees(Math.acos(xDiff / distanceXZ));
        double pitch = Math.toDegrees(Math.acos(yDiff / distanceY)) - 90;
        if (zDiff < 0.0)
            yaw += Math.abs(180 - yaw) * 2;
        if (handle instanceof EntityEnderDragon) {
            yaw = Util.getDragonYaw(handle.getBukkitEntity(), xDiff, zDiff);
        } else {
            yaw = yaw - 90;
        }
        if (headOnly) {
            setHeadYaw(entity, (float) yaw);
        } else {
            look(entity, (float) yaw, (float) pitch);
        }
        return;
    }
    if (handle instanceof EntityInsentient) {
        ((EntityInsentient) handle).getControllerLook().a(to.getX(), to.getY(), to.getZ(), 10, ((EntityInsentient) handle).bQ());
        while (((EntityInsentient) handle).aK >= 180F) {
            ((EntityInsentient) handle).aK -= 360F;
        }
        while (((EntityInsentient) handle).aK < -180F) {
            ((EntityInsentient) handle).aK += 360F;
        }
    } else if (handle instanceof EntityHumanNPC) {
        ((EntityHumanNPC) handle).setTargetLook(to);
    }
}
Also used : PathEntity(net.minecraft.server.v1_8_R3.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) Entity(net.minecraft.server.v1_8_R3.Entity) CraftEntity(org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) EntityEnderDragon(net.minecraft.server.v1_8_R3.EntityEnderDragon) EntityInsentient(net.minecraft.server.v1_8_R3.EntityInsentient) EntityHumanNPC(net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC) Location(org.bukkit.Location)

Example 24 with EntityInsentient

use of net.minecraft.server.v1_14_R1.EntityInsentient in project UltraCosmetics by iSach.

the class PlayerFollower method follow.

@Override
public void follow(Player player) {
    if (player == null) {
        return;
    }
    if (UltraCosmeticsData.get().getPlugin().getPlayerManager().getUltraPlayer(player).getCurrentTreasureChest() != null) {
        return;
    }
    Entity petEntity;
    if (pet.isCustomEntity()) {
        petEntity = ((CustomEntityPet) pet).getCustomEntity();
    } else {
        petEntity = ((CraftEntity) pet.getEntity()).getHandle();
    }
    // Run in sync... To enhance :S
    Bukkit.getScheduler().runTask(UltraCosmeticsData.get().getPlugin(), () -> {
        if (!player.isOnline())
            return;
        if (!player.getWorld().equals(petEntity.getBukkitEntity().getWorld())) {
            petEntity.getBukkitEntity().teleport(player.getLocation());
            return;
        }
        ((EntityInsentient) petEntity).getNavigation().a(2d);
        Location targetLocation = player.getLocation();
        PathEntity path = ((EntityInsentient) petEntity).getNavigation().a(targetLocation.getX() + 1, targetLocation.getY(), targetLocation.getZ() + 1, 1);
        try {
            int distance = (int) Bukkit.getPlayer(player.getName()).getLocation().distance(petEntity.getBukkitEntity().getLocation());
            if (distance > 10 && petEntity.valid && player.isOnGround()) {
                petEntity.setLocation(targetLocation.getBlockX(), targetLocation.getBlockY(), targetLocation.getBlockZ(), 0, 0);
            }
            if (path != null && distance > 1.3) {
                double speed = 1.15d;
                if (pet.getType().getEntityType() == EntityType.ZOMBIE) {
                    speed *= 1.3;
                }
                ((EntityInsentient) petEntity).getNavigation().a(path, speed);
                ((EntityInsentient) petEntity).getNavigation().a(speed);
            }
        } catch (IllegalArgumentException exception) {
            petEntity.setLocation(targetLocation.getBlockX(), targetLocation.getBlockY(), targetLocation.getBlockZ(), 0, 0);
        // exception.printStackTrace();
        }
    });
}
Also used : PathEntity(net.minecraft.server.v1_14_R1.PathEntity) Entity(net.minecraft.server.v1_14_R1.Entity) CraftEntity(org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity) PathEntity(net.minecraft.server.v1_14_R1.PathEntity) Location(org.bukkit.Location)

Example 25 with EntityInsentient

use of net.minecraft.server.v1_14_R1.EntityInsentient in project UltraCosmetics by iSach.

the class PlayerFollower method follow.

@Override
public void follow(Player player) {
    if (player == null)
        return;
    if (UltraCosmeticsData.get().getPlugin().getPlayerManager().getUltraPlayer(player).getCurrentTreasureChest() != null)
        return;
    Entity petEntity;
    if (pet.isCustomEntity()) {
        petEntity = ((CustomEntityPet) pet).getCustomEntity();
    } else {
        petEntity = ((CraftEntity) pet.getEntity()).getHandle();
    }
    ((EntityInsentient) petEntity).getNavigation().a(2);
    Location targetLocation = player.getLocation();
    PathEntity path;
    path = ((EntityInsentient) petEntity).getNavigation().a(targetLocation.getX() + 1, targetLocation.getY(), targetLocation.getZ() + 1);
    try {
        int distance = (int) Bukkit.getPlayer(player.getName()).getLocation().distance(petEntity.getBukkitEntity().getLocation());
        if (distance > 10 && petEntity.valid && player.isOnGround()) {
            petEntity.setLocation(targetLocation.getBlockX(), targetLocation.getBlockY(), targetLocation.getBlockZ(), 0, 0);
        }
        if (path != null && distance > 3.3) {
            double speed = 1.05d;
            if (pet.getType().getEntityType() == EntityType.ZOMBIE)
                speed *= 1.5;
            ((EntityInsentient) petEntity).getNavigation().a(path, speed);
            ((EntityInsentient) petEntity).getNavigation().a(speed);
        }
    } catch (IllegalArgumentException exception) {
        petEntity.setLocation(targetLocation.getBlockX(), targetLocation.getBlockY(), targetLocation.getBlockZ(), 0, 0);
    }
}
Also used : PathEntity(net.minecraft.server.v1_8_R3.PathEntity) CraftEntity(org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity) Entity(net.minecraft.server.v1_8_R3.Entity) EntityInsentient(net.minecraft.server.v1_8_R3.EntityInsentient) PathEntity(net.minecraft.server.v1_8_R3.PathEntity) Location(org.bukkit.Location)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)43 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)42 Location (org.bukkit.Location)18 EntityInsentient (net.minecraft.server.v1_16_R3.EntityInsentient)12 EntityInsentient (net.minecraft.server.v1_15_R1.EntityInsentient)11 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)9 CommandException (net.citizensnpcs.api.command.exception.CommandException)8 EntityHumanNPC (net.citizensnpcs.nms.v1_14_R1.entity.EntityHumanNPC)8 EntityHumanNPC (net.citizensnpcs.nms.v1_15_R1.entity.EntityHumanNPC)8 EntityHumanNPC (net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC)8 EntityInsentient (net.minecraft.server.v1_12_R1.EntityInsentient)8 EntityInsentient (net.minecraft.server.v1_14_R1.EntityInsentient)8 CancelReason (net.citizensnpcs.api.ai.event.CancelReason)7 EntityHumanNPC (net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC)7 MCNavigator (net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator)7 EntityInsentient (net.minecraft.server.v1_11_R1.EntityInsentient)7 PathEntity (net.minecraft.server.v1_14_R1.PathEntity)7 PathEntity (net.minecraft.server.v1_15_R1.PathEntity)7 PathEntity (net.minecraft.server.v1_16_R3.PathEntity)7 Player (org.bukkit.entity.Player)7