Search in sources :

Example 16 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();
    }
    ((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)

Example 17 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 (petEntity == null) {
        return;
    }
    // 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 : CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) PathEntity(net.minecraft.server.v1_16_R3.PathEntity) Entity(net.minecraft.server.v1_16_R3.Entity) PathEntity(net.minecraft.server.v1_16_R3.PathEntity) Location(org.bukkit.Location)

Example 18 with PathEntity

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

the class PlayerPathfinder method a.

private PathEntity a(IBlockAccess paramIBlockAccess, Entity paramEntity, double paramDouble1, double paramDouble2, double paramDouble3, float paramFloat) {
    this.a.a();
    this.c.a(paramIBlockAccess, paramEntity);
    PathPoint localPathPoint1 = this.c.a(paramEntity);
    PathPoint localPathPoint2 = this.c.a(paramEntity, paramDouble1, paramDouble2, paramDouble3);
    PathEntity localPathEntity = a(paramEntity, localPathPoint1, localPathPoint2, paramFloat);
    this.c.a();
    return localPathEntity;
}
Also used : PathPoint(net.minecraft.server.v1_8_R3.PathPoint) PathEntity(net.minecraft.server.v1_8_R3.PathEntity)

Example 19 with PathEntity

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

the class PlayerPathfinder method a.

private PathEntity a(PathPoint paramPathPoint1, PathPoint paramPathPoint2) {
    int i = 1;
    PathPoint localPathPoint = paramPathPoint2;
    try {
        while (H.get(localPathPoint) != null) {
            i++;
            localPathPoint = (PathPoint) H.get(localPathPoint);
        }
    } catch (IllegalArgumentException e1) {
        e1.printStackTrace();
    } catch (IllegalAccessException e1) {
        e1.printStackTrace();
    }
    PathPoint[] arrayOfPathPoint = new PathPoint[i];
    localPathPoint = paramPathPoint2;
    arrayOfPathPoint[(--i)] = localPathPoint;
    try {
        while (H.get(localPathPoint) != null) {
            localPathPoint = (PathPoint) H.get(localPathPoint);
            arrayOfPathPoint[(--i)] = localPathPoint;
        }
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return new PathEntity(arrayOfPathPoint);
}
Also used : PathPoint(net.minecraft.server.v1_8_R3.PathPoint) PathEntity(net.minecraft.server.v1_8_R3.PathEntity) PathPoint(net.minecraft.server.v1_8_R3.PathPoint)

Example 20 with PathEntity

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

the class PlayerNavigation method a.

@Override
public PathEntity a(BlockPosition paramBlockPosition) {
    if (!b()) {
        return null;
    }
    float f1 = i();
    this.c.methodProfiler.a("pathfind");
    BlockPosition localBlockPosition = new BlockPosition(this.b);
    int k = (int) (f1 + 8.0F);
    ChunkCache localChunkCache = new ChunkCache(this.c, localBlockPosition.a(-k, -k, -k), localBlockPosition.a(k, k, k), 0);
    PathEntity localPathEntity = this.j.a(localChunkCache, this.b, paramBlockPosition, f1);
    this.c.methodProfiler.b();
    return localPathEntity;
}
Also used : ChunkCache(net.minecraft.server.v1_8_R3.ChunkCache) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) PathEntity(net.minecraft.server.v1_8_R3.PathEntity) PathPoint(net.minecraft.server.v1_8_R3.PathPoint)

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