Search in sources :

Example 86 with AMVector3

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

the class PowerNodeRegistry method registerPowerNodeInternal.

PowerNodeEntry registerPowerNodeInternal(IPowerNode node) {
    ChunkCoordIntPair chunk = getChunkFromNode(node);
    HashMap<AMVector3, PowerNodeEntry> nodeList;
    TileEntity te = ((TileEntity) node);
    World world = te.getWorldObj();
    if (powerNodes.containsKey(chunk)) {
        nodeList = powerNodes.get(chunk);
        LogHelper.trace("Located Power Node list for chunk %d, %d", chunk.chunkXPos, chunk.chunkZPos);
    } else {
        LogHelper.trace("Node list not found.  Checking cache/files for prior data");
        NBTTagCompound compound = PowerNodeCache.instance.getNBTForChunk(world, chunk);
        nodeList = new HashMap<AMVector3, PowerNodeEntry>();
        if (compound == null || !compound.hasKey("AM2PowerData")) {
            powerNodes.put(chunk, nodeList);
            LogHelper.trace("Prior node list not found.  Created Power Node list for chunk %d, %d", chunk.chunkXPos, chunk.chunkZPos);
        } else {
            LoadChunkFromNBT(chunk, compound);
            nodeList = powerNodes.get(chunk);
            //sanity check
            if (nodeList == null)
                nodeList = new HashMap<AMVector3, PowerNodeEntry>();
            LogHelper.trace("Loaded power data for chunk %d, %d", chunk.chunkXPos, chunk.chunkZPos);
        }
    }
    AMVector3 nodeLoc = new AMVector3((TileEntity) node);
    //prevent duplicate registrations
    if (nodeList.containsKey(nodeLoc))
        return nodeList.get(nodeLoc);
    PowerNodeEntry pnd = new PowerNodeEntry();
    nodeList.put(nodeLoc, pnd);
    LogHelper.trace("Successfully registered power node at {%d, %d, %d}", ((TileEntity) node).xCoord, ((TileEntity) node).yCoord, ((TileEntity) node).zCoord);
    return pnd;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) World(net.minecraft.world.World)

Example 87 with AMVector3

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

the class PowerNodeEntry method validatePath.

private boolean validatePath(World world, LinkedList<AMVector3> path) {
    for (AMVector3 vec : path) {
        //power can't transfer through unloaded chunks!
        Chunk chunk = world.getChunkFromBlockCoords((int) vec.x, (int) vec.z);
        if (!chunk.isChunkLoaded)
            return false;
        TileEntity te = world.getTileEntity((int) vec.x, (int) vec.y, (int) vec.z);
        //if valid, continue the loop, otherwise return false.
        if (te != null && te instanceof IPowerNode)
            continue;
        //set a marker block to say that a conduit or other power relay of some sort was here and is now not
        if (!world.isRemote && world.isAirBlock((int) vec.x, (int) vec.y, (int) vec.z)) {
            world.setBlock((int) vec.x, (int) vec.y, (int) vec.z, BlocksCommonProxy.brokenLinkBlock);
        }
        return false;
    }
    //if we're here, then all locations checked out
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) Chunk(net.minecraft.world.chunk.Chunk) IPowerNode(am2.api.power.IPowerNode)

Example 88 with AMVector3

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

the class PowerNodeEntry method saveToNBT.

public NBTTagCompound saveToNBT() {
    NBTTagCompound compound = new NBTTagCompound();
    //power amounts
    //list of entries containing power type IDs and the associated amount
    NBTTagList powerAmountStore = new NBTTagList();
    for (PowerTypes type : this.powerAmounts.keySet()) {
        if (//sanity check
        type == null)
            continue;
        //individual power type/amount entry
        NBTTagCompound powerType = new NBTTagCompound();
        //set power type ID
        powerType.setInteger("powerType", type.ID());
        //set power amount
        powerType.setFloat("powerAmount", powerAmounts.get(type));
        //attach the power node to the list
        powerAmountStore.appendTag(powerType);
    }
    //append list to output compound
    compound.setTag("powerAmounts", powerAmountStore);
    //power paths
    NBTTagList powerPathList = new NBTTagList();
    for (PowerTypes type : nodePaths.keySet()) {
        //This is the actual entry in the power path list
        NBTTagCompound powerPathEntry = new NBTTagCompound();
        ArrayList<LinkedList<AMVector3>> paths = nodePaths.get(type);
        //This stores each path individually for a given power type
        NBTTagList pathsForType = new NBTTagList();
        for (LinkedList<AMVector3> path : paths) {
            //This stores each individual node in the given path
            NBTTagList pathNodes = new NBTTagList();
            for (AMVector3 pathNode : path) {
                //This stores one individual node in the given path
                NBTTagCompound node = new NBTTagCompound();
                pathNode.writeToNBT(node);
                //Append individual node to path
                pathNodes.appendTag(node);
            }
            //Append path to list of paths for the power type
            pathsForType.appendTag(pathNodes);
        }
        //set the power type that this list of paths is for
        powerPathEntry.setInteger("powerType", type.ID());
        //append the list of paths to the entry in the power path list
        powerPathEntry.setTag("nodePaths", pathsForType);
        //AMCore.log.info("Saved %d node paths for %s etherium.", nodePaths.get(type).size(), type.name());
        //append this entry in the power path list to the list of power path entries
        powerPathList.appendTag(powerPathEntry);
    }
    //append the entire power path list to the saved compound
    compound.setTag("powerPathList", powerPathList);
    return compound;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) AMVector3(am2.api.math.AMVector3) PowerTypes(am2.api.power.PowerTypes) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) LinkedList(java.util.LinkedList)

