Search in sources :

Example 1 with EntityWinterGuardian

use of am2.bosses.EntityWinterGuardian in project ArsMagica2 by Mithion.

the class EntityWinterGuardianArm method onUpdate.

@Override
public void onUpdate() {
    if (!worldObj.isRemote && (getThrowingEntity() == null || getThrowingEntity().isDead)) {
        setDead();
        return;
    } else {
        ticksExisted++;
        if (ticksExisted >= maxTicksToExist && !worldObj.isRemote) {
            setDead();
            return;
        }
    }
    if (!takenArm && getThrowingEntity() != null && getThrowingEntity() instanceof EntityWinterGuardian) {
        ((EntityWinterGuardian) getThrowingEntity()).launchOneArm();
        takenArm = true;
    }
    Vec3 vec3d = Vec3.createVectorHelper(posX, posY, posZ);
    Vec3 vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
    MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1);
    vec3d = Vec3.createVectorHelper(posX, posY, posZ);
    vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
    if (movingobjectposition != null) {
        vec3d1 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
    }
    Entity entity = null;
    List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
    double d = 0.0D;
    for (int j = 0; j < list.size(); j++) {
        Entity entity1 = (Entity) list.get(j);
        if (!entity1.canBeCollidedWith() || entity1.isEntityEqual(getThrowingEntity()) && ticksExisted < 25) {
            continue;
        }
        float f2 = 0.3F;
        AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f2, f2, f2);
        MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
        if (movingobjectposition1 == null) {
            continue;
        }
        double d1 = vec3d.distanceTo(movingobjectposition1.hitVec);
        if (d1 < d || d == 0.0D) {
            entity = entity1;
            d = d1;
        }
    }
    if (entity != null) {
        movingobjectposition = new MovingObjectPosition(entity);
    }
    if (movingobjectposition != null) {
        HitObject(movingobjectposition);
    }
    posX += motionX;
    posY += motionY;
    posZ += motionZ;
    float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
    rotationYaw = (float) ((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
    for (rotationPitch = (float) ((Math.atan2(motionY, f) * 180D) / 3.1415927410125732D); rotationPitch - prevRotationPitch < -180F; prevRotationPitch -= 360F) {
    }
    for (; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) {
    }
    for (; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) {
    }
    for (; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) {
    }
    rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.4F;
    rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.4F;
    float f1 = 0.95F;
    if (isInWater()) {
        for (int k = 0; k < 4; k++) {
            float f3 = 0.25F;
            worldObj.spawnParticle("bubble", posX - motionX * f3, posY - motionY * f3, posZ - motionZ * f3, motionX, motionY, motionZ);
        }
        f1 = 0.8F;
    } else {
        for (int i = 0; i < 2; ++i) {
            AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, "ember", posX + rand.nextFloat() * 0.2 - 0.1, posY + 1.2, posZ + rand.nextFloat() * 0.2 - 0.1);
            if (particle != null) {
                particle.setIgnoreMaxAge(false);
                particle.setMaxAge(15);
                particle.setParticleScale(0.35f);
                particle.setRGBColorF(0.5098f, 0.7843f, 0.7843f);
                particle.AddParticleController(new ParticleMoveOnHeading(particle, Math.toDegrees(this.rotationPitch), Math.toDegrees(this.rotationYaw), 0.2f, 1, false));
            }
        }
    }
    setPosition(posX, posY, posZ);
    int halflife = 80;
    if (this.ticksExisted > 30 && this.ticksExisted < halflife) {
        this.motionX *= 0.8f;
        this.motionY *= 0.8f;
        this.motionZ *= 0.8f;
    } else if (this.ticksExisted > halflife && getThrowingEntity() != null) {
        double deltaX = this.posX - getThrowingEntity().posX;
        double deltaZ = this.posZ - getThrowingEntity().posZ;
        double deltaY = this.posY - (getThrowingEntity().posY + getThrowingEntity().getEyeHeight());
        double angle = Math.atan2(deltaZ, deltaX);
        double speed = Math.min((this.ticksExisted - halflife) / 10f, this.getProjectileSpeed());
        double horizontalDistance = MathHelper.sqrt_double(deltaX * deltaX + deltaZ * deltaZ);
        float pitchRotation = (float) (-Math.atan2(deltaY, horizontalDistance));
        this.motionX = -Math.cos(angle) * speed;
        this.motionZ = -Math.sin(angle) * speed;
        this.motionY = Math.sin(pitchRotation) * speed;
        if (this.entityHit != null) {
            Entity entityhit = worldObj.getEntityByID(this.entityHit);
            if (entityhit != null) {
                entityhit.posX = this.posX;
                entityhit.posY = this.posY - entityhit.height / 2 + 1.2;
                entityhit.posZ = this.posZ;
                entityhit.motionX = this.motionX;
                entityhit.motionY = this.motionY;
                entityhit.motionZ = this.motionZ;
                entityhit.lastTickPosX = this.lastTickPosX;
                entityhit.lastTickPosY = this.lastTickPosY - entityhit.height / 2 + 1.2;
                entityhit.lastTickPosZ = this.lastTickPosZ;
                entityhit.fallDistance = 0;
            }
        }
        if (this.getDistanceSqToEntity(getThrowingEntity()) < 9 && !worldObj.isRemote) {
            this.setDead();
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) AMParticle(am2.particles.AMParticle) List(java.util.List) EntityWinterGuardian(am2.bosses.EntityWinterGuardian) ParticleMoveOnHeading(am2.particles.ParticleMoveOnHeading)

Example 2 with EntityWinterGuardian

use of am2.bosses.EntityWinterGuardian in project ArsMagica2 by Mithion.

the class EntityWinterGuardianArm method setDead.

@Override
public void setDead() {
    if (getThrowingEntity() != null) {
        if (getThrowingEntity() instanceof EntityWinterGuardian) {
            ((EntityWinterGuardian) getThrowingEntity()).returnOneArm();
        } else if (getThrowingEntity() instanceof EntityPlayer && !this.worldObj.isRemote) {
            if (getThrowingEntity().getHealth() <= 0) {
                PlayerTracker.storeSoulboundItemForRespawn((EntityPlayer) getThrowingEntity(), ItemsCommonProxy.winterArmEnchanted.copy());
            } else {
                if (!((EntityPlayer) getThrowingEntity()).inventory.addItemStackToInventory(ItemsCommonProxy.winterArmEnchanted.copy())) {
                    EntityItem item = new EntityItem(worldObj);
                    item.setPosition(posX, posY, posZ);
                    item.setEntityItemStack(ItemsCommonProxy.winterArmEnchanted.copy());
                    worldObj.spawnEntityInWorld(item);
                }
            }
        }
    }
    if (entityHit != null) {
        Entity entityhit = worldObj.getEntityByID(this.entityHit);
        if (entityhit != null) {
            entityhit.motionX = 0;
            entityhit.motionY = 0;
            entityhit.motionZ = 0;
        }
    }
    super.setDead();
}
Also used : Entity(net.minecraft.entity.Entity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityWinterGuardian(am2.bosses.EntityWinterGuardian) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

EntityWinterGuardian (am2.bosses.EntityWinterGuardian)2 Entity (net.minecraft.entity.Entity)2 AMParticle (am2.particles.AMParticle)1 ParticleMoveOnHeading (am2.particles.ParticleMoveOnHeading)1 List (java.util.List)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1