Search in sources :

Example 1 with PowerNodeEntry

use of am2.power.PowerNodeEntry in project ArsMagica2 by Mithion.

the class AMPacketProcessorClient method handleRcvPowerPaths.

private void handleRcvPowerPaths(byte[] data) {
    AMDataReader rdr = new AMDataReader(data, false);
    byte bite = rdr.getByte();
    NBTTagCompound compound = rdr.getNBTTagCompound();
    if (bite == 0) {
        PowerNodeEntry pnd = PowerNodeRegistry.For(Minecraft.getMinecraft().theWorld).parseFromNBT(compound);
        AMCore.proxy.receivePowerPathVisuals(pnd.getNodePaths());
    } else if (bite == 1) {
        int x = rdr.getInt();
        int y = rdr.getInt();
        int z = rdr.getInt();
        AMCore.proxy.setTrackedPowerCompound((NBTTagCompound) compound.copy());
        TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(x, y, z);
        if (te != null && te instanceof IPowerNode)
            PowerNodeRegistry.For(Minecraft.getMinecraft().theWorld).setDataCompoundForNode((IPowerNode) te, compound);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PowerNodeEntry(am2.power.PowerNodeEntry) IPowerNode(am2.api.power.IPowerNode)

Example 2 with PowerNodeEntry

use of am2.power.PowerNodeEntry in project ArsMagica2 by Mithion.

the class ClientProxy method drawPowerOnBlockHighlight.

@Override
public void drawPowerOnBlockHighlight(EntityPlayer player, MovingObjectPosition target, float partialTicks) {
    if (AMCore.proxy.getLocalPlayer().getCurrentArmor(3) != null && (AMCore.proxy.getLocalPlayer().getCurrentArmor(3).getItem() == ItemsCommonProxy.magitechGoggles || ArmorHelper.isInfusionPreset(AMCore.proxy.getLocalPlayer().getCurrentArmor(3), GenericImbuement.magitechGoggleIntegration))) {
        TileEntity te = player.worldObj.getTileEntity(target.blockX, target.blockY, target.blockZ);
        if (te != null && te instanceof IPowerNode) {
            AMCore.proxy.setTrackedLocation(new AMVector3(target.blockX, target.blockY, target.blockZ));
        } else {
            AMCore.proxy.setTrackedLocation(AMVector3.zero());
        }
        if (AMCore.proxy.hasTrackedLocationSynced()) {
            PowerNodeEntry data = AMCore.proxy.getTrackedData();
            Block block = player.worldObj.getBlock(target.blockX, target.blockY, 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;
                    RenderUtilities.drawTextInWorldAtOffset(String.format("%s%.2f (%.2f%%)", type.chatColor(), pwr, pct), target.blockX - (player.prevPosX - (player.prevPosX - player.posX) * partialTicks) + 0.5f, target.blockY + yOff - (player.prevPosY - (player.prevPosY - player.posY) * partialTicks) + block.getBlockBoundsMaxY() * 0.8f, target.blockZ - (player.prevPosZ - (player.prevPosZ - player.posZ) * partialTicks) + 0.5f, 0xFFFFFF);
                    yOff += 0.12f;
                }
                GL11.glPopAttrib();
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) PowerTypes(am2.api.power.PowerTypes) Block(net.minecraft.block.Block) PowerNodeEntry(am2.power.PowerNodeEntry) IPowerNode(am2.api.power.IPowerNode)

Example 3 with PowerNodeEntry

use of am2.power.PowerNodeEntry in project ArsMagica2 by Mithion.

the class PowerNodeRegistry method LoadChunkFromNBT.

public void LoadChunkFromNBT(ChunkCoordIntPair chunk, NBTTagCompound compound) {
    if (!compound.hasKey("AM2PowerData"))
        //nothing was saved in this chunk for the power system
        return;
    NBTTagList powerNodeTagList = compound.getTagList("AM2PowerData", Constants.NBT.TAG_COMPOUND);
    HashMap<AMVector3, PowerNodeEntry> chunkPowerData = new HashMap<AMVector3, PowerNodeEntry>();
    for (int i = 0; i < powerNodeTagList.tagCount(); ++i) {
        NBTTagCompound nodeCompound = (NBTTagCompound) powerNodeTagList.getCompoundTagAt(i);
        AMVector3 nodeLocation = new AMVector3(nodeCompound.getInteger("xCoord"), nodeCompound.getInteger("yCoord"), nodeCompound.getInteger("zCoord"));
        PowerNodeEntry pnd = new PowerNodeEntry();
        pnd.readFromNBT(nodeCompound.getCompoundTag("nodeData"));
        chunkPowerData.put(nodeLocation, pnd);
    }
    LogHelper.trace("Loaded %d power node entries", chunkPowerData.size());
    powerNodes.put(chunk, chunkPowerData);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) AMVector3(am2.api.math.AMVector3) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 4 with PowerNodeEntry

use of am2.power.PowerNodeEntry in project ArsMagica2 by Mithion.

the class ClientTickHandler method setTrackData.

public void setTrackData(NBTTagCompound compound) {
    this.powerData = new PowerNodeEntry();
    this.powerData.readFromNBT(compound);
    this.hasSynced = true;
}
Also used : PowerNodeEntry(am2.power.PowerNodeEntry)

Example 5 with PowerNodeEntry

use of am2.power.PowerNodeEntry in project ArsMagica2 by Mithion.

the class PowerNodeRegistry method getAllNearbyNodes.

/**
	 * Returns all power nodes within POWER_SEARCH_RADIUS
	 *
	 * @param location The center point to search from
	 * @param power    The power type that the provider needs to supply or accept to be considered valid
	 * @return An array of IPowerNodes
	 */
public IPowerNode[] getAllNearbyNodes(World world, AMVector3 location, PowerTypes power) {
    //get the list of chunks we'll need to search in
    ChunkCoordIntPair[] search = getSearchChunks(location);
    //build the list of nodes from that chunk
    HashMap<AMVector3, PowerNodeEntry> nodesToSearch = new HashMap<AMVector3, PowerNodeEntry>();
    for (ChunkCoordIntPair pair : search) {
        HashMap<AMVector3, PowerNodeEntry> nodesInChunk = powerNodes.get(pair);
        if (nodesInChunk != null) {
            //Add only vectors that are less than or equal to POWER_SEARCH_RADIUS_SQ away
            for (AMVector3 vector : nodesInChunk.keySet()) {
                if (location.distanceSqTo(vector) <= POWER_SEARCH_RADIUS_SQ && !vector.equals(location)) {
                    nodesToSearch.put(vector, nodesInChunk.get(vector));
                }
            }
        }
    }
    //spin through and create our list of providers
    ArrayList<IPowerNode> nodes = new ArrayList<IPowerNode>();
    int deadNodesRemoved = 0;
    for (AMVector3 vector : nodesToSearch.keySet()) {
        if (!world.checkChunksExist((int) vector.x, (int) vector.y, (int) vector.z, (int) vector.x, (int) vector.y, (int) vector.z)) {
            continue;
        }
        Chunk chunk = world.getChunkFromBlockCoords((int) vector.x, (int) vector.z);
        if (!chunk.isChunkLoaded)
            continue;
        TileEntity te = world.getTileEntity((int) vector.x, (int) vector.y, (int) vector.z);
        if (te == null || !(te instanceof IPowerNode)) {
            //opportune time to remove dead power nodes
            removePowerNode(chunk.getChunkCoordIntPair(), vector);
            deadNodesRemoved++;
            continue;
        }
        IPowerNode node = (IPowerNode) te;
        nodes.add(node);
    }
    if (deadNodesRemoved > 0)
        LogHelper.trace("Removed %d dead power nodes", deadNodesRemoved);
    IPowerNode[] nodeArray = nodes.toArray(new IPowerNode[nodes.size()]);
    LogHelper.trace("Located %d nearby power providers", nodeArray.length);
    return nodeArray;
}
Also used : ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) Chunk(net.minecraft.world.chunk.Chunk) TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) IPowerNode(am2.api.power.IPowerNode)

Aggregations

AMVector3 (am2.api.math.AMVector3)6 IPowerNode (am2.api.power.IPowerNode)4 PowerNodeEntry (am2.power.PowerNodeEntry)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 TileEntity (net.minecraft.tileentity.TileEntity)4 PowerTypes (am2.api.power.PowerTypes)2 Block (net.minecraft.block.Block)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)2 ItemBlock (net.minecraft.item.ItemBlock)1 World (net.minecraft.world.World)1 Chunk (net.minecraft.world.chunk.Chunk)1