Example 89 with AMVector3

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

the class PowerNodeEntry method requestPowerFrom.

private float requestPowerFrom(World world, LinkedList<AMVector3> path, PowerTypes type, float amount) {
    if (!validatePath(world, path))
        return 0f;
    AMVector3 end = path.getLast();
    TileEntity te = world.getTileEntity((int) end.x, (int) end.y, (int) end.z);
    if (te != null && te instanceof IPowerNode) {
        if (((IPowerNode) te).canProvidePower(type)) {
            return PowerNodeRegistry.For(world).consumePower(((IPowerNode) te), type, amount);
        }
    }
    return 0f;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) IPowerNode(am2.api.power.IPowerNode)

Example 90 with AMVector3

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

the class TileEntityArcaneReconstructor method updateEntity.

@Override
public void updateEntity() {
    if (isFirstTick) {
        outerRingRotationSpeeds = new AMVector3(worldObj.rand.nextDouble() * 4 - 2, worldObj.rand.nextDouble() * 4 - 2, worldObj.rand.nextDouble() * 4 - 2);
        middleRingRotationSpeeds = new AMVector3(worldObj.rand.nextDouble() * 4 - 2, worldObj.rand.nextDouble() * 4 - 2, worldObj.rand.nextDouble() * 4 - 2);
        innerRingRotationSpeeds = new AMVector3(worldObj.rand.nextDouble() * 4 - 2, worldObj.rand.nextDouble() * 4 - 2, worldObj.rand.nextDouble() * 4 - 2);
        isFirstTick = false;
    }
    if (PowerNodeRegistry.For(this.worldObj).checkPower(this, this.getRepairCost())) {
        // has enough power
        if ((repairCounter++ % getRepairRate() == 0) && (!queueRepairableItem())) {
            // has ticked and already has item queued
            if (performRepair()) {
                // something to repair
                if (!worldObj.isRemote) {
                    PowerNodeRegistry.For(this.worldObj).consumePower(this, PowerNodeRegistry.For(worldObj).getHighestPowerType(this), this.getRepairCost());
                }
            }
        }
        deactivationDelayTicks = 0;
    } else if (!worldObj.isRemote && active) {
        // out of power, on server and active
        if (deactivationDelayTicks++ > 100) {
            // 5 seconds
            deactivationDelayTicks = 0;
            this.active = false;
            if (!worldObj.isRemote)
                worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
        }
    }
    if (worldObj.isRemote) {
        updateRotations();
        if (shouldRenderItemStack()) {
            AMParticle p = (AMParticle) AMCore.instance.proxy.particleManager.spawn(worldObj, "sparkle2", xCoord + 0.2 + (worldObj.rand.nextDouble() * 0.6), yCoord + 0.4, zCoord + 0.2 + (worldObj.rand.nextDouble() * 0.6));
            if (p != null) {
                p.AddParticleController(new ParticleFloatUpward(p, 0.0f, 0.02f, 1, false));
                p.setIgnoreMaxAge(true);
                p.setParticleScale(0.1f);
                p.AddParticleController(new ParticleFadeOut(p, 1, false).setFadeSpeed(0.035f).setKillParticleOnFinish(true));
                p.setRGBColorF(1, 0, 1);
            }
        }
    }
    super.updateEntity();
}
Also used : AMVector3(am2.api.math.AMVector3) AMParticle(am2.particles.AMParticle) ParticleFadeOut(am2.particles.ParticleFadeOut) ParticleFloatUpward(am2.particles.ParticleFloatUpward)

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