Search in sources :

Example 1 with Colour

use of am2.spell.modifiers.Colour 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 Colour

use of am2.spell.modifiers.Colour in project ArsMagica2 by Mithion.

the class EntitySpellEffect method wallUpdate.

private void wallUpdate() {
    if (worldObj.isRemote) {
        if (spellStack == null) {
            spellStack = this.dataWatcher.getWatchableObjectItemStack(22);
            if (spellStack == null) {
                return;
            }
        }
        double dist = this.dataWatcher.getWatchableObjectFloat(WATCHER_RADIUS);
        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);
                }
            }
        }
        double px = Math.cos(3.141 / 180 * (rotationYaw + 90)) * 0.1f;
        double pz = Math.sin(3.141 / 180 * (rotationYaw + 90)) * 0.1f;
        double py = 0.1f;
        for (float i = 0; i < dist; i += 0.5f) {
            double x = this.posX - Math.cos(3.141 / 180 * (rotationYaw)) * i;
            double z = this.posZ - Math.sin(3.141 / 180 * (rotationYaw)) * i;
            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.addRandomOffset(1, 1, 1);
                effect.setParticleScale(0.15f);
                effect.setRGBColorI(color);
                if (dataWatcher.getWatchableObjectInt(WATCHER_TYPE) == TYPE_WALL) {
                    effect.AddParticleController(new ParticleFloatUpward(effect, 0, 0.07f, 1, false));
                } else {
                    effect.setAffectedByGravity();
                    effect.setDontRequireControllers();
                    effect.addVelocity(px, py, pz);
                }
            }
            x = this.posX - Math.cos(Math.toRadians(rotationYaw)) * -i;
            z = this.posZ - Math.sin(Math.toRadians(rotationYaw)) * -i;
            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.addRandomOffset(1, 1, 1);
                effect.setMaxAge(20);
                effect.setParticleScale(0.15f);
                effect.setRGBColorI(color);
                if (dataWatcher.getWatchableObjectInt(WATCHER_TYPE) == TYPE_WALL) {
                    effect.AddParticleController(new ParticleFloatUpward(effect, 0, 0.07f, 1, false));
                } else {
                    effect.setAffectedByGravity();
                    effect.setDontRequireControllers();
                    effect.addVelocity(px, py, pz);
                }
            }
        }
    } else {
        ticksToEffect--;
        if (spellStack == null) {
            if (!worldObj.isRemote) {
                this.setDead();
            }
            return;
        }
        if (dummycaster == null) {
            dummycaster = DummyEntityPlayer.fromEntityLiving(new EntityDummyCaster(worldObj));
        }
        if (ticksToEffect <= 0) {
            ticksToEffect = maxTicksToEffect_wall;
            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));
            ItemStack newStack = SpellUtils.instance.popStackStage(spellStack);
            for (Entity e : possibleTargets) {
                if (e == this || e == dummycaster || e.getEntityId() == casterEntityID)
                    continue;
                if (e instanceof EntityDragonPart && ((EntityDragonPart) e).entityDragonObj instanceof EntityLivingBase)
                    e = (EntityLivingBase) ((EntityDragonPart) e).entityDragonObj;
                AMVector3 target = new AMVector3(e);
                double dirX = Math.cos(3.141 / 180 * (rotationYaw));
                double dirZ = Math.sin(3.141 / 180 * (rotationYaw));
                AMVector3 a = new AMVector3(this.posX - dirX * radius, this.posY, this.posZ - dirZ * radius);
                AMVector3 b = new AMVector3(this.posX - dirX * -radius, this.posY, this.posZ - dirZ * -radius);
                AMVector3 closest = new AMLineSegment(a, b).closestPointOnLine(target);
                closest.y = 0;
                target.y = 0;
                double hDistance = closest.distanceTo(target);
                double vDistance = Math.abs(this.posY - e.posY);
                if (e instanceof EntityLivingBase && hDistance < 0.75f && vDistance < 2) {
                    // commented out in favor of line below so as to apply subsequent shapes as well
                    // uncomment and comment out below line to revert to direct target only, but mark wave/wall as terminus
                    // SpellHelper.instance.applyStageToEntity(spellStack, dummycaster, worldObj, e, 0, false);
                    SpellHelper.instance.applyStackStage(spellStack, dummycaster, (EntityLivingBase) e, this.posX, this.posY, this.posZ, 0, worldObj, false, false, 0);
                }
            }
        }
    }
}
Also used : AMLineSegment(am2.api.math.AMLineSegment) Entity(net.minecraft.entity.Entity) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) Colour(am2.spell.modifiers.Colour) AMVector3(am2.api.math.AMVector3) EntityDragonPart(net.minecraft.entity.boss.EntityDragonPart) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ItemStack(net.minecraft.item.ItemStack)

Example 3 with Colour

use of am2.spell.modifiers.Colour in project ArsMagica2 by Mithion.

the class EntitySpellEffect method blizzardUpdate.

