Search in sources :

Example 1 with ParticleChangeSize

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

the class EntityThrownRock method onUpdate.

@Override
public void onUpdate() {
    super.onUpdate();
    if (this.target != null && this.posY > this.target.y) {
        double deltaX = this.posX - target.x;
        double deltaY = this.posY - target.y;
        double deltaZ = this.posZ - target.z;
        double angle = Math.atan2(deltaZ, deltaX);
        double hDist = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
        double vAngle = Math.atan2(deltaY, hDist);
        motionX = -Math.cos(angle) * 0.2;
        motionZ = -Math.sin(angle) * 0.2;
        motionY = -Math.sin(vAngle) * 2.5;
    }
    if (!getIsMoonstoneMeteor() && !getIsShootingStar()) {
        if (!worldObj.isRemote && (throwingEntity == null || throwingEntity.isDead)) {
            setDead();
        } else {
            ticksExisted++;
            int maxTicksToLive = maxTicksToExist > -1 ? maxTicksToExist : 100;
            if (ticksExisted >= maxTicksToLive && !worldObj.isRemote) {
                setDead();
                return;
            }
        }
    }
    if (getIsShootingStar()) {
        motionY -= 0.1f;
        if (motionY < -2f)
            motionY = -2f;
    }
    if (worldObj.isRemote) {
        if (getIsMoonstoneMeteor()) {
            AMParticle fire = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, "explosion_2", posX, posY, posZ);
            if (fire != null) {
                fire.setMaxAge(20);
                fire.setRGBColorF(1, 1, 1);
                fire.setParticleScale(2.0f);
                fire.AddParticleController(new ParticleHoldPosition(fire, 20, 1, false));
                fire.AddParticleController(new ParticleColorShift(fire, 1, false).SetShiftSpeed(0.1f).SetColorTarget(0.01f, 0.01f, 0.01f).SetEndOnReachingTargetColor().setKillParticleOnFinish(false));
            }
        } else if (getIsShootingStar()) {
            int color = -1;
            if (getSpellStack() != null) {
                if (SpellUtils.instance.modifierIsPresent(SpellModifiers.COLOR, getSpellStack(), 0)) {
                    ISpellModifier[] mods = SpellUtils.instance.getModifiersForStage(getSpellStack(), 0);
                    int ordinalCount = 0;
                    for (ISpellModifier mod : mods) {
                        if (mod instanceof Colour) {
                            byte[] meta = SpellUtils.instance.getModifierMetadataFromStack(getSpellStack(), mod, 0, ordinalCount++);
                            color = (int) mod.getModifier(SpellModifiers.COLOR, null, null, null, meta);
                        }
                    }
                }
            }
            for (float i = 0; i < Math.abs(motionY); i += 0.1f) {
                AMParticle star = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, "ember", posX + motionX * i, posY + motionY * i, posZ + motionZ * i);
                if (star != null) {
                    star.setMaxAge(22);
                    float clr = rand.nextFloat();
                    float clrMod = Minecraft.getMinecraft().theWorld.rand.nextFloat();
                    int finalColor = -1;
                    if (color == -1)
                        finalColor = MathUtilities.colorFloatsToInt(0.24f * clrMod, 0.58f * clrMod, 0.71f * clrMod);
                    else {
                        float[] colors = MathUtilities.colorIntToFloats(color);
                        for (int c = 0; c < colors.length; ++c) colors[c] = colors[c] * clrMod;
                        finalColor = MathUtilities.colorFloatsToInt(colors[0], colors[1], colors[2]);
                    }
                    star.setRGBColorI(finalColor);
                    star.AddParticleController(new ParticleHoldPosition(star, 20, 1, false));
                    star.AddParticleController(new ParticleChangeSize(star, 0.5f, 0.05f, 20, 1, false));
                }
            }
        }
    }
    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(throwingEntity) && 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.2F;
    rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;
    float f1 = 0.95F;
    setPosition(posX, posY, posZ);
}
Also used : Entity(net.minecraft.entity.Entity) AMParticle(am2.particles.AMParticle) ParticleColorShift(am2.particles.ParticleColorShift) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) ParticleHoldPosition(am2.particles.ParticleHoldPosition) Colour(am2.spell.modifiers.Colour) ParticleChangeSize(am2.particles.ParticleChangeSize) List(java.util.List)

Example 2 with ParticleChangeSize

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

the class AMPacketProcessorClient method handleStarFall.

private void handleStarFall(byte[] data) {
    AMDataReader rdr = new AMDataReader(data, false);
    double x = rdr.getDouble();
    double y = rdr.getDouble();
    double z = rdr.getDouble();
    ItemStack spellStack = null;
    if (rdr.getBoolean())
        spellStack = rdr.getItemStack();
    int color = -1;
    if (spellStack != null) {
        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);
                }
            }
        }
    }
    for (int i = 0; i < 360; i += AMCore.config.FullGFX() ? 5 : AMCore.config.LowGFX() ? 10 : 20) {
        AMParticle effect = (AMParticle) AMCore.instance.proxy.particleManager.spawn(Minecraft.getMinecraft().theWorld, "sparkle2", x, y + 1.5, z);
        if (effect != null) {
            effect.setIgnoreMaxAge(true);
            effect.AddParticleController(new ParticleMoveOnHeading(effect, i, 0, 0.7f, 1, false));
            float clrMod = Minecraft.getMinecraft().theWorld.rand.nextFloat();
            int finalColor = -1;
            if (color == -1)
                finalColor = MathUtilities.colorFloatsToInt(0.24f * clrMod, 0.58f * clrMod, 0.71f * clrMod);
            else {
                float[] colors = MathUtilities.colorIntToFloats(color);
                for (int c = 0; c < colors.length; ++c) colors[c] = colors[c] * clrMod;
                finalColor = MathUtilities.colorFloatsToInt(colors[0], colors[1], colors[2]);
            }
            effect.setParticleScale(1.2f);
            effect.noClip = false;
            effect.setRGBColorI(finalColor);
            effect.AddParticleController(new ParticleFadeOut(effect, 1, false).setFadeSpeed(0.05f).setKillParticleOnFinish(true));
            effect.AddParticleController(new ParticleLeaveParticleTrail(effect, "sparkle2", false, 15, 1, false).addControllerToParticleList(new ParticleChangeSize(effect, 1.2f, 0.01f, 15, 1, false)).setParticleRGB_I(finalColor).setChildAffectedByGravity().addRandomOffset(0.2f, 0.2f, 0.2f));
        }
    }
    Minecraft.getMinecraft().theWorld.playSound(x, y, z, "arsmagica2:spell.special.starfall", 2.0f, 1.0f, false);
}
Also used : ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) Colour(am2.spell.modifiers.Colour) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)2 Colour (am2.spell.modifiers.Colour)2 AMParticle (am2.particles.AMParticle)1 ParticleChangeSize (am2.particles.ParticleChangeSize)1 ParticleColorShift (am2.particles.ParticleColorShift)1 ParticleHoldPosition (am2.particles.ParticleHoldPosition)1 List (java.util.List)1 Entity (net.minecraft.entity.Entity)1 ItemStack (net.minecraft.item.ItemStack)1