Search in sources :

Example 1 with IElectricityNetwork

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) IElectricityNetwork(micdoodle8.mods.galacticraft.api.transmission.grid.IElectricityNetwork) HashSet(java.util.HashSet) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 2 with IElectricityNetwork

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IConductor(micdoodle8.mods.galacticraft.api.transmission.tile.IConductor) EnumFacing(net.minecraft.util.EnumFacing) IElectricityNetwork(micdoodle8.mods.galacticraft.api.transmission.grid.IElectricityNetwork) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 3 with IElectricityNetwork

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;
}
Also used : EnergyNetwork(micdoodle8.mods.galacticraft.core.energy.grid.EnergyNetwork) IElectricityNetwork(micdoodle8.mods.galacticraft.api.transmission.grid.IElectricityNetwork)

Example 4 with IElectricityNetwork

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;
}
Also used : EnergyNetwork(micdoodle8.mods.galacticraft.core.energy.grid.EnergyNetwork) IElectricityNetwork(micdoodle8.mods.galacticraft.api.transmission.grid.IElectricityNetwork)

Aggregations

IElectricityNetwork (micdoodle8.mods.galacticraft.api.transmission.grid.IElectricityNetwork)4 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)2 EnergyNetwork (micdoodle8.mods.galacticraft.core.energy.grid.EnergyNetwork)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 HashSet (java.util.HashSet)1 IConductor (micdoodle8.mods.galacticraft.api.transmission.tile.IConductor)1