Search in sources :

Example 1 with PathEntity

use of net.minecraft.server.v1_10_R1.PathEntity in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelper_v1_10_R1 method walkTo.

@Override
public void walkTo(final Entity entity, Location location, double speed, final Runnable callback) {
    if (entity == null || location == null) {
        return;
    }
    net.minecraft.server.v1_10_R1.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
    if (!(nmsEntityEntity instanceof EntityInsentient)) {
        return;
    }
    final EntityInsentient nmsEntity = (EntityInsentient) nmsEntityEntity;
    final NavigationAbstract entityNavigation = nmsEntity.getNavigation();
    final PathEntity path;
    final boolean aiDisabled = isAIDisabled(entity);
    if (aiDisabled) {
        toggleAI(entity, true);
        nmsEntity.onGround = true;
    }
    path = entityNavigation.a(location.getX(), location.getY(), location.getZ());
    if (path != null) {
        entityNavigation.a(path, 1D);
        entityNavigation.a(2D);
        final double oldSpeed = nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).b();
        nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
        new BukkitRunnable() {

            @Override
            public void run() {
                if (entityNavigation.n() || path.b()) {
                    if (callback != null) {
                        callback.run();
                    }
                    nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(oldSpeed);
                    if (aiDisabled) {
                        toggleAI(entity, false);
                    }
                    cancel();
                }
            }
        }.runTaskTimer(NMSHandler.getJavaPlugin(), 1, 1);
    } else //if (!Utilities.checkLocation(location, entity.getLocation(), 20)) {
    // TODO: generate waypoints to the target location?
    {
        entity.teleport(location);
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity) net.minecraft.server.v1_10_R1(net.minecraft.server.v1_10_R1) CompoundTag_v1_10_R1(net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_10_R1) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 2 with PathEntity

use of net.minecraft.server.v1_10_R1.PathEntity in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelper_v1_10_R1 method follow.

@Override
public void follow(final Entity target, final Entity follower, final double speed, final double lead, final double maxRange, final boolean allowWander) {
    if (target == null || follower == null) {
        return;
    }
    final net.minecraft.server.v1_10_R1.Entity nmsEntityFollower = ((CraftEntity) follower).getHandle();
    if (!(nmsEntityFollower instanceof EntityInsentient)) {
        return;
    }
    final EntityInsentient nmsFollower = (EntityInsentient) nmsEntityFollower;
    final NavigationAbstract followerNavigation = nmsFollower.getNavigation();
    UUID uuid = follower.getUniqueId();
    if (followTasks.containsKey(uuid)) {
        followTasks.get(uuid).cancel();
    }
    final int locationNearInt = (int) Math.floor(lead);
    final boolean hasMax = maxRange > lead;
    followTasks.put(follower.getUniqueId(), new BukkitRunnable() {

        private boolean inRadius = false;

        public void run() {
            if (!target.isValid() || !follower.isValid()) {
                this.cancel();
            }
            followerNavigation.a(2F);
            Location targetLocation = target.getLocation();
            PathEntity path;
            if (hasMax && !Utilities.checkLocation(targetLocation, follower.getLocation(), maxRange) && !target.isDead() && target.isOnGround()) {
                if (!inRadius) {
                    follower.teleport(Utilities.getWalkableLocationNear(targetLocation, locationNearInt));
                } else {
                    inRadius = false;
                    path = followerNavigation.a(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ());
                    if (path != null) {
                        followerNavigation.a(path, 1D);
                        followerNavigation.a(2D);
                    }
                }
            } else if (!inRadius && !Utilities.checkLocation(targetLocation, follower.getLocation(), lead)) {
                path = followerNavigation.a(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ());
                if (path != null) {
                    followerNavigation.a(path, 1D);
                    followerNavigation.a(2D);
                }
            } else {
                inRadius = true;
            }
            if (inRadius && !allowWander) {
                followerNavigation.o();
            }
            nmsFollower.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
        }
    }.runTaskTimer(NMSHandler.getJavaPlugin(), 0, 10));
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity) net.minecraft.server.v1_10_R1(net.minecraft.server.v1_10_R1) CompoundTag_v1_10_R1(net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_10_R1) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) UUID(java.util.UUID) Location(org.bukkit.Location)

