Search in sources :

Example 96 with AMVector3

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

the class Recall method handleRitualReagents.

private boolean handleRitualReagents(ItemStack[] ritualRunes, World world, int x, int y, int z, EntityLivingBase caster, Entity target) {
    boolean hasVinteumDust = false;
    for (ItemStack stack : ritualRunes) {
        if (stack.getItem() == ItemsCommonProxy.itemOre && stack.getItemDamage() == ItemsCommonProxy.itemOre.META_VINTEUMDUST) {
            hasVinteumDust = true;
            break;
        }
    }
    if (!hasVinteumDust && ritualRunes.length == 3) {
        long key = KeystoneUtilities.instance.getKeyFromRunes(ritualRunes);
        AMVector3 vector = AMCore.proxy.blocks.getNextKeystonePortalLocation(world, x, y, z, false, key);
        if (vector == null || vector.equals(new AMVector3(x, y, z))) {
            if (caster instanceof EntityPlayer && !world.isRemote)
                ((EntityPlayer) caster).addChatMessage(new ChatComponentText(StatCollector.translateToLocal("am2.tooltip.noMatchingGate")));
            return false;
        } else {
            RitualShapeHelper.instance.consumeRitualReagents(this, world, x, y, z);
            RitualShapeHelper.instance.consumeRitualShape(this, world, x, y, z);
            ((EntityLivingBase) target).setPositionAndUpdate(vector.x, vector.y - target.height, vector.z);
            return true;
        }
    } else if (hasVinteumDust) {
        ArrayList<ItemStack> copy = new ArrayList<ItemStack>();
        for (ItemStack stack : ritualRunes) {
            if (stack.getItem() == ItemsCommonProxy.rune && stack.getItemDamage() <= 16) {
                copy.add(stack);
            }
        }
        ItemStack[] newRunes = copy.toArray(new ItemStack[copy.size()]);
        long key = KeystoneUtilities.instance.getKeyFromRunes(newRunes);
        EntityPlayer player = EntityUtilities.getPlayerForCombo(world, (int) key);
        if (player == null) {
            if (caster instanceof EntityPlayer && !world.isRemote)
                ((EntityPlayer) caster).addChatMessage(new ChatComponentText("am2.tooltip.noMatchingPlayer"));
            return false;
        } else if (player == caster) {
            if (caster instanceof EntityPlayer && !world.isRemote)
                ((EntityPlayer) caster).addChatMessage(new ChatComponentText("am2.tooltip.cantSummonSelf"));
            return false;
        } else {
            RitualShapeHelper.instance.consumeRitualReagents(this, world, x, y, z);
            if (target.worldObj.provider.dimensionId != caster.worldObj.provider.dimensionId) {
                DimensionUtilities.doDimensionTransfer(player, caster.worldObj.provider.dimensionId);
            }
            ((EntityLivingBase) target).setPositionAndUpdate(x, y, z);
            return true;
        }
    }
    return false;
}
Also used : AMVector3(am2.api.math.AMVector3) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 97 with AMVector3

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

the class TileEntitySlipstreamGenerator method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    if (updateTicks++ > 10) {
        refreshPlayerList();
        updateTicks = 0;
        if (worldObj.isRemote && levitatingEntities.size() > 0)
            AMNetHandler.INSTANCE.sendPowerRequestToServer(new AMVector3(this));
    }
    Iterator<EntityPlayer> it = levitatingEntities.iterator();
    while (it.hasNext()) {
        EntityPlayer player = it.next();
        if (!playerIsValid(player)) {
            it.remove();
            continue;
        }
        if (PowerNodeRegistry.For(this.worldObj).getHighestPower(this) >= 0.25f) {
            player.motionY *= 0.5999999;
            if (Math.abs(player.motionY) < 0.2) {
                player.addVelocity(0, -player.motionY, 0);
                player.fallDistance = 0f;
            } else {
                player.fallDistance--;
            }
            if (!player.isSneaking()) {
                float pitch = player.rotationPitch;
                float factor = (pitch > 0 ? (pitch - 10) : (pitch + 10)) / -180.0f;
                if (Math.abs(pitch) > 10f) {
                    player.moveEntity(0, factor, 0);
                }
            }
            if (worldObj.isRemote)
                spawnParticles(player);
            PowerNodeRegistry.For(this.worldObj).consumePower(this, PowerNodeRegistry.For(this.worldObj).getHighestPowerType(this), 0.25f);
        }
    }
}
Also used : AMVector3(am2.api.math.AMVector3) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 98 with AMVector3

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

the class TileEntityKeystoneRecepticle method doTeleport.

