Search in sources :

Example 56 with AMVector3

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

the class MeteorSpawnHelper method spawnMeteor.

public void spawnMeteor() {
    ticksSinceLastMeteor = 48000;
    if (MinecraftServer.getServer().worldServers.length < 1)
        return;
    WorldServer ws = null;
    for (WorldServer world : MinecraftServer.getServer().worldServers) {
        if (world.provider.dimensionId == 0) {
            ws = world;
            break;
        }
    }
    if (ws == null)
        return;
    long time = ws.getWorldTime() % 24000;
    if (time > 14500 && time < 21500) {
        //night time range (just past dusk and just before dawn)
        if (ws.playerEntities.size() < 1)
            return;
        int playerID = rand.nextInt(ws.playerEntities.size());
        EntityPlayer player = (EntityPlayer) ws.playerEntities.get(playerID);
        if (ExtendedProperties.For(player).getMagicLevel() < AMCore.config.getMeteorMinSpawnLevel())
            return;
        AMVector3 spawnCoord = new AMVector3(player);
        boolean found = false;
        int meteorOffsetRadius = 64;
        AMVector3 attractorCoord = FlickerOperatorMoonstoneAttractor.getMeteorAttractor(spawnCoord);
        if (attractorCoord != null) {
            spawnCoord = attractorCoord;
            meteorOffsetRadius = 4;
        }
        for (int i = 0; i < 10; ++i) {
            AMVector3 offsetCoord = spawnCoord.copy().add(new AMVector3(rand.nextInt(meteorOffsetRadius) - (meteorOffsetRadius / 2), 0, rand.nextInt(meteorOffsetRadius) - (meteorOffsetRadius / 2)));
            offsetCoord.y = correctYCoord(ws, (int) offsetCoord.x, (int) offsetCoord.y, (int) offsetCoord.z);
            if (offsetCoord.y < 0)
                return;
            if (topBlockIsBiomeGeneric(ws, (int) offsetCoord.x, (int) offsetCoord.y, (int) offsetCoord.z)) {
                spawnCoord = offsetCoord;
                found = true;
                break;
            }
        }
        if (!found)
            return;
        EntityThrownRock meteor = new EntityThrownRock(ws);
        meteor.setPosition(spawnCoord.x + rand.nextInt(meteorOffsetRadius) - (meteorOffsetRadius / 2), ws.getActualHeight(), spawnCoord.z + rand.nextInt(meteorOffsetRadius) - (meteorOffsetRadius / 2));
        meteor.setMoonstoneMeteor();
        meteor.setMoonstoneMeteorTarget(spawnCoord);
        ws.spawnEntityInWorld(meteor);
    }
}
Also used : AMVector3(am2.api.math.AMVector3) EntityThrownRock(am2.entities.EntityThrownRock) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer)

Example 57 with AMVector3

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

the class AMClientEventHandler method renderPowerFloatingText.