private void blizzardUpdate() {
    float radius = this.dataWatcher.getWatchableObjectFloat(WATCHER_RADIUS);
    if (worldObj.isRemote) {
        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);
                }
            }
        }
        for (int i = 0; i < 20; ++i) {
            double x = this.posX - radius + (rand.nextDouble() * radius * 2);
            double z = this.posZ - radius + (rand.nextDouble() * radius * 2);
            double y = this.posY + 10;
            AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, "snowflakes", x, y, z);
            if (particle != null) {
                particle.setMaxAge(20);
                particle.setParticleScale(0.1f);
                particle.addVelocity(rand.nextDouble() * 0.2f - 0.1f, 0, rand.nextDouble() * 0.2f - 0.1f);
                particle.setAffectedByGravity();
                particle.setRGBColorI(color);
                particle.setDontRequireControllers();
                particle.noClip = false;
            }
        }
        double x = this.posX - radius + (rand.nextDouble() * radius * 2);
        double z = this.posZ - radius + (rand.nextDouble() * radius * 2);
        double y = this.posY + rand.nextDouble();
        AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, "smoke", x, y, z);
        if (particle != null) {
            particle.setParticleScale(2.0f);
            particle.setMaxAge(20);
            // particle.setRGBColorF(0.5f, 0.92f, 0.92f);
            particle.setRGBColorF(0.5098f, 0.7843f, 0.7843f);
            particle.SetParticleAlpha(0.6f);
            particle.AddParticleController(new ParticleFleePoint(particle, new AMVector3(x, y, z), 0.1f, 3f, 1, false));
        }
    // TODO: SoundHelper.instance.loopSound(worldObj, (float)posX, (float)posY, (float)posZ, "arsmagica2:spell.loop.air", 1.0f);
    } else {
        List<Entity> possibleTargets = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(posX - radius, posY - 1, posZ - radius, posX + radius, posY + 3, posZ + radius));
        for (Entity e : possibleTargets) {
            if (e != dummycaster) {
                if (e instanceof EntityDragonPart && ((EntityDragonPart) e).entityDragonObj instanceof EntityLivingBase)
                    e = (EntityLivingBase) ((EntityDragonPart) e).entityDragonObj;
                if (e instanceof EntityLivingBase)
                    ((EntityLivingBase) e).addPotionEffect(new BuffEffectFrostSlowed(80, 3));
                float damage = 1 * this.dataWatcher.getWatchableObjectFloat(WATCHER_DAMAGEBONUS);
                double lastVelX = e.motionX;
                double lastVelY = e.motionY;
                double lastVelZ = e.motionZ;
                if (SpellHelper.instance.attackTargetSpecial(null, e, DamageSources.causeEntityFrostDamage(dummycaster), damage) && !(e instanceof EntityPlayer))
                    e.hurtResistantTime = 15;
                e.addVelocity(-(e.motionX - lastVelX), -(e.motionY - lastVelY), -(e.motionZ - lastVelZ));
            }
        }
        if (rand.nextInt(10) < 2) {
            int pX = (int) (posX - radius + rand.nextInt((int) Math.ceil(radius) * 2));
            int pY = (int) posY + rand.nextInt(2);
            int pZ = (int) (posZ - radius + rand.nextInt((int) Math.ceil(radius) * 2));
            if (worldObj.isAirBlock(pX, pY, pZ) && !worldObj.isAirBlock(pX, pY - 1, pZ) && worldObj.getBlock(pX, pY, pZ).isOpaqueCube())
                worldObj.setBlock(pX, pY, pZ, Blocks.snow);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) Colour(am2.spell.modifiers.Colour) AMVector3(am2.api.math.AMVector3) EntityDragonPart(net.minecraft.entity.boss.EntityDragonPart) BuffEffectFrostSlowed(am2.buffs.BuffEffectFrostSlowed) EntityLivingBase(net.minecraft.entity.EntityLivingBase) DummyEntityPlayer(am2.utility.DummyEntityPlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 4 with Colour

use of am2.spell.modifiers.Colour in project ArsMagica2 by Mithion.

the class SpellHelper method applyStageToEntity.

public SpellCastResult applyStageToEntity(ItemStack stack, EntityLivingBase caster, World world, Entity target, int stage, boolean shiftAffinityAndXP) {
    ISpellShape stageShape = SpellUtils.instance.getShapeForStage(stack, 0);
    if (stageShape == null)
        return SpellCastResult.MALFORMED_SPELL_STACK;
    if ((!AMCore.config.getAllowCreativeTargets()) && target instanceof EntityPlayerMP && ((EntityPlayerMP) target).capabilities.isCreativeMode) {
        return SpellCastResult.EFFECT_FAILED;
    }
    ISpellComponent[] components = SpellUtils.instance.getComponentsForStage(stack, 0);
    boolean appliedOneComponent = false;
    for (ISpellComponent component : components) {
        if (SkillTreeManager.instance.isSkillDisabled(component))
            continue;
        if (component.applyEffectEntity(stack, world, caster, target)) {
            appliedOneComponent = true;
            if (world.isRemote) {
                int color = -1;
                if (SpellUtils.instance.modifierIsPresent(SpellModifiers.COLOR, stack, 0)) {
                    ISpellModifier[] mods = SpellUtils.instance.getModifiersForStage(stack, 0);
                    int ordinalCount = 0;
                    for (ISpellModifier mod : mods) {
                        if (mod instanceof Colour) {
                            byte[] meta = SpellUtils.instance.getModifierMetadataFromStack(stack, mod, 0, ordinalCount++);
                            color = (int) mod.getModifier(SpellModifiers.COLOR, null, null, null, meta);
                        }
                    }
                }
                component.spawnParticles(world, target.posX, target.posY + target.getEyeHeight(), target.posZ, caster, target, world.rand, color);
            }
            if (shiftAffinityAndXP)
                SpellUtils.instance.doAffinityShift(caster, component, stageShape);
        }
    }
    if (appliedOneComponent)
        return SpellCastResult.SUCCESS;
    else
        return SpellCastResult.EFFECT_FAILED;
}
Also used : ISpellComponent(am2.api.spell.component.interfaces.ISpellComponent) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ISpellShape(am2.api.spell.component.interfaces.ISpellShape) Colour(am2.spell.modifiers.Colour)

Example 5 with Colour

use of am2.spell.modifiers.Colour in project ArsMagica2 by Mithion.

the class SpellHelper method applyStageToGround.

public SpellCastResult applyStageToGround(ItemStack stack, EntityLivingBase caster, World world, int blockX, int blockY, int blockZ, int blockFace, double impactX, double impactY, double impactZ, int stage, boolean consumeMBR) {
    ISpellShape stageShape = SpellUtils.instance.getShapeForStage(stack, 0);
    if (stageShape == null || stageShape == SkillManager.instance.missingShape) {
        return SpellCastResult.MALFORMED_SPELL_STACK;
    }
    ISpellComponent[] components = SpellUtils.instance.getComponentsForStage(stack, 0);
    for (ISpellComponent component : components) {
        if (SkillTreeManager.instance.isSkillDisabled(component))
            continue;
        // special logic for spell sealed doors
        if (BlocksCommonProxy.spellSealedDoor.applyComponentToDoor(world, component, blockX, blockY, blockZ))
            continue;
        if (component.applyEffectBlock(stack, world, blockX, blockY, blockZ, blockFace, impactX, impactY, impactZ, caster)) {
            if (world.isRemote) {
                int color = -1;
                if (SpellUtils.instance.modifierIsPresent(SpellModifiers.COLOR, stack, 0)) {
                    ISpellModifier[] mods = SpellUtils.instance.getModifiersForStage(stack, 0);
                    int ordinalCount = 0;
                    for (ISpellModifier mod : mods) {
                        if (mod instanceof Colour) {
                            byte[] meta = SpellUtils.instance.getModifierMetadataFromStack(stack, mod, 0, ordinalCount++);
                            color = (int) mod.getModifier(SpellModifiers.COLOR, null, null, null, meta);
                        }
                    }
                }
                component.spawnParticles(world, blockX, blockY, blockZ, caster, caster, world.rand, color);
            }
            if (consumeMBR)
                SpellUtils.instance.doAffinityShift(caster, component, stageShape);
        }
    }
    return SpellCastResult.SUCCESS;
}
Also used : ISpellComponent(am2.api.spell.component.interfaces.ISpellComponent) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) ISpellShape(am2.api.spell.component.interfaces.ISpellShape) Colour(am2.spell.modifiers.Colour)

Aggregations

ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)13 Colour (am2.spell.modifiers.Colour)13 Entity (net.minecraft.entity.Entity)6 EntityLivingBase (net.minecraft.entity.EntityLivingBase)5 EntityDragonPart (net.minecraft.entity.boss.EntityDragonPart)5 ItemStack (net.minecraft.item.ItemStack)3 AMVector3 (am2.api.math.AMVector3)2 ISpellComponent (am2.api.spell.component.interfaces.ISpellComponent)2 ISpellShape (am2.api.spell.component.interfaces.ISpellShape)2 Affinity (am2.api.spell.enums.Affinity)2 AMParticle (am2.particles.AMParticle)2 DummyEntityPlayer (am2.utility.DummyEntityPlayer)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 AMLineSegment (am2.api.math.AMLineSegment)1 AMVector2 (am2.api.math.AMVector2)1 SpellCastResult (am2.api.spell.enums.SpellCastResult)1 BuffEffectFrostSlowed (am2.buffs.BuffEffectFrostSlowed)1 AMBeam (am2.particles.AMBeam)1 ParticleChangeSize (am2.particles.ParticleChangeSize)1 ParticleColorShift (am2.particles.ParticleColorShift)1