Search in sources :

Example 71 with LivingEntity

use of org.bukkit.entity.LivingEntity in project Citizens2 by CitizensDev.

the class CitizensNavigator method setTarget.

@Override
public void setTarget(Location target) {
    if (!npc.isSpawned())
        throw new IllegalStateException("npc is not spawned");
    if (target == null) {
        cancelNavigation();
        return;
    }
    switchParams();
    updatePathfindingRange();
    PathStrategy newStrategy;
    if (npc.isFlyable()) {
        newStrategy = new FlyingAStarNavigationStrategy(npc, target, localParams);
    } else if (localParams.useNewPathfinder() || !(npc.getEntity() instanceof LivingEntity)) {
        newStrategy = new AStarNavigationStrategy(npc, target, localParams);
    } else {
        newStrategy = new MCNavigationStrategy(npc, target, localParams);
    }
    switchStrategyTo(newStrategy);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) PathStrategy(net.citizensnpcs.api.ai.PathStrategy)

Example 72 with LivingEntity

use of org.bukkit.entity.LivingEntity in project Citizens2 by CitizensDev.

the class CitizensNavigator method setTarget.

@Override
public void setTarget(Iterable<Vector> path) {
    if (!npc.isSpawned())
        throw new IllegalStateException("npc is not spawned");
    if (path == null || Iterables.size(path) == 0) {
        cancelNavigation();
        return;
    }
    switchParams();
    updatePathfindingRange();
    PathStrategy newStrategy;
    if (npc.isFlyable()) {
        newStrategy = new FlyingAStarNavigationStrategy(npc, path, localParams);
    } else if (localParams.useNewPathfinder() || !(npc.getEntity() instanceof LivingEntity)) {
        newStrategy = new AStarNavigationStrategy(npc, path, localParams);
    } else {
        newStrategy = new MCNavigationStrategy(npc, path, localParams);
    }
    switchStrategyTo(newStrategy);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) PathStrategy(net.citizensnpcs.api.ai.PathStrategy)

Example 73 with LivingEntity

use of org.bukkit.entity.LivingEntity in project Citizens2 by CitizensDev.

the class MCTargetStrategy method update.

@Override
public boolean update() {
    if (target == null || !target.isValid()) {
        cancelReason = CancelReason.TARGET_DIED;
        return true;
    }
    if (target.getWorld() != handle.getWorld()) {
        cancelReason = CancelReason.TARGET_MOVED_WORLD;
        return true;
    }
    if (cancelReason != null) {
        return true;
    }
    if (!aggro && distanceSquared() <= parameters.distanceMargin()) {
        stop();
        return false;
    } else if (updateCounter == -1 || updateCounter++ > parameters.updatePathRate()) {
        targetNavigator.setPath();
        updateCounter = 0;
    }
    targetNavigator.update();
    NMS.look(handle, target);
    if (aggro && canAttack()) {
        AttackStrategy strategy = parameters.attackStrategy();
        if (strategy != null && strategy.handle((LivingEntity) handle, (LivingEntity) getTarget())) {
        } else if (strategy != parameters.defaultAttackStrategy()) {
            parameters.defaultAttackStrategy().handle((LivingEntity) handle, (LivingEntity) getTarget());
        }
        attackTicks = parameters.attackDelayTicks();
    }
    if (attackTicks > 0) {
        attackTicks--;
    }
    return false;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) AttackStrategy(net.citizensnpcs.api.ai.AttackStrategy)

Example 74 with LivingEntity

use of org.bukkit.entity.LivingEntity in project Citizens2 by CitizensDev.

the class Controllable method loadController.

private void loadController() {
    EntityType type = npc.getEntity().getType();
    if (explicitType != null) {
        type = explicitType;
    }
    if (!(npc.getEntity() instanceof LivingEntity) && (explicitType == null || explicitType == EntityType.UNKNOWN || npc.getEntity().getType() == explicitType)) {
        controller = new LookAirController();
        return;
    }
    Class<? extends MovementController> clazz = controllerTypes.get(type);
    if (clazz == null) {
        controller = new GroundController();
        return;
    }
    Constructor<? extends MovementController> innerConstructor = null;
    try {
        innerConstructor = clazz.getConstructor(Controllable.class);
        innerConstructor.setAccessible(true);
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        if (innerConstructor == null) {
            controller = clazz.newInstance();
        } else {
            controller = innerConstructor.newInstance(this);
        }
    } catch (Exception e) {
        e.printStackTrace();
        controller = new GroundController();
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) NPCLoadException(net.citizensnpcs.api.exception.NPCLoadException)

Example 75 with LivingEntity

use of org.bukkit.entity.LivingEntity in project Citizens2 by CitizensDev.

the class NMSImpl method setHeadYaw.

@Override
public void setHeadYaw(org.bukkit.entity.Entity entity, float yaw) {
    if (!(entity instanceof LivingEntity))
        return;
    EntityLiving handle = (EntityLiving) getHandle(entity);
    yaw = Util.clampYaw(yaw);
    handle.aP = yaw;
    if (!(handle instanceof EntityHuman))
        handle.aO = yaw;
    handle.aQ = yaw;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) EntityHuman(net.minecraft.server.v1_10_R1.EntityHuman) EntityLiving(net.minecraft.server.v1_10_R1.EntityLiving)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)322 Entity (org.bukkit.entity.Entity)169 Player (org.bukkit.entity.Player)121 Location (org.bukkit.Location)71 EventHandler (org.bukkit.event.EventHandler)63 Vector (org.bukkit.util.Vector)60 ItemStack (org.bukkit.inventory.ItemStack)47 ArrayList (java.util.ArrayList)41 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)37 PotionEffect (org.bukkit.potion.PotionEffect)34 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)30 Block (org.bukkit.block.Block)24 Mage (com.elmakers.mine.bukkit.api.magic.Mage)22 Projectile (org.bukkit.entity.Projectile)20 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)18 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)17 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)16 Target (com.elmakers.mine.bukkit.utility.Target)15 World (org.bukkit.World)14 Creature (org.bukkit.entity.Creature)14