Search in sources :

Example 61 with AMParticle

use of am2.particles.AMParticle in project ArsMagica2 by Mithion.

the class EntitySpellProjectile method onUpdate.

@Override
public void onUpdate() {
    // super.onUpdate();
    if (!worldObj.isRemote && (getShootingEntity() == null || getShootingEntity().isDead)) {
        setDead();
    } else {
        ticksExisted++;
        int maxTicksToLive = maxTicksToExist > -1 ? maxTicksToExist : 100;
        if (ticksExisted >= maxTicksToLive && !worldObj.isRemote) {
            setDead();
            return;
        }
    }
    // TODO Fix homing
    if (this.dataWatcher.getWatchableObjectByte(DW_HOMING) != (byte) 0 && this.ticksExisted > 10) {
        if (this.dataWatcher.getWatchableObjectInt(DW_HOMING_TARGET) == -1) {
            findHomingTarget();
        } else {
            EntityLivingBase homingTarget = getHomingEntity();
            // AMCore.log.info("%.2f, %.2f, %.2f", posX, posY, posZ);
            LogHelper.trace("Homing Target: " + getHomingEntity());
            if (homingTarget != null && new AMVector3(this).distanceSqTo(new AMVector3(homingTarget)) > 2) {
                this.moveTowards(homingTarget, 60, 60);
            }
        }
    }
    Vec3 vec3d = Vec3.createVectorHelper(posX, posY, posZ);
    Vec3 vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
    MovingObjectPosition movingobjectposition = null;
    movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1, true);
    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(getShootingEntity())) {
            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) {
        if (entity instanceof EntityDragonPart && ((EntityDragonPart) entity).entityDragonObj != null && ((EntityDragonPart) entity).entityDragonObj instanceof EntityLivingBase) {
            entity = (EntityLivingBase) ((EntityDragonPart) entity).entityDragonObj;
        }
        movingobjectposition = new MovingObjectPosition(entity);
    }
    if (movingobjectposition != null) {
        boolean doHit = true;
        boolean pierce = this.getNumPierces() > 0;
        if (movingobjectposition.typeOfHit == MovingObjectType.ENTITY && movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityLivingBase) {
            EntityLivingBase ent = (EntityLivingBase) movingobjectposition.entityHit;
            if (ent.isPotionActive(BuffList.spellReflect.id) && !pierce) {
                doHit = false;
                this.setShootingEntity(ent);
                this.motionX = -this.motionX;
                this.motionY = -this.motionY;
                this.motionZ = -this.motionZ;
                if (!worldObj.isRemote)
                    ent.removePotionEffect(BuffList.spellReflect.id);
                setBounces(originalBounceCount);
                if (worldObj.isRemote) {
                    for (int i = 0; i < 13; ++i) {
                        AMParticle effect = (AMParticle) AMCore.instance.proxy.particleManager.spawn(worldObj, "hr_lensflare", ent.posX + rand.nextDouble() - 0.5, ent.posY + ent.getEyeHeight() + rand.nextDouble() - 0.5, ent.posZ + rand.nextDouble() - 0.5);
                        if (effect != null) {
                            EntityPlayer player = AMCore.instance.proxy.getLocalPlayer();
                            effect.setIgnoreMaxAge(true);
                            if (player != null && ent != player) {
                                effect.setParticleScale(1.5f);
                            }
                            effect.setRGBColorF(0.5f + rand.nextFloat() * 0.5f, 0.2f, 0.5f + rand.nextFloat() * 0.5f);
                            effect.AddParticleController(new ParticleHoldPosition(effect, 100, 1, false));
                        }
                    }
                }
            }
        } else if (movingobjectposition.typeOfHit == MovingObjectType.BLOCK && getBounces() > 0) {
            doHit = false;
            switch(movingobjectposition.sideHit) {
                case 0:
                case 1:
                    motionY = motionY * friction_coefficient * -1;
                    break;
                case 2:
                case 3:
                    motionZ = motionZ * friction_coefficient * -1;
                    break;
                case 4:
                case 5:
                    motionX = motionX * friction_coefficient * -1;
                    break;
            }
            this.setBounces(getBounces() - 1);
        }
        if (movingobjectposition.typeOfHit == MovingObjectType.BLOCK) {
            Block block = worldObj.getBlock(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ);
            AxisAlignedBB bb = block.getCollisionBoundingBoxFromPool(worldObj, movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ);
            if (bb == null && !SpellUtils.instance.modifierIsPresent(SpellModifiers.TARGET_NONSOLID_BLOCKS, getEffectStack(), 0))
                doHit = false;
        }
        if (doHit)
            HitObject(movingobjectposition, pierce);
    }
    if (getGravity() < 0 && motionY > GRAVITY_TERMINAL_VELOCITY) {
        this.motionY += getGravity();
    } else if (getGravity() > 0 && motionY < -GRAVITY_TERMINAL_VELOCITY) {
        this.motionY -= getGravity();
    }
    posX += motionX;
    posY += motionY;
    posZ += motionZ;
    float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
    rotationYaw = (float) (Math.atan2(motionX, motionZ));
    for (rotationPitch = (float) (Math.atan2(motionY, f)); 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.2F;
    rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;
    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;
    }
    if (!AMCore.config.NoGFX() && worldObj.isRemote && this.getShootingEntity() instanceof EntityPlayer) {
        if (this.particleType == null || this.particleType.isEmpty())
            particleType = AMParticleIcons.instance.getSecondaryParticleForAffinity(SpellUtils.instance.mainAffinityFor(getEffectStack()));
        AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, particleType, this.posX, this.posY, this.posZ);
        if (particle != null) {
            particle.addRandomOffset(0.3f, 0.3f, 0.3f);
            particle.AddParticleController(new ParticleFloatUpward(particle, 0.1f, 0, 1, false));
            particle.setMaxAge(10);
            particle.setParticleScale(0.05f);
        }
    }
    setPosition(posX, posY, posZ);
}
Also used : Entity(net.minecraft.entity.Entity) AMParticle(am2.particles.AMParticle) ParticleHoldPosition(am2.particles.ParticleHoldPosition) ParticleFloatUpward(am2.particles.ParticleFloatUpward) AMVector3(am2.api.math.AMVector3) EntityDragonPart(net.minecraft.entity.boss.EntityDragonPart) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) ArrayList(java.util.ArrayList) BuffList(am2.buffs.BuffList) List(java.util.List)

