Search in sources :

Example 6 with PathPoint

use of net.minecraft.server.v1_15_R1.PathPoint in project Citizens2 by CitizensDev.

the class NMSImpl method getTargetNavigator.

private MCNavigator getTargetNavigator(final org.bukkit.entity.Entity entity, final NavigatorParameters params, final Function<NavigationAbstract, Boolean> function) {
    net.minecraft.server.v1_13_R2.Entity raw = getHandle(entity);
    raw.onGround = true;
    // not sure of a better way around this - if onGround is false, then
    // navigation won't execute, and calling entity.move doesn't
    // entirely fix the problem.
    final NavigationAbstract navigation = NMSImpl.getNavigation(entity);
    final float oldWater = raw instanceof EntityPlayer ? ((EntityHumanNPC) raw).a(PathType.WATER) : ((EntityInsentient) raw).a(PathType.WATER);
    if (params.avoidWater() && oldWater >= 0) {
        if (raw instanceof EntityPlayer) {
            ((EntityHumanNPC) raw).a(PathType.WATER, oldWater + 1F);
        } else {
            ((EntityInsentient) raw).a(PathType.WATER, oldWater + 1F);
        }
    }
    return new MCNavigator() {

        float lastSpeed;

        CancelReason reason;

        @Override
        public CancelReason getCancelReason() {
            return reason;
        }

        @Override
        public Iterable<Vector> getPath() {
            return new NavigationIterable(navigation);
        }

        @Override
        public void stop() {
            if (params.debug() && navigation.m() != null) {
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < navigation.m().d(); i++) {
                        PathPoint pp = navigation.m().a(i);
                        org.bukkit.block.Block block = new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()).getBlock();
                        player.sendBlockChange(block.getLocation(), block.getBlockData());
                    }
                }
            }
            if (oldWater >= 0) {
                if (raw instanceof EntityPlayer) {
                    ((EntityHumanNPC) raw).a(PathType.WATER, oldWater);
                } else {
                    ((EntityInsentient) raw).a(PathType.WATER, oldWater);
                }
            }
            stopNavigation(navigation);
        }

        @Override
        public boolean update() {
            if (params.speed() != lastSpeed) {
                if (Messaging.isDebugging() && lastSpeed > 0) {
                    Messaging.debug("Repathfinding " + ((NPCHolder) entity).getNPC().getId() + " due to speed change");
                }
                Entity handle = getHandle(entity);
                float oldWidth = handle.width;
                if (handle instanceof EntityHorse) {
                    handle.width = Math.min(0.99f, oldWidth);
                }
                if (!function.apply(navigation)) {
                    reason = CancelReason.STUCK;
                }
                // minecraft requires that an entity fit onto both blocks if width >= 1f,
                handle.width = oldWidth;
                // but we'd prefer to make it just fit on 1 so hack around it a bit.
                lastSpeed = params.speed();
            }
            if (params.debug() && !NMSImpl.isNavigationFinished(navigation)) {
                BlockData data = Material.DANDELION.createBlockData();
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < navigation.m().d(); i++) {
                        PathPoint pp = navigation.m().a(i);
                        player.sendBlockChange(new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()), data);
                    }
                }
            }
            navigation.a(params.speed());
            return NMSImpl.isNavigationFinished(navigation);
        }
    };
}
Also used : PathEntity(net.minecraft.server.v1_13_R2.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) Entity(net.minecraft.server.v1_13_R2.Entity) Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_13_R2.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) EntityInsentient(net.minecraft.server.v1_13_R2.EntityInsentient) Entity(net.minecraft.server.v1_13_R2.Entity) NavigationAbstract(net.minecraft.server.v1_13_R2.NavigationAbstract) PathPoint(net.minecraft.server.v1_13_R2.PathPoint) EntityHumanNPC(net.citizensnpcs.nms.v1_13_R2.entity.EntityHumanNPC) PathPoint(net.minecraft.server.v1_13_R2.PathPoint) MCNavigator(net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator) EntityHorse(net.minecraft.server.v1_13_R2.EntityHorse) CancelReason(net.citizensnpcs.api.ai.event.CancelReason) EntityPlayer(net.minecraft.server.v1_13_R2.EntityPlayer) BlockData(org.bukkit.block.data.BlockData) IBlockData(net.minecraft.server.v1_13_R2.IBlockData) Vector(org.bukkit.util.Vector)

