Search in sources :

Example 1 with EntityInsentient

use of net.minecraft.server.v1_8_R3.EntityInsentient in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelper_v1_8_R3 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_8_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) {
                    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.n();
            }
            nmsFollower.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
        }
    }.runTaskTimer(NMSHandler.getJavaPlugin(), 0, 10));
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) UUID(java.util.UUID) CompoundTag_v1_8_R3(net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_8_R3) net.minecraft.server.v1_8_R3(net.minecraft.server.v1_8_R3)

Example 2 with EntityInsentient

use of net.minecraft.server.v1_8_R3.EntityInsentient in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelper_v1_8_R3 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_8_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 = 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.m() || 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_8_R3.entity.CraftEntity) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CompoundTag_v1_8_R3(net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_8_R3) net.minecraft.server.v1_8_R3(net.minecraft.server.v1_8_R3)

Example 3 with EntityInsentient

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

the class NMSImpl method updatePathfindingRange.

@Override
public void updatePathfindingRange(NPC npc, float pathfindingRange) {
    if (!npc.isSpawned() || !npc.getEntity().getType().isAlive())
        return;
    EntityLiving en = NMSImpl.getHandle((LivingEntity) npc.getEntity());
    if (!(en instanceof EntityInsentient)) {
        if (en instanceof EntityHumanNPC) {
            ((EntityHumanNPC) en).updatePathfindingRange(pathfindingRange);
        }
        return;
    }
    if (PATHFINDING_RANGE == null)
        return;
    EntityInsentient handle = (EntityInsentient) en;
    NavigationAbstract navigation = handle.getNavigation();
    try {
        AttributeInstance inst = (AttributeInstance) PATHFINDING_RANGE.get(navigation);
        inst.setValue(pathfindingRange);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : EntityLiving(net.minecraft.server.v1_10_R1.EntityLiving) AttributeInstance(net.minecraft.server.v1_10_R1.AttributeInstance) EntityInsentient(net.minecraft.server.v1_10_R1.EntityInsentient) NavigationAbstract(net.minecraft.server.v1_10_R1.NavigationAbstract) EntityHumanNPC(net.citizensnpcs.nms.v1_10_R1.entity.EntityHumanNPC)

Example 4 with EntityInsentient

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

the class NMSImpl method setShouldJump.

@Override
public void setShouldJump(org.bukkit.entity.Entity entity) {
    Entity handle = NMSImpl.getHandle(entity);
    if (handle == null)
        return;
    if (handle instanceof EntityInsentient) {
        ControllerJump controller = ((EntityInsentient) handle).getControllerJump();
        controller.a();
    } else if (handle instanceof EntityHumanNPC) {
        ((EntityHumanNPC) handle).setShouldJump();
    }
}
Also used : PathEntity(net.minecraft.server.v1_8_R3.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) Entity(net.minecraft.server.v1_8_R3.Entity) CraftEntity(org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) EntityInsentient(net.minecraft.server.v1_8_R3.EntityInsentient) ControllerJump(net.minecraft.server.v1_8_R3.ControllerJump) EntityHumanNPC(net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC)

Example 5 with EntityInsentient

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

the class NMSImpl method updatePathfindingRange.

@Override
public void updatePathfindingRange(NPC npc, float pathfindingRange) {
    if (!npc.isSpawned() || !npc.getEntity().getType().isAlive())
        return;
    EntityLiving en = NMSImpl.getHandle((LivingEntity) npc.getEntity());
    if (!(en instanceof EntityInsentient)) {
        if (en instanceof EntityHumanNPC) {
            ((EntityHumanNPC) en).updatePathfindingRange(pathfindingRange);
        }
        return;
    }
    if (PATHFINDING_RANGE == null)
        return;
    EntityInsentient handle = (EntityInsentient) en;
    NavigationAbstract navigation = handle.getNavigation();
    try {
        AttributeInstance inst = (AttributeInstance) PATHFINDING_RANGE.get(navigation);
        inst.setValue(pathfindingRange);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : EntityLiving(net.minecraft.server.v1_8_R3.EntityLiving) AttributeInstance(net.minecraft.server.v1_8_R3.AttributeInstance) EntityInsentient(net.minecraft.server.v1_8_R3.EntityInsentient) NavigationAbstract(net.minecraft.server.v1_8_R3.NavigationAbstract) EntityHumanNPC(net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)14 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)13 EntityInsentient (net.minecraft.server.v1_12_R1.EntityInsentient)7 EntityHumanNPC (net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC)5 EntityHumanNPC (net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC)5 EntityInsentient (net.minecraft.server.v1_10_R1.EntityInsentient)5 EntityInsentient (net.minecraft.server.v1_11_R1.EntityInsentient)5 EntityInsentient (net.minecraft.server.v1_8_R3.EntityInsentient)5 CommandException (net.citizensnpcs.api.command.exception.CommandException)4 EntityHumanNPC (net.citizensnpcs.nms.v1_10_R1.entity.EntityHumanNPC)4 EntityHumanNPC (net.citizensnpcs.nms.v1_11_R1.entity.EntityHumanNPC)4 Entity (net.minecraft.server.v1_12_R1.Entity)4 Location (org.bukkit.Location)4 CraftEntity (org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity)4 Entity (net.minecraft.server.v1_10_R1.Entity)3 PathEntity (net.minecraft.server.v1_10_R1.PathEntity)3 Entity (net.minecraft.server.v1_11_R1.Entity)3 PathEntity (net.minecraft.server.v1_11_R1.PathEntity)3 PathEntity (net.minecraft.server.v1_12_R1.PathEntity)3 Entity (net.minecraft.server.v1_8_R3.Entity)3