Example 62 with AMParticle

use of am2.particles.AMParticle in project ArsMagica2 by Mithion.

the class EntityShadowHelper method spawnParticles.

private void spawnParticles() {
    if (worldObj.isRemote) {
        for (int i = 0; i < 25 * AMCore.config.getGFXLevel() + 1; ++i) {
            AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, "arcane", posX, posY, posZ);
            if (particle != null) {
                particle.addRandomOffset(1, 1, 1);
                particle.AddParticleController(new ParticleFloatUpward(particle, 0, 0.02f + getRNG().nextFloat() * 0.2f, 1, false));
                particle.setIgnoreMaxAge(false);
                particle.setMaxAge(20 + getRNG().nextInt(20));
            }
        }
    }
}
Also used : AMParticle(am2.particles.AMParticle) ParticleFloatUpward(am2.particles.ParticleFloatUpward)

Example 63 with AMParticle

use of am2.particles.AMParticle in project ArsMagica2 by Mithion.

the class EntitySpellEffect method zoneUpdate.

private void zoneUpdate() {
    if (this.worldObj.isRemote) {
        if (!AMCore.config.NoGFX()) {
            this.rotation += this.rotationSpeed;
            this.rotation %= 360;
            double dist = this.dataWatcher.getWatchableObjectFloat(WATCHER_RADIUS);
            double _rotation = rotation;
            if (spellStack == null) {
                spellStack = this.dataWatcher.getWatchableObjectItemStack(22);
                if (spellStack == null) {
                    return;
                }
            }
            int color = 0xFFFFFF;
            if (SpellUtils.instance.modifierIsPresent(SpellModifiers.COLOR, spellStack, 0)) {
                ISpellModifier[] mods = SpellUtils.instance.getModifiersForStage(spellStack, 0);
                int ordinalCount = 0;
                for (ISpellModifier mod : mods) {
                    if (mod instanceof Colour) {
                        byte[] meta = SpellUtils.instance.getModifierMetadataFromStack(spellStack, mod, 0, ordinalCount++);
                        color = (int) mod.getModifier(SpellModifiers.COLOR, null, null, null, meta);
                    }
                }
            }
            if ((AMCore.config.FullGFX() && this.ticksExisted % 2 == 0) || this.ticksExisted % 8 == 0) {
                for (int i = 0; i < 4; ++i) {
                    _rotation = (rotation + (90 * i)) % 360;
                    double x = this.posX - Math.cos(3.141 / 180 * (_rotation)) * dist;
                    double z = this.posZ - Math.sin(3.141 / 180 * (_rotation)) * dist;
                    AMParticle effect = (AMParticle) AMCore.instance.proxy.particleManager.spawn(worldObj, AMParticleIcons.instance.getParticleForAffinity(SpellUtils.instance.mainAffinityFor(spellStack)), x, posY, z);
                    if (effect != null) {
                        effect.setIgnoreMaxAge(false);
                        effect.setMaxAge(20);
                        effect.setParticleScale(0.15f);
                        effect.setRGBColorI(color);
                        effect.AddParticleController(new ParticleFloatUpward(effect, 0, 0.07f, 1, false));
                        if (AMCore.config.LowGFX()) {
                            effect.AddParticleController(new ParticleOrbitPoint(effect, posX, posY, posZ, 2, false).setIgnoreYCoordinate(true).SetOrbitSpeed(0.05f).SetTargetDistance(dist).setRotateDirection(true));
                        }
                    }
                }
            }
        }
    }
    this.moveEntity(0, this.dataWatcher.getWatchableObjectInt(WATCHER_GRAVITY) / 100.0f, 0);
    ticksToEffect--;
    if (spellStack == null) {
        if (!worldObj.isRemote) {
            this.setDead();
        }
        return;
    }
    if (dummycaster == null) {
        dummycaster = DummyEntityPlayer.fromEntityLiving(new EntityDummyCaster(worldObj));
    }
    if (ticksToEffect <= 0) {
        ticksToEffect = maxTicksToEffect;
        float radius = this.dataWatcher.getWatchableObjectFloat(WATCHER_RADIUS);
        List<Entity> possibleTargets = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(posX - radius, posY - 1, posZ - radius, posX + radius, posY + 3, posZ + radius));
        for (Entity e : possibleTargets) {
            if (e instanceof EntityDragonPart && ((EntityDragonPart) e).entityDragonObj instanceof EntityLivingBase)
                e = (EntityLivingBase) ((EntityDragonPart) e).entityDragonObj;
            if (e instanceof EntityLivingBase)
                SpellHelper.instance.applyStageToEntity(spellStack, dummycaster, worldObj, e, 0, false);
        }
        if (this.dataWatcher.getWatchableObjectInt(WATCHER_GRAVITY) < 0 && !firstApply)
            SpellHelper.instance.applyStackStage(spellStack, dummycaster, null, posX, posY - 1, posZ, 0, worldObj, false, false, this.ticksExisted);
        else
            SpellHelper.instance.applyStackStage(spellStack, dummycaster, null, posX, posY, posZ, 0, worldObj, false, false, this.ticksExisted);
        firstApply = false;
    }
}
Also used : Entity(net.minecraft.entity.Entity) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) Colour(am2.spell.modifiers.Colour) EntityDragonPart(net.minecraft.entity.boss.EntityDragonPart) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 64 with AMParticle