Example 7 with PathPoint

use of net.minecraft.server.v1_15_R1.PathPoint in project Citizens2 by CitizensDev.

the class PlayerPathfinder method a.

private PathEntity a(PathPoint paramPathPoint1, PathPoint paramPathPoint2) {
    int i = 1;
    PathPoint localPathPoint = paramPathPoint2;
    while (localPathPoint.h != null) {
        i++;
        localPathPoint = localPathPoint.h;
    }
    PathPoint[] arrayOfPathPoint = new PathPoint[i];
    localPathPoint = paramPathPoint2;
    arrayOfPathPoint[(--i)] = localPathPoint;
    while (localPathPoint.h != null) {
        localPathPoint = localPathPoint.h;
        arrayOfPathPoint[(--i)] = localPathPoint;
    }
    return new PathEntity(arrayOfPathPoint);
}
Also used : PathPoint(net.minecraft.server.v1_13_R2.PathPoint) PathEntity(net.minecraft.server.v1_13_R2.PathEntity) PathPoint(net.minecraft.server.v1_13_R2.PathPoint)

Example 8 with PathPoint

use of net.minecraft.server.v1_15_R1.PathPoint in project Citizens2 by CitizensDev.

the class PlayerPathfinderNormal method a.

@Override
public int a(PathPoint[] var1, PathPoint var2, PathPoint var3, float var4) {
    int var5 = 0;
    int var6 = 0;
    PathType var7 = this.a(this.b, var2.a, var2.b + 1, var2.c);
    if (this.b.a(var7) >= 0.0F) {
        var6 = MathHelper.d(Math.max(1.0F, this.b.Q));
    }
    double var8 = a(this.a, new BlockPosition(var2.a, var2.b, var2.c));
    PathPoint var10 = this.a(var2.a, var2.b, var2.c + 1, var6, var8, EnumDirection.SOUTH);
    PathPoint var11 = this.a(var2.a - 1, var2.b, var2.c, var6, var8, EnumDirection.WEST);
    PathPoint var12 = this.a(var2.a + 1, var2.b, var2.c, var6, var8, EnumDirection.EAST);
    PathPoint var13 = this.a(var2.a, var2.b, var2.c - 1, var6, var8, EnumDirection.NORTH);
    if (var10 != null && !var10.i && var10.a(var3) < var4) {
        var1[var5++] = var10;
    }
    if (var11 != null && !var11.i && var11.a(var3) < var4) {
        var1[var5++] = var11;
    }
    if (var12 != null && !var12.i && var12.a(var3) < var4) {
        var1[var5++] = var12;
    }
    if (var13 != null && !var13.i && var13.a(var3) < var4) {
        var1[var5++] = var13;
    }
    boolean var14 = var13 == null || var13.m == PathType.OPEN || var13.l != 0.0F;
    boolean var15 = var10 == null || var10.m == PathType.OPEN || var10.l != 0.0F;
    boolean var16 = var12 == null || var12.m == PathType.OPEN || var12.l != 0.0F;
    boolean var17 = var11 == null || var11.m == PathType.OPEN || var11.l != 0.0F;
    PathPoint var18;
    if (var14 && var17) {
        var18 = this.a(var2.a - 1, var2.b, var2.c - 1, var6, var8, EnumDirection.NORTH);
        if (var18 != null && !var18.i && var18.a(var3) < var4) {
            var1[var5++] = var18;
        }
    }
    if (var14 && var16) {
        var18 = this.a(var2.a + 1, var2.b, var2.c - 1, var6, var8, EnumDirection.NORTH);
        if (var18 != null && !var18.i && var18.a(var3) < var4) {
            var1[var5++] = var18;
        }
    }
    if (var15 && var17) {
        var18 = this.a(var2.a - 1, var2.b, var2.c + 1, var6, var8, EnumDirection.SOUTH);
        if (var18 != null && !var18.i && var18.a(var3) < var4) {
            var1[var5++] = var18;
        }
    }
    if (var15 && var16) {
        var18 = this.a(var2.a + 1, var2.b, var2.c + 1, var6, var8, EnumDirection.SOUTH);
        if (var18 != null && !var18.i && var18.a(var3) < var4) {
            var1[var5++] = var18;
        }
    }
    return var5;
}
Also used : PathType(net.minecraft.server.v1_13_R2.PathType) PathPoint(net.minecraft.server.v1_13_R2.PathPoint) MutableBlockPosition(net.minecraft.server.v1_13_R2.BlockPosition.MutableBlockPosition) BlockPosition(net.minecraft.server.v1_13_R2.BlockPosition) PathPoint(net.minecraft.server.v1_13_R2.PathPoint)

