Search in sources :

Example 1 with AMVector3

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

the class EntityUtilities method setGuardSpawnLocation.

public static void setGuardSpawnLocation(EntityCreature entity, double x, double y, double z) {
    float speed = entity.getAIMoveSpeed();
    if (speed <= 0)
        speed = 1.0f;
    entity.tasks.addTask(1, new EntityAIGuardSpawnLocation(entity, speed, 3, 16, new AMVector3(x, y, z)));
}
Also used : AMVector3(am2.api.math.AMVector3) EntityAIGuardSpawnLocation(am2.entities.ai.EntityAIGuardSpawnLocation)

Example 2 with AMVector3

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

the class MathUtilities method calcNewVector.

private static AMVector3 calcNewVector(float scaler, AMVector3 base) {
    AMVector3 retValue = new AMVector3(base.x, base.y, base.z);
    retValue.scale(scaler);
    return retValue;
}
Also used : AMVector3(am2.api.math.AMVector3)

Example 3 with AMVector3

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

the class MathUtilities method GetHorizontalBlocksInFrontOfCharacter.

public static AMVector3[] GetHorizontalBlocksInFrontOfCharacter(EntityLivingBase entity, int numBlocks, int x, int y, int z) {
    float speed = 0.1F;
    float factor = (float) (Math.PI / 180.0f);
    float sinYawRadians = MathHelper.sin(entity.rotationYaw * factor);
    float cosYawRadians = MathHelper.cos(entity.rotationYaw * factor);
    float cosPitchRadians = MathHelper.cos(entity.rotationPitch * factor);
    double motionZ = cosYawRadians * speed;
    double motionX = -sinYawRadians * speed;
    double curX = x;
    double curY = y;
    double curZ = z;
    float minimum = 0.01f;
    if (Math.abs(motionX) < minimum) {
        motionX = 0;
    }
    if (Math.abs(motionZ) < minimum) {
        motionZ = 0;
    }
    int lastX = x;
    int lastY = y;
    int lastZ = z;
    AMVector3[] list = new AMVector3[numBlocks];
    list[0] = new AMVector3(x, y, z);
    int count = 1;
    while (count < numBlocks) {
        curX += motionX;
        curZ += motionZ;
        // check for deltas
        if ((int) Math.round(curX) != lastX || (int) Math.round(curY) != lastY || (int) Math.round(curZ) != lastZ) {
            lastX = (int) Math.round(curX);
            lastY = (int) Math.round(curY);
            lastZ = (int) Math.round(curZ);
            list[count++] = new AMVector3(lastX, lastY, lastZ);
        }
    }
    return list;
}
Also used : AMVector3(am2.api.math.AMVector3)

Example 4 with AMVector3

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

the class EntityAIChestDeposit method updateTask.

@Override
public void updateTask() {
    AMVector3 iLoc = host.getChestLocation();
    if (iLoc == null)
        return;
    TileEntity te = host.worldObj.getTileEntity((int) iLoc.x, (int) iLoc.y, (int) iLoc.z);
    if (te == null || !(te instanceof IInventory))
        return;
    if (new AMVector3(host).distanceSqTo(iLoc) > 256) {
        host.setPosition(iLoc.x, iLoc.y, iLoc.z);
        return;
    }
    if (new AMVector3(host).distanceSqTo(iLoc) > 9) {
        host.getNavigator().tryMoveToXYZ(iLoc.x + 0.5, iLoc.y, iLoc.z + 0.5, 0.5f);
    } else {
        IInventory inventory = (IInventory) te;
        if (!isDepositing)
            inventory.openInventory();
        isDepositing = true;
        depositCounter++;
        if (depositCounter > 10) {
            ItemStack mergeStack = InventoryUtilities.getFirstStackInInventory(host.getBroomInventory()).copy();
            int originalSize = mergeStack.stackSize;
            if (!InventoryUtilities.mergeIntoInventory(inventory, mergeStack, 1)) {
                if (te instanceof TileEntityChest) {
                    TileEntityChest chest = (TileEntityChest) te;
                    TileEntityChest adjacent = null;
                    if (chest.adjacentChestXNeg != null)
                        adjacent = chest.adjacentChestXNeg;
                    else if (chest.adjacentChestXPos != null)
                        adjacent = chest.adjacentChestXPos;
                    else if (chest.adjacentChestZPos != null)
                        adjacent = chest.adjacentChestZPos;
                    else if (chest.adjacentChestZNeg != null)
                        adjacent = chest.adjacentChestZNeg;
                    if (adjacent != null) {
                        InventoryUtilities.mergeIntoInventory(adjacent, mergeStack, 1);
                    }
                }
            }
            InventoryUtilities.deductFromInventory(host.getBroomInventory(), mergeStack, originalSize - mergeStack.stackSize);
        }
        if (depositCounter > 10 && (InventoryUtilities.isInventoryEmpty(host.getBroomInventory()) || !InventoryUtilities.canMergeHappen(host.getBroomInventory(), inventory))) {
            inventory.closeInventory();
            resetTask();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ItemStack(net.minecraft.item.ItemStack)

Example 5 with AMVector3

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

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