use of am2.particles.AMParticle in project ArsMagica2 by Mithion.

the class EntityFlicker method onUpdate.

@Override
public void onUpdate() {
    super.onUpdate();
    this.motionX = 0;
    this.motionY = 0;
    this.motionZ = 0;
    long time = worldObj.getWorldTime() % 24000;
    if (!worldObj.isRemote && time >= 18500 && time <= 18600) {
        // this.dataWatcher.updateObject(WATCHER_AMBIENTFLICK, (byte)1);
        this.setDead();
        return;
    }
    boolean playerClose = false;
    AMVector3 me = new AMVector3(this);
    if (!worldObj.isRemote) {
        for (Object o : worldObj.playerEntities) {
            if (me.distanceSqTo(new AMVector3((EntityPlayer) o)) < 25) {
                ItemStack chestArmor = ((EntityPlayer) o).getCurrentArmor(2);
                if (chestArmor == null || !ArmorHelper.isInfusionPreset(chestArmor, GenericImbuement.flickerLure))
                    playerClose = true;
                break;
            }
        }
    }
    if (this.ticksExisted > 100 && playerClose && this.dataWatcher.getWatchableObjectByte(WATCHER_AMBIENTFLICK) == (byte) 0) {
        if (this.getActivePotionEffects().size() == 0 || (this.getActivePotionEffects().size() == 1 && worldObj.rand.nextDouble() < 0.1f))
            this.dataWatcher.updateObject(WATCHER_AMBIENTFLICK, (byte) 1);
    } else if (this.dataWatcher.getWatchableObjectByte(WATCHER_AMBIENTFLICK) == (byte) 1) {
        flickCount++;
        if (worldObj.isRemote && flickCount > 7)
            // client flick
            flick();
        else if (!worldObj.isRemote && flickCount > 10)
            // server flick
            flick();
    }
    if (worldObj.isRemote) {
        // for (int i = 0; i < + 1; ++i){
        if (getRNG().nextInt(10) < AMCore.config.getGFXLevel()) {
            AMParticle effect = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, AMParticleIcons.instance.getParticleForAffinity(getFlickerAffinity()), posX, posY, posZ);
            if (effect != null) {
                effect.addRandomOffset(this.width, this.height, this.width);
                effect.setDontRequireControllers();
                effect.setMaxAge(10);
                if (getFlickerAffinity() == Affinity.EARTH)
                    effect.setParticleScale(0.01f + rand.nextFloat() * 0.05f);
                else
                    effect.setParticleScale(0.05f + rand.nextFloat() * 0.05f);
            }
        }
    }
}
Also used : AMVector3(am2.api.math.AMVector3) AMParticle(am2.particles.AMParticle) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 65 with AMParticle

