Search in sources :

Example 1 with ReceptorEntry

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;
}
Also used : IPowerStorage(crazypants.enderio.base.power.IPowerStorage) ReceptorEntry(crazypants.enderio.conduits.conduit.power.PowerConduitNetwork.ReceptorEntry)

Example 2 with ReceptorEntry

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;
}
Also used : IPowerInterface(crazypants.enderio.base.power.IPowerInterface) ReceptorEntry(crazypants.enderio.conduits.conduit.power.PowerConduitNetwork.ReceptorEntry) HashSet(java.util.HashSet)

Example 3 with ReceptorEntry

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);
}
Also used : IPowerInterface(crazypants.enderio.base.power.IPowerInterface) ReceptorEntry(crazypants.enderio.conduits.conduit.power.PowerConduitNetwork.ReceptorEntry)

Example 4 with ReceptorEntry

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;
}
Also used : IPowerInterface(crazypants.enderio.base.power.IPowerInterface) ReceptorEntry(crazypants.enderio.conduits.conduit.power.PowerConduitNetwork.ReceptorEntry) HashSet(java.util.HashSet)

Aggregations

ReceptorEntry (crazypants.enderio.conduits.conduit.power.PowerConduitNetwork.ReceptorEntry)4 IPowerInterface (crazypants.enderio.base.power.IPowerInterface)3 HashSet (java.util.HashSet)2 IPowerStorage (crazypants.enderio.base.power.IPowerStorage)1