private void renderPowerFloatingText(DrawBlockHighlightEvent event, TileEntity te) {
    PowerNodeEntry data = AMCore.proxy.getTrackedData();
    Block block = event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ);
    float yOff = 0.5f;
    if (data != null) {
        GL11.glPushAttrib(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_LIGHTING_BIT);
        for (PowerTypes type : ((IPowerNode) te).getValidPowerTypes()) {
            float pwr = data.getPower(type);
            float pct = pwr / ((IPowerNode) te).getCapacity() * 100;
            AMVector3 offset = new AMVector3(event.target.blockX + 0.5, event.target.blockY + 0.5, event.target.blockZ + 0.5).sub(new AMVector3((event.player.prevPosX - (event.player.prevPosX - event.player.posX) * event.partialTicks), (event.player.prevPosY - (event.player.prevPosY - event.player.posY) * event.partialTicks) + event.player.getEyeHeight(), (event.player.prevPosZ - (event.player.prevPosZ - event.player.posZ) * event.partialTicks)));
            offset = offset.normalize();
            if (event.target.blockY <= event.player.posY - 0.5) {
                RenderUtilities.drawTextInWorldAtOffset(String.format("%s%.2f (%.2f%%)", type.chatColor(), pwr, pct), event.target.blockX - (event.player.prevPosX - (event.player.prevPosX - event.player.posX) * event.partialTicks) + 0.5f - offset.x, event.target.blockY + yOff - (event.player.prevPosY - (event.player.prevPosY - event.player.posY) * event.partialTicks) + block.getBlockBoundsMaxY() * 0.8f, event.target.blockZ - (event.player.prevPosZ - (event.player.prevPosZ - event.player.posZ) * event.partialTicks) + 0.5f - offset.z, 0xFFFFFF);
                yOff += 0.12f;
            } else {
                RenderUtilities.drawTextInWorldAtOffset(String.format("%s%.2f (%.2f%%)", type.chatColor(), pwr, pct), event.target.blockX - (event.player.prevPosX - (event.player.prevPosX - event.player.posX) * event.partialTicks) + 0.5f - offset.x, event.target.blockY - yOff - (event.player.prevPosY - (event.player.prevPosY - event.player.posY) * event.partialTicks) - block.getBlockBoundsMaxY() * 0.2f, event.target.blockZ - (event.player.prevPosZ - (event.player.prevPosZ - event.player.posZ) * event.partialTicks) + 0.5f - offset.z, 0xFFFFFF);
                yOff -= 0.12f;
            }
        }
        GL11.glPopAttrib();
    }
}
Also used : AMVector3(am2.api.math.AMVector3) PowerTypes(am2.api.power.PowerTypes) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) PowerNodeEntry(am2.power.PowerNodeEntry) IPowerNode(am2.api.power.IPowerNode)

Example 58 with AMVector3

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

the class FlickerOperatorItemTransport method FindOutput.

/**
	 * Will try to find a place to move the item stack
	 *
	 * @param stack The item stack to move
	 * @return Returns true if the item can be moved, returns false otherwise
	 */
private boolean FindOutput(World worldObj, TileEntityFlickerHabitat attuner, ItemStack stack, IInventory source) {
    HashMap<Integer, ArrayList<AMVector3>> removeFromOutList = new HashMap<Integer, ArrayList<AMVector3>>();
    boolean itemMoved = false;
    for (int priority = 0; priority <= TileEntityFlickerHabitat.PRIORITY_FINAL; ++priority) {
        if (attuner.getOutListPosition(priority) >= attuner.getOutListSize(priority)) {
            //if the out list position has gone outside the list size reset it to 0
            attuner.setOutListPosition(priority, 0);
        }
        int start = attuner.getOutListPosition(priority);
        int pos = start;
        boolean fullLoop = false;
        while (!fullLoop) {
            //get the crystal marker tile entity for the specified position
            AMVector3 vector = attuner.getOutListAt(priority, pos);
            TileEntity te = null;
            TileEntityCrystalMarker crystalMarkerTE = GetCrystalMarkerTileEntity(worldObj, (int) vector.x, (int) vector.y, (int) vector.z);
            if (crystalMarkerTE == null) {
                //crystal marker no longer exists, remove it from the list
                if (!removeFromOutList.containsKey(priority))
                    removeFromOutList.put(priority, new ArrayList<AMVector3>());
                removeFromOutList.get(priority).add(vector);
                break;
            }
            te = GetAttachedCrystalMarkerTileEntity(worldObj, crystalMarkerTE, vector);
            int markerType = worldObj.getBlockMetadata((int) vector.x, (int) vector.y, (int) vector.z);
            if (te != null && te instanceof IInventory) {
                IInventory inventory = (IInventory) te;
                itemMoved = outputItem(markerType, new IInventory[] { inventory }, stack, crystalMarkerTE, new IInventory[] { source });
                if (itemMoved) {
                    attuner.setOutListPosition(priority, pos + 1);
                }
            }
            if (!itemMoved && te instanceof TileEntityChest) {
                //This handles the special case of double chests
                TileEntityChest adjacent = InventoryUtilities.getAdjacentChest((TileEntityChest) te);
                if (adjacent != null) {
                    IInventory inventory = adjacent;
                    itemMoved = outputItem(markerType, new IInventory[] { inventory, (IInventory) te }, stack, crystalMarkerTE, new IInventory[] { source });
                    if (itemMoved) {
                        attuner.setOutListPosition(priority, pos + 1);
                    }
                }
            }
            if (itemMoved)
                break;
            pos++;
            pos %= attuner.getOutListSize(priority);
            if (pos == start)
                fullLoop = true;
        }
        for (int i : removeFromOutList.keySet()) {
            for (AMVector3 vector : removeFromOutList.get(i)) {
                attuner.removeOutListAt(i, vector);
            }
        }
        if (!itemMoved) {
            attuner.setOutListPosition(priority, 0);
        } else {
            break;
        }
    }
    return itemMoved;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3) TileEntityChest(net.minecraft.tileentity.TileEntityChest) TileEntityCrystalMarker(am2.blocks.tileentities.TileEntityCrystalMarker) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 59 with AMVector3

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

