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