use of micdoodle8.mods.galacticraft.api.transmission.grid.IElectricityNetwork in project Galacticraft by micdoodle8.
the class NetworkHelper method getNetworksFromMultipleSides.
/**
* @param tileEntity - The TileEntity's sides.
* @param approachingDirection - The directions that can be connected.
* @return A list of networks from all specified sides. There will be no
* repeated ElectricityNetworks and it will never return null.
*/
public static Set<IElectricityNetwork> getNetworksFromMultipleSides(TileEntity tileEntity, EnumSet<EnumFacing> approachingDirection) {
final Set<IElectricityNetwork> connectedNetworks = new HashSet<IElectricityNetwork>();
BlockVec3 tileVec = new BlockVec3(tileEntity);
for (EnumFacing side : EnumFacing.VALUES) {
if (approachingDirection.contains(side)) {
TileEntity outputConductor = tileVec.getTileEntityOnSide(tileEntity.getWorld(), side);
IElectricityNetwork electricityNetwork = NetworkHelper.getElectricalNetworkFromTileEntity(outputConductor, side);
if (electricityNetwork != null) {
connectedNetworks.add(electricityNetwork);
}
}
}
return connectedNetworks;
}
use of micdoodle8.mods.galacticraft.api.transmission.grid.IElectricityNetwork in project Galacticraft by micdoodle8.
the class TileBaseUniversalElectricalSource method produce.
/*
* Function to produce energy each tick into the outputs of a source.
* If simulate is true, no energy is in fact transferred.
*
* Note: even if simulate is false this does NOT reduce the source's own
* energy storage by the amount produced, that needs to be done elsewhere
* See this.produce() for an example.
*/
public float produce(boolean simulate) {
float amountProduced = 0;
if (!this.worldObj.isRemote) {
EnumSet<EnumFacing> outputDirections = this.getElectricalOutputDirections();
// outputDirections.remove(EnumFacing.UNKNOWN);
BlockVec3 thisVec = new BlockVec3(this);
for (EnumFacing direction : outputDirections) {
TileEntity tileAdj = thisVec.getTileEntityOnSide(this.worldObj, direction);
if (tileAdj != null) {
float toSend = this.extractEnergyGC(null, Math.min(this.getEnergyStoredGC() - amountProduced, this.getEnergyStoredGC() / outputDirections.size()), true);
if (toSend <= 0) {
continue;
}
if (tileAdj instanceof TileBaseConductor && ((TileBaseConductor) tileAdj).canConnect(direction.getOpposite(), NetworkType.POWER)) {
IElectricityNetwork network = ((IConductor) tileAdj).getNetwork();
if (network != null) {
amountProduced += (toSend - network.produce(toSend, !simulate, this.tierGC, this));
}
} else if (tileAdj instanceof TileBaseUniversalElectrical) {
amountProduced += ((TileBaseUniversalElectrical) tileAdj).receiveElectricity(direction.getOpposite(), toSend, this.tierGC, !simulate);
} else {
amountProduced += EnergyUtil.otherModsEnergyTransfer(tileAdj, direction.getOpposite(), toSend, simulate);
}
}
}
}
return amountProduced;
}
use of micdoodle8.mods.galacticraft.api.transmission.grid.IElectricityNetwork in project Galacticraft by micdoodle8.
the class TileEntityAluminumWireSwitch method getNetwork.
@Override
public IElectricityNetwork getNetwork() {
if (this.network == null) {
EnergyNetwork network = new EnergyNetwork();
if (!this.disableConnections)
network.getTransmitters().add(this);
this.setNetwork(network);
}
return (IElectricityNetwork) this.network;
}
use of micdoodle8.mods.galacticraft.api.transmission.grid.IElectricityNetwork in project Galacticraft by micdoodle8.
the class TileBaseConductor method getNetwork.
@Override
public IElectricityNetwork getNetwork() {
if (this.network == null) {
EnergyNetwork network = new EnergyNetwork();
network.getTransmitters().add(this);
this.setNetwork(network);
}
return (IElectricityNetwork) this.network;
}
Aggregations