Search in sources :

Example 36 with PathPoint

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

the class PlayerPathfinderNormal method a.

@Override
public int a(PathPoint[] paramArrayOfPathPoint, Entity paramEntity, PathPoint paramPathPoint1, PathPoint paramPathPoint2, float paramFloat) {
    int k = 0;
    int m = 0;
    if (a(paramEntity, paramPathPoint1.a, paramPathPoint1.b + 1, paramPathPoint1.c) == 1) {
        m = 1;
    }
    PathPoint localPathPoint1 = a(paramEntity, paramPathPoint1.a, paramPathPoint1.b, paramPathPoint1.c + 1, m);
    PathPoint localPathPoint2 = a(paramEntity, paramPathPoint1.a - 1, paramPathPoint1.b, paramPathPoint1.c, m);
    PathPoint localPathPoint3 = a(paramEntity, paramPathPoint1.a + 1, paramPathPoint1.b, paramPathPoint1.c, m);
    PathPoint localPathPoint4 = a(paramEntity, paramPathPoint1.a, paramPathPoint1.b, paramPathPoint1.c - 1, m);
    if ((localPathPoint1 != null) && (!localPathPoint1.i) && (localPathPoint1.a(paramPathPoint2) < paramFloat)) {
        paramArrayOfPathPoint[(k++)] = localPathPoint1;
    }
    if ((localPathPoint2 != null) && (!localPathPoint2.i) && (localPathPoint2.a(paramPathPoint2) < paramFloat)) {
        paramArrayOfPathPoint[(k++)] = localPathPoint2;
    }
    if ((localPathPoint3 != null) && (!localPathPoint3.i) && (localPathPoint3.a(paramPathPoint2) < paramFloat)) {
        paramArrayOfPathPoint[(k++)] = localPathPoint3;
    }
    if ((localPathPoint4 != null) && (!localPathPoint4.i) && (localPathPoint4.a(paramPathPoint2) < paramFloat)) {
        paramArrayOfPathPoint[(k++)] = localPathPoint4;
    }
    return k;
}
Also used : PathPoint(net.minecraft.server.v1_8_R3.PathPoint) PathPoint(net.minecraft.server.v1_8_R3.PathPoint)

Example 37 with PathPoint

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

the class PlayerPathfinderAbstract method a.

@Override
protected PathPoint a(int paramInt1, int paramInt2, int paramInt3) {
    int i = PathPoint.a(paramInt1, paramInt2, paramInt3);
    PathPoint localPathPoint = this.b.get(i);
    if (localPathPoint == null) {
        localPathPoint = new PathPoint(paramInt1, paramInt2, paramInt3);
        this.b.a(i, localPathPoint);
    }
    return localPathPoint;
}
Also used : PathPoint(net.minecraft.server.v1_8_R3.PathPoint) PathPoint(net.minecraft.server.v1_8_R3.PathPoint)

Example 38 with PathPoint

use of net.minecraft.server.v1_16_R3.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_11_R1.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.k() != null) {
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < navigation.k().d(); i++) {
                        PathPoint pp = navigation.k().a(i);
                        org.bukkit.block.Block block = new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()).getBlock();
                        player.sendBlockChange(block.getLocation(), block.getType(), block.getData());
                    }
                }
            }
            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 && lastSpeed > 0) {
                if (Messaging.isDebugging()) {
                    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)) {
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < navigation.k().d(); i++) {
                        PathPoint pp = navigation.k().a(i);
                        player.sendBlockChange(new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()), Material.YELLOW_FLOWER, (byte) 0);
                    }
                }
            }
            navigation.a(params.speed());
            return NMSImpl.isNavigationFinished(navigation);
        }
    };
}
Also used : PathEntity(net.minecraft.server.v1_11_R1.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) CraftEntity(org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) Entity(net.minecraft.server.v1_11_R1.Entity) CraftPlayer(org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer) Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_11_R1.EntityPlayer) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) EntityInsentient(net.minecraft.server.v1_11_R1.EntityInsentient) NavigationAbstract(net.minecraft.server.v1_11_R1.NavigationAbstract) PathPoint(net.minecraft.server.v1_11_R1.PathPoint) EntityHumanNPC(net.citizensnpcs.nms.v1_11_R1.entity.EntityHumanNPC) PathPoint(net.minecraft.server.v1_11_R1.PathPoint) MCNavigator(net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator) EntityHorse(net.minecraft.server.v1_11_R1.EntityHorse) CancelReason(net.citizensnpcs.api.ai.event.CancelReason) Entity(net.minecraft.server.v1_11_R1.Entity) EntityPlayer(net.minecraft.server.v1_11_R1.EntityPlayer) Vector(org.bukkit.util.Vector)

