Search in sources :

Example 31 with AMVector3

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

the class RandomTeleport method getRandomTeleportLocation.

private AMVector3 getRandomTeleportLocation(World world, ItemStack stack, EntityLivingBase caster, Entity target) {
    AMVector3 origin = new AMVector3(target);
    float maxDist = 9;
    maxDist = (float) SpellUtils.instance.getModifiedDouble_Mul(maxDist, stack, caster, target, world, 0, SpellModifiers.RANGE);
    origin.add(new AMVector3((world.rand.nextDouble() - 0.5) * maxDist, (world.rand.nextDouble() - 0.5) * maxDist, (world.rand.nextDouble() - 0.5) * maxDist));
    return origin;
}
Also used : AMVector3(am2.api.math.AMVector3)

Example 32 with AMVector3

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

the class TileEntityBlackAurem method updateEntity.

@Override
public void updateEntity() {
    if (worldObj.isRemote) {
        this.rotation += this.rotationIncrement;
    } else {
        surroundingCheckTicks++;
    }
    if (worldObj.isRemote || ticksSinceLastEntityScan++ > 25) {
        updateNearbyEntities();
        ticksSinceLastEntityScan = 0;
    }
    Iterator<EntityLivingBase> it = cachedEntities.iterator();
    while (it.hasNext()) {
        EntityLivingBase ent = it.next();
        if (ent.isDead) {
            it.remove();
            continue;
        }
        MovingObjectPosition mop = this.worldObj.rayTraceBlocks(Vec3.createVectorHelper(xCoord + 0.5, yCoord + 1.5, zCoord + 0.5), Vec3.createVectorHelper(ent.posX, ent.posY + ent.getEyeHeight(), ent.posZ), false);
        if (EntityUtilities.isSummon(ent) || mop != null) {
            continue;
        }
        ent.motionY = 0;
        ent.motionX = 0;
        ent.motionZ = 0;
        double deltaX = this.xCoord + 0.5f - ent.posX;
        double deltaZ = this.zCoord + 0.5f - ent.posZ;
        double deltaY = this.yCoord - ent.posY;
        double angle = Math.atan2(deltaZ, deltaX);
        double offsetX = Math.cos(angle) * 0.1;
        double offsetZ = Math.sin(angle) * 0.1;
        double offsetY = 0.05f;
        double distanceHorizontal = deltaX * deltaX + deltaZ * deltaZ;
        double distanceVertical = this.yCoord - ent.posY;
        boolean spawnedParticles = false;
        if (distanceHorizontal < 1.3) {
            if (distanceVertical < -1.5) {
                if (worldObj.isRemote && worldObj.rand.nextInt(10) < 3) {
                    AMCore.proxy.particleManager.BoltFromPointToPoint(worldObj, xCoord + 0.5, yCoord + 1.3, zCoord + 0.5, ent.posX, ent.posY, ent.posZ, 4, 0x000000);
                }
            }
            if (distanceVertical < -2) {
                offsetY = 0;
                if (!worldObj.isRemote) {
                    if (ent.attackEntityFrom(DamageSources.darkNexus, 4)) {
                        if (ent.getHealth() <= 0) {
                            ent.setDead();
                            float power = ((int) Math.ceil((ent.getMaxHealth() * (ent.ticksExisted / 20)) % 5000)) * this.powerMultiplier;
                            PowerNodeRegistry.For(this.worldObj).insertPower(this, PowerTypes.DARK, power);
                        }
                    }
                }
            }
        }
        if (worldObj.isRemote) {
            if (!arcs.containsKey(ent)) {
                AMLineArc arc = (AMLineArc) AMCore.proxy.particleManager.spawn(worldObj, "textures/blocks/oreblocksunstone.png", xCoord + 0.5, yCoord + 1.3, zCoord + 0.5, ent);
                if (arc != null) {
                    arc.setExtendToTarget();
                    arc.setRBGColorF(1, 1, 1);
                }
                arcs.put(ent, arc);
            }
            Iterator arcIterator = arcs.keySet().iterator();
            ArrayList<Entity> toRemove = new ArrayList<Entity>();
            while (arcIterator.hasNext()) {
                Entity arcEnt = (Entity) arcIterator.next();
                AMLineArc arc = (AMLineArc) arcs.get(arcEnt);
                if (arcEnt == null || arcEnt.isDead || arc == null || arc.isDead || new AMVector3(ent).distanceSqTo(new AMVector3(xCoord, yCoord, zCoord)) > 100)
                    toRemove.add(arcEnt);
            }
            for (Entity e : toRemove) {
                arcs.remove(e);
            }
        }
        if (!worldObj.isRemote)
            ent.moveEntity(offsetX, offsetY, offsetZ);
    }
    if (surroundingCheckTicks % 100 == 0) {
        checkNearbyBlockState();
        surroundingCheckTicks = 1;
        if (!worldObj.isRemote && PowerNodeRegistry.For(this.worldObj).checkPower(this, this.capacity * 0.1f)) {
            List<EntityPlayer> nearbyPlayers = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(this.xCoord - 2, this.yCoord, this.zCoord - 2, this.xCoord + 2, this.yCoord + 3, this.zCoord + 2));
            for (EntityPlayer p : nearbyPlayers) {
                if (p.isPotionActive(BuffList.manaRegen.id))
                    continue;
                p.addPotionEffect(new BuffEffectManaRegen(600, 3));
            }
        }
    // TODO:
    /*if (rand.nextDouble() < (this.getCharge() / this.getCapacity()) * 0.01){
					int maxSev = (int)Math.ceil((this.getCharge() / this.getCapacity()) * 2) + rand.nextInt(2);
					IllEffectsManager.instance.ApplyRandomBadThing(this, IllEffectSeverity.values()[maxSev], BadThingTypes.DARKNEXUS);
				}*/
    }
    super.callSuperUpdate();
}
Also used : Entity(net.minecraft.entity.Entity) ArrayList(java.util.ArrayList) BuffEffectManaRegen(am2.buffs.BuffEffectManaRegen) AMLineArc(am2.particles.AMLineArc) AMVector3(am2.api.math.AMVector3) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Iterator(java.util.Iterator) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 33 with AMVector3

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