Example 3 with PathEntity

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

the class PlayerNavigation method a.

@Override
public PathEntity a(BlockPosition paramBlockPosition) {
    BlockPosition localBlockPosition;
    if (this.b.getType(paramBlockPosition).getMaterial() == Material.AIR) {
        localBlockPosition = paramBlockPosition.down();
        while ((localBlockPosition.getY() > 0) && (this.b.getType(localBlockPosition).getMaterial() == Material.AIR)) {
            localBlockPosition = localBlockPosition.down();
        }
        if (localBlockPosition.getY() > 0) {
            return supera(localBlockPosition.up());
        }
        while ((localBlockPosition.getY() < this.b.getHeight()) && (this.b.getType(localBlockPosition).getMaterial() == Material.AIR)) {
            localBlockPosition = localBlockPosition.up();
        }
        paramBlockPosition = localBlockPosition;
    }
    if (this.b.getType(paramBlockPosition).getMaterial().isBuildable()) {
        localBlockPosition = paramBlockPosition.up();
        while ((localBlockPosition.getY() < this.b.getHeight()) && (this.b.getType(localBlockPosition).getMaterial().isBuildable())) {
            localBlockPosition = localBlockPosition.up();
        }
        return a2(localBlockPosition);
    }
    return a2(paramBlockPosition);
}
Also used : BlockPosition(net.minecraft.server.v1_10_R1.BlockPosition)

Example 4 with PathEntity

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

the class PlayerNavigation method supera.

public PathEntity supera(BlockPosition paramBlockPosition) {
    if (!b()) {
        return null;
    }
    if ((this.c != null) && (!this.c.b()) && (paramBlockPosition.equals(this.r))) {
        return this.c;
    }
    this.r = paramBlockPosition;
    float f1 = h();
    BlockPosition localBlockPosition = new BlockPosition(this.a);
    int i1 = (int) (f1 + 8.0F);
    ChunkCache localChunkCache = new ChunkCache(this.b, localBlockPosition.a(-i1, -i1, -i1), localBlockPosition.a(i1, i1, i1), 0);
    PathEntity localPathEntity = this.s.a(localChunkCache, this.a, this.r, f1);
    return localPathEntity;
}
Also used : ChunkCache(net.minecraft.server.v1_10_R1.ChunkCache) BlockPosition(net.minecraft.server.v1_10_R1.BlockPosition) PathEntity(net.minecraft.server.v1_10_R1.PathEntity) PathPoint(net.minecraft.server.v1_10_R1.PathPoint)

Example 5 with PathEntity

use of net.minecraft.server.v1_10_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;
    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_10_R1.PathPoint) PathEntity(net.minecraft.server.v1_10_R1.PathEntity) PathPoint(net.minecraft.server.v1_10_R1.PathPoint)

Aggregations

PathEntity (net.minecraft.server.v1_10_R1.PathEntity)5 PathPoint (net.minecraft.server.v1_10_R1.PathPoint)5 PathEntity (net.minecraft.server.v1_11_R1.PathEntity)5 PathPoint (net.minecraft.server.v1_11_R1.PathPoint)5 PathEntity (net.minecraft.server.v1_12_R1.PathEntity)4 PathPoint (net.minecraft.server.v1_12_R1.PathPoint)4 PathEntity (net.minecraft.server.v1_8_R3.PathEntity)4 PathPoint (net.minecraft.server.v1_8_R3.PathPoint)4 BlockPosition (net.minecraft.server.v1_10_R1.BlockPosition)3 CompoundTag_v1_10_R1 (net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_10_R1)2 net.minecraft.server.v1_10_R1 (net.minecraft.server.v1_10_R1)2 ChunkCache (net.minecraft.server.v1_10_R1.ChunkCache)2 BlockPosition (net.minecraft.server.v1_11_R1.BlockPosition)2 ChunkCache (net.minecraft.server.v1_11_R1.ChunkCache)2 BlockPosition (net.minecraft.server.v1_8_R3.BlockPosition)2 ChunkCache (net.minecraft.server.v1_8_R3.ChunkCache)2 CraftEntity (org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 UUID (java.util.UUID)1 Vec3D (net.minecraft.server.v1_10_R1.Vec3D)1