Search in sources :

Example 1 with AMLineSegment

use of am2.api.math.AMLineSegment 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)

Aggregations

AMLineSegment (am2.api.math.AMLineSegment)1 AMVector3 (am2.api.math.AMVector3)1 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)1 Colour (am2.spell.modifiers.Colour)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityDragonPart (net.minecraft.entity.boss.EntityDragonPart)1 ItemStack (net.minecraft.item.ItemStack)1