Search in sources :

Example 76 with EntityInsentient

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

the class PlayerPathfinder method a.

@Override
public PathEntity a(ChunkCache var0, EntityInsentient var1, Set<BlockPosition> var2, float var3, int var4, float var5) {
    this.d.a();
    this.c.a(var0, var1);
    PathPoint var6 = this.c.b();
    Map var7 = var2.stream().collect(Collectors.toMap((var0x) -> {
        return this.c.a((double) var0x.getX(), (double) var0x.getY(), (double) var0x.getZ());
    }, Function.identity()));
    PathEntity var8 = this.a(var6, var7, var3, var4, var5);
    this.c.a();
    return var8;
}
Also used : Pathfinder(net.minecraft.server.v1_16_R3.Pathfinder) ImmutableSet(com.google.common.collect.ImmutableSet) EntityHumanNPC(net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC) PathEntity(net.minecraft.server.v1_16_R3.PathEntity) Set(java.util.Set) Setting(net.citizensnpcs.Settings.Setting) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) ChunkCache(net.minecraft.server.v1_16_R3.ChunkCache) Sets(com.google.common.collect.Sets) EntityInsentient(net.minecraft.server.v1_16_R3.EntityInsentient) List(java.util.List) Stream(java.util.stream.Stream) Lists(com.google.common.collect.Lists) PathPoint(net.minecraft.server.v1_16_R3.PathPoint) Map(java.util.Map) Optional(java.util.Optional) Path(net.minecraft.server.v1_16_R3.Path) Comparator(java.util.Comparator) PathDestination(net.minecraft.server.v1_16_R3.PathDestination) PathPoint(net.minecraft.server.v1_16_R3.PathPoint) PathEntity(net.minecraft.server.v1_16_R3.PathEntity) Map(java.util.Map)

Example 77 with EntityInsentient

use of net.minecraft.server.v1_16_R3.EntityInsentient in project Denizen by DenizenScript.

the class EntityHelperImpl method follow.

@Override
public void follow(final Entity target, final Entity follower, final double speed, final double lead, final double maxRange, final boolean allowWander, final boolean teleport) {
    if (target == null || follower == null) {
        return;
    }
    final net.minecraft.server.v1_16_R3.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) {
                    if (teleport) {
                        follower.teleport(Utilities.getWalkableLocationNear(targetLocation, locationNearInt));
                    } else {
                        cancel();
                    }
                } else {
                    inRadius = false;
                    path = followerNavigation.a(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ(), 0);
                    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(), 0);
                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 : net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Location(org.bukkit.Location)

Example 78 with EntityInsentient

use of net.minecraft.server.v1_16_R3.EntityInsentient in project Denizen by DenizenScript.

the class EntityHelperImpl method walkTo.

@Override
public void walkTo(final LivingEntity entity, Location location, Double speed, final Runnable callback) {
    if (entity == null || location == null) {
        return;
    }
    net.minecraft.server.v1_16_R3.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 = !entity.hasAI();
    if (aiDisabled) {
        entity.setAI(true);
        try {
            ENTITY_ONGROUND_SETTER.invoke(nmsEntity, true);
        } catch (Throwable ex) {
            Debug.echoError(ex);
        }
    }
    path = entityNavigation.a(location.getX(), location.getY(), location.getZ(), 0);
    if (path != null) {
        entityNavigation.a(path, 1D);
        entityNavigation.a(2D);
        final double oldSpeed = nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getBaseValue();
        if (speed != null) {
            nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                if (!entity.isValid()) {
                    if (callback != null) {
                        callback.run();
                    }
                    cancel();
                    return;
                }
                if (aiDisabled && entity instanceof Wolf) {
                    ((Wolf) entity).setAngry(false);
                }
                if (entityNavigation.m() || path.c()) {
                    if (callback != null) {
                        callback.run();
                    }
                    if (speed != null) {
                        nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(oldSpeed);
                    }
                    if (aiDisabled) {
                        entity.setAI(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 : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)43 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)42 Location (org.bukkit.Location)20 EntityInsentient (net.minecraft.server.v1_16_R3.EntityInsentient)12 EntityInsentient (net.minecraft.server.v1_15_R1.EntityInsentient)11 EntityHumanNPC (net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC)9 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)9 CommandException (net.citizensnpcs.api.command.exception.CommandException)8 EntityHumanNPC (net.citizensnpcs.nms.v1_15_R1.entity.EntityHumanNPC)8 EntityInsentient (net.minecraft.server.v1_12_R1.EntityInsentient)8 EntityInsentient (net.minecraft.server.v1_14_R1.EntityInsentient)8 PathEntity (net.minecraft.server.v1_16_R3.PathEntity)8 CancelReason (net.citizensnpcs.api.ai.event.CancelReason)7 EntityHumanNPC (net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC)7 EntityHumanNPC (net.citizensnpcs.nms.v1_14_R1.entity.EntityHumanNPC)7 MCNavigator (net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator)7 EntityInsentient (net.minecraft.server.v1_11_R1.EntityInsentient)7 PathEntity (net.minecraft.server.v1_15_R1.PathEntity)7 Entity (net.minecraft.server.v1_16_R3.Entity)7 CraftEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity)7