Search in sources :

Example 6 with AMVector3

use of am2.api.math.AMVector3 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 7 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class EntitySpellProjectile method findHomingTarget.

private void findHomingTarget() {
    List<EntityLivingBase> entities = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(this.posX - 15, this.posY - 15, this.posZ - 15, this.posX + 15, this.posY + 15, this.posZ + 15));
    EntityLivingBase closest = null;
    double curShortestDistance = 900;
    AMVector3 me = new AMVector3(this);
    for (EntityLivingBase e : entities) {
        if (e == this.getShootingEntity())
            continue;
        double distance = new AMVector3(e).distanceSqTo(me);
        if (distance < curShortestDistance) {
            curShortestDistance = distance;
            closest = e;
        }
    }
    if (closest != null) {
        setHomingTarget(closest);
    }
}
Also used : AMVector3(am2.api.math.AMVector3) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 8 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class EntityFlicker method updateEntityActionState.

@Override
protected void updateEntityActionState() {
    super.updateEntityActionState();
    AMVector3 me = new AMVector3(this);
    boolean needsNewPath = targetPosition == null || this.ticksExisted % DIRECTION_CHANGE_TIME == 0;
    if (needsNewPath && worldObj.rand.nextDouble() < 0.1f)
        pickNewTargetPosition();
    if (// this represents the pause state in between picking new waypoints
    targetPosition == null)
        return;
    if (me.distanceSqTo(targetPosition) < 1f) {
        targetPosition = null;
        return;
    }
    this.rotationYaw = AMVector3.anglePreNorm(me, targetPosition);
    normalizedMovementVector = me.copy().sub(targetPosition).normalize();
    if (normalizedMovementVector.y > 0)
        rotatePitchTowards(-70 * normalizedMovementVector.y, 30);
    else
        rotatePitchTowards(0, 30);
    float speed = 0.2f;
    this.addVelocity(-normalizedMovementVector.x * speed, -normalizedMovementVector.y * speed, -normalizedMovementVector.z * speed);
}
Also used : AMVector3(am2.api.math.AMVector3)

Example 9 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class EntityAIPickup method checkStuck.

private boolean checkStuck() {
    AMVector3 loc = new AMVector3(host);
    if (lastLocation == null) {
        lastLocation = loc;
        return false;
    }
    if (lastLocation.distanceSqTo(loc) < 1) {
        stuckTicks++;
        if (stuckTicks > 40) {
            return true;
        }
    }
    lastLocation = loc;
    return false;
}
Also used : AMVector3(am2.api.math.AMVector3)

Example 10 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class PowerNodePathfinder method generateSuccessors.

@Override
protected List<AMVector3> generateSuccessors(AMVector3 node) {
    IPowerNode powerNode = getPowerNode(world, node);
    if (powerNode == null)
        return new ArrayList<AMVector3>();
    IPowerNode[] candidates = PowerNodeRegistry.For(world).getAllNearbyNodes(world, node, powerType);
    ArrayList<AMVector3> prunedCandidates = new ArrayList<AMVector3>();
    for (IPowerNode candidate : candidates) {
        if (verifyCandidate(candidate)) {
            prunedCandidates.add(new AMVector3((TileEntity) candidate));
        }
    }
    return prunedCandidates;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) ArrayList(java.util.ArrayList) IPowerNode(am2.api.power.IPowerNode)

Aggregations

AMVector3 (am2.api.math.AMVector3)113 TileEntity (net.minecraft.tileentity.TileEntity)21 EntityPlayer (net.minecraft.entity.player.EntityPlayer)16 EntityLivingBase (net.minecraft.entity.EntityLivingBase)15 ArrayList (java.util.ArrayList)11 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)11 IPowerNode (am2.api.power.IPowerNode)10 Block (net.minecraft.block.Block)9 Entity (net.minecraft.entity.Entity)9 ItemStack (net.minecraft.item.ItemStack)9 NBTTagList (net.minecraft.nbt.NBTTagList)9 IInventory (net.minecraft.inventory.IInventory)8 PowerTypes (am2.api.power.PowerTypes)6 AMParticle (am2.particles.AMParticle)5 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)5 TileEntityCrystalMarker (am2.blocks.tileentities.TileEntityCrystalMarker)4 EntityDragonPart (net.minecraft.entity.boss.EntityDragonPart)4 TileEntityFlickerHabitat (am2.blocks.tileentities.TileEntityFlickerHabitat)3 AMDataWriter (am2.network.AMDataWriter)3 ParticleFloatUpward (am2.particles.ParticleFloatUpward)3