Search in sources :

Example 1 with IPowerInterface

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

Example 2 with IPowerInterface

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

Example 3 with IPowerInterface

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());
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) IPowerInterface(crazypants.enderio.base.power.IPowerInterface) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with IPowerInterface

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;
}
Also used : EnergyReceptor(crazypants.enderio.powertools.machine.capbank.network.EnergyReceptor) EnumFacing(net.minecraft.util.EnumFacing) IPowerInterface(crazypants.enderio.base.power.IPowerInterface) IoMode(crazypants.enderio.base.machine.modes.IoMode)

Example 5 with IPowerInterface

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

Aggregations

IPowerInterface (crazypants.enderio.base.power.IPowerInterface)8 ReceptorEntry (crazypants.enderio.conduits.conduit.power.PowerConduitNetwork.ReceptorEntry)3 EnumFacing (net.minecraft.util.EnumFacing)3 IoMode (crazypants.enderio.base.machine.modes.IoMode)2 HashSet (java.util.HashSet)2 IConduitBundle (crazypants.enderio.base.conduit.IConduitBundle)1 IPowerConduit (crazypants.enderio.conduits.conduit.power.IPowerConduit)1 EnergyReceptor (crazypants.enderio.powertools.machine.capbank.network.EnergyReceptor)1 FillGaugeBakery (crazypants.enderio.powertools.machine.capbank.render.FillGaugeBakery)1 Nonnull (javax.annotation.Nonnull)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1