the class EntitySpellEffect method getAllBlockLocationsBetween.

private AMVector3[] getAllBlockLocationsBetween(AMVector3 a, AMVector3 b) {
    a.floorToI();
    b.floorToI();
    double stepX = a.x < b.x ? 0.2f : -0.2f;
    double stepZ = a.z < b.z ? 0.2f : -0.2f;
    ArrayList<AMVector3> vecList = new ArrayList<AMVector3>();
    AMVector3 curPos = new AMVector3(a.x, a.y, a.z);
    for (int i = 0; i < this.height; ++i) {
        vecList.add(new AMVector3(curPos.x, curPos.y + i, curPos.z));
    }
    while (stepX != 0 || stepZ != 0) {
        if ((stepX < 0 && curPos.x <= b.x) || (stepX > 0 && curPos.x >= b.x))
            stepX = 0;
        if ((stepZ < 0 && curPos.z <= b.z) || (stepZ > 0 && curPos.z >= b.z))
            stepZ = 0;
        curPos = new AMVector3(curPos.x + stepX, curPos.y, curPos.z + stepZ);
        AMVector3 tempPos = curPos.copy();
        tempPos.roundToI();
        if (!vecList.contains(tempPos)) {
            for (int i = 0; i < this.height; ++i) {
                vecList.add(new AMVector3(tempPos.x, tempPos.y + i, tempPos.z));
            }
        }
    }
    return vecList.toArray(new AMVector3[vecList.size()]);
}
Also used : AMVector3(am2.api.math.AMVector3) ArrayList(java.util.ArrayList)

Example 60 with AMVector3

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

the class EntitySpellEffect method waveUpdate.

private void waveUpdate() {
    ticksToEffect = 0;
    wallUpdate();
    double dx = Math.cos(Math.toRadians(this.rotationYaw + 90));
    double dz = Math.sin(Math.toRadians(this.rotationYaw + 90));
    this.moveEntity(dx * moveSpeed, 0, dz * moveSpeed);
    double dxH = Math.cos(Math.toRadians(this.rotationYaw));
    double dzH = Math.sin(Math.toRadians(this.rotationYaw));
    float radius = this.dataWatcher.getWatchableObjectFloat(WATCHER_RADIUS);
    AMVector3 a = new AMVector3((this.posX + dx) - dxH * radius, this.posY, (this.posZ + dz) - dzH * radius);
    AMVector3 b = new AMVector3((this.posX + dx) - dxH * -radius, this.posY, (this.posZ + dz) - dzH * -radius);
    if (dummycaster == null) {
        dummycaster = DummyEntityPlayer.fromEntityLiving(new EntityDummyCaster(worldObj));
    }
    AMVector3[] vecs = getAllBlockLocationsBetween(a, b);
    for (AMVector3 vec : vecs) {
        SpellHelper.instance.applyStageToGround(spellStack, dummycaster, worldObj, (int) vec.x, (int) vec.y, (int) vec.z, 0, vec.x + 0.5, vec.y + 0.5, vec.z + 0.5, 0, false);
    }
}
Also used : AMVector3(am2.api.math.AMVector3)

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