use of crazypants.enderio.base.power.IPowerInterface in project EnderIO by SleepyTrousers.
the class NetworkPowerManager method getPowerInReceptors.
public long getPowerInReceptors() {
long result = 0;
Set<Object> done = new HashSet<Object>();
for (ReceptorEntry re : receptors) {
if (!re.emmiter.getConnectionsDirty()) {
IPowerInterface powerReceptor = re.powerInterface;
if (!done.contains(powerReceptor.getProvider())) {
done.add(powerReceptor.getProvider());
result += powerReceptor.getEnergyStored();
}
}
}
return result;
}
use of crazypants.enderio.base.power.IPowerInterface in project EnderIO by SleepyTrousers.
the class NetworkPowerManager method doApplyRecievedPower.
public void doApplyRecievedPower(@Nullable Profiler profiler) {
trackerStartTick();
Prof.start(profiler, "checkReceptors");
checkReceptors();
// Update our energy stored based on what's in our conduits
Prof.next(profiler, "updateNetworkStorage");
updateNetworkStorage();
networkPowerTracker.tickStart(energyStored);
Prof.next(profiler, "capSupplyInit");
capSupply.init();
int appliedCount = 0;
int numReceptors = receptors.size();
int available = energyStored + capSupply.canExtract;
int wasAvailable = available;
if (available <= 0 || (receptors.isEmpty() && storageReceptors.isEmpty())) {
trackerEndTick();
networkPowerTracker.tickEnd(energyStored);
Prof.stop(profiler);
return;
}
Prof.next(profiler, "sendEnergy");
while (available > 0 && appliedCount < numReceptors) {
if (!receptors.isEmpty() && !receptorIterator.hasNext()) {
receptorIterator = receptors.listIterator();
}
ReceptorEntry r = receptorIterator.next();
IPowerInterface pp = r.powerInterface;
if (pp != null) {
int canOffer = Math.min(r.emmiter.getMaxEnergyExtracted(r.direction), available);
Prof.start(profiler, "", pp.getProvider());
int used = pp.receiveEnergy(canOffer, false);
Prof.next(profiler, "trackEnergy");
used = Math.max(0, used);
trackerSend(r.emmiter, used, false);
available -= used;
Prof.stop(profiler);
if (available <= 0) {
break;
}
}
appliedCount++;
}
int used = wasAvailable - available;
// use all the capacator storage first
energyStored -= used;
Prof.next(profiler, "capBankUpdate");
if (!capSupply.capBanks.isEmpty()) {
int capBankChange = 0;
if (energyStored < 0) {
// not enough so get the rest from the capacitor bank
capBankChange = energyStored;
energyStored = 0;
} else if (energyStored > 0) {
// push as much as we can back to the cap banks
capBankChange = Math.min(energyStored, capSupply.canFill);
energyStored -= capBankChange;
}
if (capBankChange < 0) {
capSupply.remove(Math.abs(capBankChange));
} else if (capBankChange > 0) {
capSupply.add(capBankChange);
}
capSupply.balance();
}
Prof.next(profiler, "conduitUpdate");
distributeStorageToConduits();
Prof.next(profiler, "trackEnergy");
trackerEndTick();
networkPowerTracker.tickEnd(energyStored);
Prof.stop(profiler);
}
use of crazypants.enderio.base.power.IPowerInterface in project EnderIO by SleepyTrousers.
the class PowerConduitNetwork method addConduit.
@Override
public void addConduit(@Nonnull IPowerConduit con) {
super.addConduit(con);
Set<EnumFacing> externalDirs = con.getExternalConnections();
for (EnumFacing dir : externalDirs) {
IPowerInterface pr = con.getExternalPowerReceptor(dir);
if (pr != null) {
TileEntity te = con.getBundle().getEntity();
BlockPos p = te.getPos().offset(dir);
powerReceptorAdded(con, dir, p.getX(), p.getY(), p.getZ(), pr);
}
}
if (powerManager != null) {
con.setActive(powerManager.isActive());
}
}
use of crazypants.enderio.base.power.IPowerInterface in project EnderIO by SleepyTrousers.
the class TileCapBank method updateReceptors.
private void updateReceptors() {
if (network == null) {
return;
}
network.removeReceptors(receptors);
receptors.clear();
for (EnumFacing dir : EnumFacing.values()) {
IPowerInterface pi = getReceptorForFace(NullHelper.notnullJ(dir, "Enum.values()"));
if (pi != null) {
IoMode ioMode = getIoMode(NullHelper.notnullJ(dir, "Enum.values()"));
if (ioMode != IoMode.DISABLED && ioMode != IoMode.PULL) {
EnergyReceptor er = new EnergyReceptor(this, pi, NullHelper.notnullJ(dir, "Enum.values()"));
validateModeForReceptor(er);
receptors.add(er);
}
}
}
network.addReceptors(receptors);
receptorsDirty = false;
}
use of crazypants.enderio.base.power.IPowerInterface in project EnderIO by SleepyTrousers.
the class CapBankNetwork method sendPowerTo.
private int sendPowerTo(EnergyReceptor next, int available) {
// Can only send to power conduits if we are in push mode or the conduit is in pull mode
// With default setting interaction between conduits and Cap Banks is handled by NetworkPowerManager
IPowerConduit con = next.getConduit();
if (con != null && next.getMode() == IoMode.NONE && con.getConnectionMode(next.getDir().getOpposite()) == ConnectionMode.IN_OUT) {
return 0;
}
IPowerInterface inf = next.getReceptor();
int result = inf.receiveEnergy(available, false);
if (result < 0) {
result = 0;
}
return result;
}
Aggregations