Example 39 with PathPoint

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

the class PlayerPathfinder method a.

private PathEntity a(PathPoint paramPathPoint1, PathPoint paramPathPoint2, float paramFloat) {
    paramPathPoint1.e = 0.0F;
    paramPathPoint1.f = paramPathPoint1.c(paramPathPoint2);
    paramPathPoint1.g = paramPathPoint1.f;
    this.a.a();
    this.b.clear();
    this.a.a(paramPathPoint1);
    Object localObject1 = paramPathPoint1;
    int i = 0;
    while (!this.a.e()) {
        i++;
        if (i >= 2000) {
            break;
        }
        PathPoint localObject2 = this.a.c();
        if (localObject2.equals(paramPathPoint2)) {
            localObject1 = paramPathPoint2;
            break;
        }
        if (localObject2.c(paramPathPoint2) < ((PathPoint) localObject1).c(paramPathPoint2)) {
            localObject1 = localObject2;
        }
        localObject2.i = true;
        int j = this.d.a(this.c, localObject2, paramPathPoint2, paramFloat);
        for (int k = 0; k < j; k++) {
            PathPoint localPathPoint = this.c[k];
            float f1 = localObject2.c(localPathPoint);
            localPathPoint.j = (localObject2.j + f1);
            localPathPoint.k = (f1 + localPathPoint.l);
            float f2 = localObject2.e + localPathPoint.k;
            if ((localPathPoint.j < paramFloat) && ((!localPathPoint.a()) || (f2 < localPathPoint.e))) {
                localPathPoint.h = (localObject2);
                localPathPoint.e = f2;
                localPathPoint.f = (localPathPoint.c(paramPathPoint2) + localPathPoint.l);
                if (localPathPoint.a()) {
                    this.a.a(localPathPoint, localPathPoint.e + localPathPoint.f);
                } else {
                    localPathPoint.g = (localPathPoint.e + localPathPoint.f);
                    this.a.a(localPathPoint);
                }
            }
        }
    }
    if (localObject1 == paramPathPoint1) {
        return null;
    }
    Object localObject2 = a(paramPathPoint1, (PathPoint) localObject1);
    return (PathEntity) localObject2;
}
Also used : PathPoint(net.minecraft.server.v1_11_R1.PathPoint) PathEntity(net.minecraft.server.v1_11_R1.PathEntity) PathPoint(net.minecraft.server.v1_11_R1.PathPoint)

Example 40 with PathPoint

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

the class PlayerPathfinder method a.

private PathEntity a(IBlockAccess paramIBlockAccess, EntityHumanNPC paramEntityInsentient, double paramDouble1, double paramDouble2, double paramDouble3, float paramFloat) {
    this.a.a();
    this.d.a(paramIBlockAccess, paramEntityInsentient);
    PathPoint localPathPoint1 = this.d.b();
    PathPoint localPathPoint2 = this.d.a(paramDouble1, paramDouble2, paramDouble3);
    PathEntity localPathEntity = a(localPathPoint1, localPathPoint2, paramFloat);
    this.d.a();
    return localPathEntity;
}
Also used : PathPoint(net.minecraft.server.v1_11_R1.PathPoint) PathEntity(net.minecraft.server.v1_11_R1.PathEntity)

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 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 Iterator (java.util.Iterator)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