private void doTeleport(Entity entity) {
    deactivate();
    AMVector3 newLocation = AMCore.instance.proxy.blocks.getNextKeystonePortalLocation(this.worldObj, xCoord, yCoord, zCoord, false, this.key);
    AMVector3 myLocation = new AMVector3(xCoord, yCoord, zCoord);
    double distance = myLocation.distanceTo(newLocation);
    float essenceCost = (float) (Math.pow(distance, 2) * 0.00175f);
    int meta = worldObj.getBlockMetadata((int) newLocation.x, (int) newLocation.y, (int) newLocation.z);
    if (AMCore.config.getHazardousGateways()) {
        //uh-oh!  Not enough power!  The teleporter will still send you though, but I wonder where...
        float charge = PowerNodeRegistry.For(this.worldObj).getHighestPower(this);
        if (charge < essenceCost) {
            essenceCost = charge;
            //get the distance that our charge *will* take us towards the next point
            double distanceWeCanGo = MathHelper.sqrt_double(charge / 0.00175);
            //get the angle between the 2 vectors
            double deltaZ = newLocation.z - myLocation.z;
            double deltaX = newLocation.x - myLocation.x;
            double angleH = Math.atan2(deltaZ, deltaX);
            //interpolate the distance at that angle - this is the new position
            double newX = myLocation.x + (Math.cos(angleH) * distanceWeCanGo);
            double newZ = myLocation.z + (Math.sin(angleH) * distanceWeCanGo);
            double newY = myLocation.y;
            while (worldObj.isAirBlock((int) newX, (int) newY, (int) newZ)) {
                newY++;
            }
            newLocation = new AMVector3(newX, newY, newZ);
        }
    } else {
        this.worldObj.playSoundEffect(newLocation.x, newLocation.y, newLocation.z, "mob.endermen.portal", 1.0F, 1.0F);
        return;
    }
    float newRotation = 0;
    switch(meta) {
        case 0:
            newRotation = 270;
            break;
        case 1:
            newRotation = 180;
            break;
        case 2:
            newRotation = 90;
            break;
        case 3:
            newRotation = 0;
            break;
    }
    entity.setPositionAndRotation(newLocation.x + 0.5, newLocation.y - entity.height, newLocation.z + 0.5, newRotation, entity.rotationPitch);
    PowerNodeRegistry.For(this.worldObj).consumePower(this, PowerNodeRegistry.For(this.worldObj).getHighestPowerType(this), essenceCost);
    this.worldObj.playSoundEffect(myLocation.x, myLocation.y, myLocation.z, "mob.endermen.portal", 1.0F, 1.0F);
    this.worldObj.playSoundEffect(newLocation.x, newLocation.y, newLocation.z, "mob.endermen.portal", 1.0F, 1.0F);
}
Also used : AMVector3(am2.api.math.AMVector3)

Example 99 with AMVector3

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

the class TileEntityKeystoneRecepticle method setActive.

public void setActive(long key) {
    this.isActive = true;
    this.key = key;
    int myMeta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
    if (PowerNodeRegistry.For(worldObj).getHighestPowerType(this) == PowerTypes.DARK) {
        myMeta |= 8;
    } else if (PowerNodeRegistry.For(worldObj).getHighestPowerType(this) == PowerTypes.LIGHT) {
        myMeta |= 4;
    }
    if (!this.worldObj.isRemote) {
        for (Object player : this.worldObj.playerEntities) {
            if (player instanceof EntityPlayerMP && new AMVector3((EntityPlayerMP) player).distanceSqTo(new AMVector3(this)) <= 4096) {
                ((EntityPlayerMP) player).playerNetServerHandler.sendPacket(getDescriptionPacket());
            }
        }
    } else {
        worldObj.playSound(xCoord, yCoord, zCoord, "arsmagica2:misc.gateway.open", 1.0f, 1.0f, true);
    }
}
Also used : AMVector3(am2.api.math.AMVector3) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 100 with AMVector3

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

the class TileEntityOtherworldAura method spawnHelper.

private void spawnHelper() {
    if (helper != null || worldObj.isRemote)
        return;
    this.helper = new EntityShadowHelper(worldObj);
    this.helper.setPosition(xCoord, yCoord + 1, zCoord);
    if (this.watchTarget != null)
        this.helper.setAltarTarget(watchTarget);
    this.worldObj.spawnEntityInWorld(helper);
    if (this.watchTarget != null) {
        this.helper.setDropoffLocation(new AMVector3(watchTarget.xCoord, watchTarget.yCoord - 2, watchTarget.zCoord));
        if (placedByUsername != null && !placedByUsername.isEmpty())
            this.helper.setMimicUser(placedByUsername);
    }
}
Also used : AMVector3(am2.api.math.AMVector3) EntityShadowHelper(am2.entities.EntityShadowHelper)

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