the class SpellBase method getMovingObjectPosition.

@Override
public MovingObjectPosition getMovingObjectPosition(EntityLivingBase caster, World world, double range, boolean includeEntities, boolean targetWater) {
    MovingObjectPosition entityPos = null;
    if (includeEntities) {
        Entity pointedEntity = MathUtilities.getPointedEntity(world, caster, range, 1.0f);
        if (pointedEntity != null) {
            entityPos = new MovingObjectPosition(pointedEntity);
        }
    }
    float factor = 1.0F;
    float interpPitch = caster.prevRotationPitch + (caster.rotationPitch - caster.prevRotationPitch) * factor;
    float interpYaw = caster.prevRotationYaw + (caster.rotationYaw - caster.prevRotationYaw) * factor;
    double interpPosX = caster.prevPosX + (caster.posX - caster.prevPosX) * factor;
    double interpPosY = caster.prevPosY + (caster.posY - caster.prevPosY) * factor + caster.getEyeHeight();
    double interpPosZ = caster.prevPosZ + (caster.posZ - caster.prevPosZ) * factor;
    Vec3 vec3 = Vec3.createVectorHelper(interpPosX, interpPosY, interpPosZ);
    float offsetYawCos = MathHelper.cos(-interpYaw * 0.017453292F - (float) Math.PI);
    float offsetYawSin = MathHelper.sin(-interpYaw * 0.017453292F - (float) Math.PI);
    float offsetPitchCos = -MathHelper.cos(-interpPitch * 0.017453292F);
    float offsetPitchSin = MathHelper.sin(-interpPitch * 0.017453292F);
    float finalXOffset = offsetYawSin * offsetPitchCos;
    float finalZOffset = offsetYawCos * offsetPitchCos;
    Vec3 targetVector = vec3.addVector(finalXOffset * range, offsetPitchSin * range, finalZOffset * range);
    MovingObjectPosition mop = world.rayTraceBlocks(vec3, targetVector, targetWater);
    if (entityPos != null && mop != null) {
        if (new AMVector3(mop.hitVec).distanceSqTo(new AMVector3(caster)) < new AMVector3(entityPos.hitVec).distanceSqTo(new AMVector3(caster))) {
            return mop;
        } else {
            return entityPos;
        }
    }
    return entityPos != null ? entityPos : mop;
}
Also used : Entity(net.minecraft.entity.Entity) AMVector3(am2.api.math.AMVector3)

Example 34 with AMVector3

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

the class ItemRune method spawnBroom.

public void spawnBroom(ItemStack stack, World world, EntityPlayer player) {
    if (!world.isRemote) {
        MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(world, player, true);
        if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK) {
            TileEntity te = world.getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
            if (te instanceof IInventory) {
                EntityBroom broom = new EntityBroom(world);
                broom.setPosition(player.posX, player.posY, player.posZ);
                broom.setChestLocation(new AMVector3(mop.blockX, mop.blockY, mop.blockZ));
                world.spawnEntityInWorld(broom);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3)

Example 35 with AMVector3

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

the class ItemMagicBroom method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(world, player, true);
        if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK) {
            TileEntity te = world.getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
            if (te instanceof IInventory) {
                EntityBroom broom = new EntityBroom(world);
                broom.setPosition(player.posX, player.posY, player.posZ);
                broom.setChestLocation(new AMVector3(mop.blockX, mop.blockY, mop.blockZ));
                world.spawnEntityInWorld(broom);
                stack.stackSize--;
                if (stack.stackSize == 0) {
                    player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) EntityBroom(am2.entities.EntityBroom)

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