use of am2.particles.AMParticle in project ArsMagica2 by Mithion.

the class EntityFlicker method flick.

private void flick() {
    if (this.worldObj.isRemote) {
        for (int i = 0; i < 10 * AMCore.config.getGFXLevel(); ++i) {
            AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, "radiant", posX, posY, posZ);
            if (particle != null) {
                particle.AddParticleController(new ParticleMoveOnHeading(particle, worldObj.rand.nextDouble() * 360, worldObj.rand.nextDouble() * 360, worldObj.rand.nextDouble() * 0.3f + 0.01f, 1, false));
                particle.setRGBColorI(getFlickerAffinity().color);
                particle.AddParticleController(new ParticleFadeOut(particle, 1, false).setFadeSpeed((float) (worldObj.rand.nextDouble() * 0.1 + 0.05)).setKillParticleOnFinish(true));
                particle.setIgnoreMaxAge(true);
                particle.setParticleScale(0.1f);
            }
        }
    } else {
        this.setDead();
    }
}
Also used : AMParticle(am2.particles.AMParticle) ParticleFadeOut(am2.particles.ParticleFadeOut) ParticleMoveOnHeading(am2.particles.ParticleMoveOnHeading)

Aggregations

AMParticle (am2.particles.AMParticle)103 ParticleFloatUpward (am2.particles.ParticleFloatUpward)38 ParticleFadeOut (am2.particles.ParticleFadeOut)25 ParticleOrbitEntity (am2.particles.ParticleOrbitEntity)19 ParticleMoveOnHeading (am2.particles.ParticleMoveOnHeading)13 EntityLivingBase (net.minecraft.entity.EntityLivingBase)13 ParticleHoldPosition (am2.particles.ParticleHoldPosition)11 Entity (net.minecraft.entity.Entity)9 AMVector3 (am2.api.math.AMVector3)8 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)8 Colour (am2.spell.modifiers.Colour)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 ItemStack (net.minecraft.item.ItemStack)7 ParticleOrbitPoint (am2.particles.ParticleOrbitPoint)6 SideOnly (cpw.mods.fml.relauncher.SideOnly)6 Block (net.minecraft.block.Block)6 EntityDragonPart (net.minecraft.entity.boss.EntityDragonPart)6 TileEntity (net.minecraft.tileentity.TileEntity)5 List (java.util.List)4 BuffEffectFrostSlowed (am2.buffs.BuffEffectFrostSlowed)3