Search in sources :

Example 46 with PathEntity

use of net.minecraft.server.v1_14_R1.PathEntity 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();
    }
    if (!player.getWorld().equals(petEntity.getBukkitEntity().getWorld())) {
        petEntity.getBukkitEntity().teleport(player.getLocation());
        return;
    }
    ((EntityInsentient) petEntity).getNavigation().a(2);
    Location targetLocation = player.getLocation();
    PathEntity 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);
        exception.printStackTrace();
    }
}
Also used : Entity(net.minecraft.server.v1_12_R1.Entity) PathEntity(net.minecraft.server.v1_12_R1.PathEntity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) PathEntity(net.minecraft.server.v1_12_R1.PathEntity) Location(org.bukkit.Location)

Aggregations

List (java.util.List)10 Optional (java.util.Optional)9 Lists (com.google.common.collect.Lists)8 Sets (com.google.common.collect.Sets)8 Comparator (java.util.Comparator)8 Map (java.util.Map)8 Set (java.util.Set)8 Function (java.util.function.Function)8 Collectors (java.util.stream.Collectors)8 Stream (java.util.stream.Stream)8 Setting (net.citizensnpcs.Settings.Setting)8 PathEntity (net.minecraft.server.v1_16_R3.PathEntity)7 Location (org.bukkit.Location)7 Iterator (java.util.Iterator)6 PathEntity (net.minecraft.server.v1_14_R1.PathEntity)6 PathEntity (net.minecraft.server.v1_15_R1.PathEntity)6 PathPoint (net.minecraft.server.v1_16_R3.PathPoint)6 PathEntity (net.minecraft.server.v1_8_R3.PathEntity)6 PathEntity (net.minecraft.server.v1_10_R1.PathEntity)5 PathPoint (net.minecraft.server.v1_10_R1.PathPoint)5