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);
}
}
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();
}
}
}
}
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);
}
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;
}
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;
}
Aggregations