Search in sources :

Example 1 with EntityWhirlwind

use of am2.entities.EntityWhirlwind in project ArsMagica2 by Mithion.

the class EntityAIHurricane method updateTask.

@Override
public void updateTask() {
    host.getLookHelper().setLookPositionWithEntity(target, 30, 30);
    //host.getNavigator().tryMoveToEntityLiving(target, moveSpeed);
    List<EntityLivingBase> nearbyEntities = host.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, host.boundingBox.expand(6, 3, 6));
    for (EntityLivingBase ent : nearbyEntities) {
        if (ent == host)
            continue;
        if (!host.worldObj.isRemote && ent instanceof EntityWhirlwind) {
            ent.setDead();
            continue;
        }
        AMVector3 movement = MathUtilities.GetMovementVectorBetweenPoints(new AMVector3(host).add(new AMVector3(0, host.getEyeHeight(), 0)), new AMVector3(ent));
        float factor = 0.18f;
        double x = (movement.x * factor);
        double y = (movement.y * factor);
        double z = (movement.z * factor);
        double oX = ent.motionX, oY = ent.motionY, oZ = ent.motionZ;
        ent.addVelocity(x, y, z);
        if (Math.abs(ent.motionX) > Math.abs(x * 2)) {
            ent.motionX = x * (ent.motionX / ent.motionX);
        }
        if (Math.abs(ent.motionY) > Math.abs(y * 2)) {
            ent.motionY = y * (ent.motionY / ent.motionY);
        }
        if (Math.abs(ent.motionZ) > Math.abs(z * 2)) {
            ent.motionZ = z * (ent.motionZ / ent.motionZ);
        }
        if (ent instanceof EntityPlayer) {
            AMNetHandler.INSTANCE.sendVelocityAddPacket(host.worldObj, ent, -(oX - ent.motionX), -(oY - ent.motionY), -(oZ - ent.motionZ));
        }
        ent.fallDistance = 0f;
    }
}
Also used : AMVector3(am2.api.math.AMVector3) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityWhirlwind(am2.entities.EntityWhirlwind) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 2 with EntityWhirlwind

use of am2.entities.EntityWhirlwind in project ArsMagica2 by Mithion.

the class EntityAISpawnWhirlwind method updateTask.

@Override
public void updateTask() {
    host.getLookHelper().setLookPositionWithEntity(host.getAttackTarget(), 30, 30);
    if (host.getDistanceSqToEntity(host.getAttackTarget()) > 64) {
        double deltaZ = host.getAttackTarget().posZ - host.posZ;
        double deltaX = host.getAttackTarget().posX - host.posX;
        double angle = -Math.atan2(deltaZ, deltaX);
        double newX = host.getAttackTarget().posX + (Math.cos(angle) * 6);
        double newZ = host.getAttackTarget().posZ + (Math.sin(angle) * 6);
        host.getNavigator().tryMoveToXYZ(newX, host.getAttackTarget().posY, newZ, 0.5f);
    } else if (!host.canEntityBeSeen(host.getAttackTarget())) {
        host.getNavigator().tryMoveToEntityLiving(host.getAttackTarget(), 0.5f);
    } else {
        if (((IArsMagicaBoss) host).getCurrentAction() != BossActions.CASTING)
            ((IArsMagicaBoss) host).setCurrentAction(BossActions.CASTING);
        windTicks++;
        if (windTicks == 12 && !host.worldObj.isRemote) {
            if (!host.worldObj.isRemote)
                host.worldObj.playSoundAtEntity(host, ((IArsMagicaBoss) host).getAttackSound(), 1.0f, 1.0f);
            EntityWhirlwind whirlwind = new EntityWhirlwind(host.worldObj);
            whirlwind.setPosition(host.posX, host.posY + host.getEyeHeight(), host.posZ);
            host.worldObj.spawnEntityInWorld(whirlwind);
        }
    }
    if (windTicks >= 23) {
        resetTask();
    }
}
Also used : IArsMagicaBoss(am2.bosses.IArsMagicaBoss) EntityWhirlwind(am2.entities.EntityWhirlwind)

Aggregations

EntityWhirlwind (am2.entities.EntityWhirlwind)2 AMVector3 (am2.api.math.AMVector3)1 IArsMagicaBoss (am2.bosses.IArsMagicaBoss)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1