use of crazypants.enderio.conduits.conduit.power.PowerConduitNetwork.ReceptorEntry in project EnderIO by SleepyTrousers.
the class NetworkPowerManager method checkReceptors.
private void checkReceptors() {
if (!receptorsDirty) {
return;
}
receptors.clear();
storageReceptors.clear();
for (ReceptorEntry rec : network.getPowerReceptors()) {
if (rec.powerInterface.getProvider() != null && rec.powerInterface.getProvider() instanceof IPowerStorage) {
storageReceptors.add(rec);
} else {
receptors.add(rec);
}
}
receptorIterator = receptors.listIterator();
receptorsDirty = false;
}
use of crazypants.enderio.conduits.conduit.power.PowerConduitNetwork.ReceptorEntry 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.conduits.conduit.power.PowerConduitNetwork.ReceptorEntry 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.conduits.conduit.power.PowerConduitNetwork.ReceptorEntry in project EnderIO by SleepyTrousers.
the class NetworkPowerManager method getMaxPowerInReceptors.
public long getMaxPowerInReceptors() {
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.getMaxEnergyStored();
}
}
}
return result;
}
Aggregations