Example 9 with PathPoint

use of net.minecraft.server.v1_15_R1.PathPoint in project Citizens2 by CitizensDev.

the class PlayerPathfinderNormal method a.

private PathPoint a(int var1, int var2, int var3, int var4, double var5, EnumDirection var7) {
    PathPoint var8 = null;
    BlockPosition var9 = new BlockPosition(var1, var2, var3);
    double var10 = a(this.a, var9);
    if (var10 - var5 > 1.125D) {
        return null;
    } else {
        PathType var12 = this.a(this.b, var1, var2, var3);
        float var13 = this.b.a(var12);
        double var14 = this.b.width / 2.0D;
        if (var13 >= 0.0F) {
            var8 = this.a(var1, var2, var3);
            var8.m = var12;
            var8.l = Math.max(var8.l, var13);
        }
        if (var12 == PathType.WALKABLE) {
            return var8;
        } else {
            if (var8 == null && var4 > 0 && var12 != PathType.FENCE && var12 != PathType.TRAPDOOR) {
                var8 = this.a(var1, var2 + 1, var3, var4 - 1, var5, var7);
                if (var8 != null && (var8.m == PathType.OPEN || var8.m == PathType.WALKABLE) && this.b.width < 1.0F) {
                    double var16 = var1 - var7.getAdjacentX() + 0.5D;
                    double var18 = var3 - var7.getAdjacentZ() + 0.5D;
                    AxisAlignedBB var20 = new AxisAlignedBB(var16 - var14, var2 + 0.001D, var18 - var14, var16 + var14, this.b.length + a(this.a, var9.up()) - 0.002D, var18 + var14);
                    if (!this.b.world.getCubes((Entity) null, var20)) {
                        var8 = null;
                    }
                }
            }
            if (var12 == PathType.WATER && !this.e()) {
                if (this.a(this.b, var1, var2 - 1, var3) != PathType.WATER) {
                    return var8;
                }
                while (var2 > 0) {
                    --var2;
                    var12 = this.a(this.b, var1, var2, var3);
                    if (var12 != PathType.WATER) {
                        return var8;
                    }
                    var8 = this.a(var1, var2, var3);
                    var8.m = var12;
                    var8.l = Math.max(var8.l, this.b.a(var12));
                }
            }
            if (var12 == PathType.OPEN) {
                AxisAlignedBB var21 = new AxisAlignedBB(var1 - var14 + 0.5D, var2 + 0.001D, var3 - var14 + 0.5D, var1 + var14 + 0.5D, var2 + this.b.length, var3 + var14 + 0.5D);
                if (!this.b.world.getCubes((Entity) null, var21)) {
                    return null;
                }
                if (this.b.width >= 1.0F) {
                    PathType var17 = this.a(this.b, var1, var2 - 1, var3);
                    if (var17 == PathType.BLOCKED) {
                        var8 = this.a(var1, var2, var3);
                        var8.m = PathType.WALKABLE;
                        var8.l = Math.max(var8.l, var13);
                        return var8;
                    }
                }
                int var22 = 0;
                while (var2 > 0 && var12 == PathType.OPEN) {
                    --var2;
                    if (var22++ >= Setting.MC_NAVIGATION_MAX_FALL_DISTANCE.asInt()) {
                        return null;
                    }
                    var12 = this.a(this.b, var1, var2, var3);
                    var13 = this.b.a(var12);
                    if (var12 != PathType.OPEN && var13 >= 0.0F) {
                        var8 = this.a(var1, var2, var3);
                        var8.m = var12;
                        var8.l = Math.max(var8.l, var13);
                        break;
                    }
                    if (var13 < 0.0F) {
                        return null;
                    }
                }
            }
            return var8;
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.server.v1_13_R2.AxisAlignedBB) PathPoint(net.minecraft.server.v1_13_R2.PathPoint) PathType(net.minecraft.server.v1_13_R2.PathType) Entity(net.minecraft.server.v1_13_R2.Entity) MutableBlockPosition(net.minecraft.server.v1_13_R2.BlockPosition.MutableBlockPosition) BlockPosition(net.minecraft.server.v1_13_R2.BlockPosition) PathPoint(net.minecraft.server.v1_13_R2.PathPoint)

Example 10 with PathPoint

use of net.minecraft.server.v1_15_R1.PathPoint in project Citizens2 by CitizensDev.

the class PlayerPathfinder method a.

private PathEntity a(PathPoint var0, Map var1, float var2, int var3, float var4) {
    Set<PathDestination> var5 = var1.keySet();
    var0.e = 0.0F;
    var0.f = a(var0, var5);
    var0.g = var0.f;
    this.d.a();
    this.d.a(var0);
    ImmutableSet immutableSet = ImmutableSet.of();
    int var7 = 0;
    Set<PathDestination> var8 = Sets.newHashSetWithExpectedSize(var5.size());
    int var9 = (int) (this.b * var4);
    while (!this.d.e() && ++var7 < var9) {
        PathPoint pathPoint = this.d.c();
        pathPoint.i = true;
        for (PathDestination pathDestination : var5) {
            if (pathPoint.c(pathDestination) <= var3) {
                pathDestination.e();
                var8.add(pathDestination);
            }
        }
        if (!var8.isEmpty())
            break;
        if (pathPoint.a(var0) >= var2)
            continue;
        int i = this.c.a(this.a, pathPoint);
        for (int var12 = 0; var12 < i; var12++) {
            PathPoint var13 = this.a[var12];
            float var14 = pathPoint.a(var13);
            pathPoint.j += var14;
            float var15 = pathPoint.e + var14 + var13.k;
            if (var13.j < var2 && (!var13.c() || var15 < var13.e)) {
                var13.h = pathPoint;
                var13.e = var15;
                var13.f = a(var13, var5) * 1.5F;
                if (var13.c()) {
                    this.d.a(var13, var13.e + var13.f);
                } else {
                    var13.g = var13.e + var13.f;
                    this.d.a(var13);
                }
            }
        }
    }
    Optional var10 = !var8.isEmpty() ? var8.stream().map((var1x) -> {
        return this.a(var1x.d(), (BlockPosition) var1.get(var1x), true);
    }).min(Comparator.comparingInt(PathEntity::e)) : getFallbackDestinations(var1, var5).findFirst();
    if (!var10.isPresent()) {
        return null;
    } else {
        PathEntity var11 = (PathEntity) var10.get();
        return var11;
    }
}
Also used : PathPoint(net.minecraft.server.v1_16_R3.PathPoint) ImmutableSet(com.google.common.collect.ImmutableSet) Optional(java.util.Optional) PathEntity(net.minecraft.server.v1_16_R3.PathEntity) PathDestination(net.minecraft.server.v1_16_R3.PathDestination) PathPoint(net.minecraft.server.v1_16_R3.PathPoint)

Aggregations

PathPoint (net.minecraft.server.v1_16_R3.PathPoint)12 PathPoint (net.minecraft.server.v1_14_R1.PathPoint)11 PathPoint (net.minecraft.server.v1_15_R1.PathPoint)11 List (java.util.List)10 Iterator (java.util.Iterator)9 Optional (java.util.Optional)9 Set (java.util.Set)9 PathPoint (net.minecraft.server.v1_11_R1.PathPoint)9 PathPoint (net.minecraft.server.v1_13_R2.PathPoint)9 Vector (org.bukkit.util.Vector)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 Function (java.util.function.Function)8 Collectors (java.util.stream.Collectors)8 Stream (java.util.stream.Stream)8 Setting (net.citizensnpcs.Settings.Setting)8 PathPoint (net.minecraft.server.v1_10_R1.PathPoint)8 BlockPosition (net.minecraft.server.v1_14_R1.BlockPosition)8