Search in sources :

Example 1 with EnergySourceWireless

use of micdoodle8.mods.galacticraft.api.power.EnergySource.EnergySourceWireless in project Galacticraft by micdoodle8.

the class TileEntityBeamReceiver method update.

@Override
public void update() {
    super.update();
    if (this.preLoadFacing != -1) {
        this.setFacing(EnumFacing.getFront(this.preLoadFacing));
        this.preLoadFacing = -1;
    }
    if (!this.worldObj.isRemote) {
        if (this.getTarget() != null && this.modeReceive == ReceiverMode.EXTRACT.ordinal() && this.facing != null) {
            TileEntity tile = this.getAttachedTile();
            if (tile instanceof TileBaseUniversalElectricalSource) {
                // GC energy source
                TileBaseUniversalElectricalSource electricalTile = (TileBaseUniversalElectricalSource) tile;
                if (electricalTile.storage.getEnergyStoredGC() > 0) {
                    EnergySourceAdjacent source = new EnergySourceAdjacent(EnumFacing.getFront(this.facing.getIndex() ^ 1));
                    float toSend = Math.min(electricalTile.storage.getMaxExtract(), electricalTile.storage.getEnergyStoredGC());
                    float transmitted = this.getTarget().receiveEnergyGC(new EnergySourceWireless(Lists.newArrayList((ILaserNode) this)), toSend, false);
                    electricalTile.extractEnergyGC(source, transmitted, false);
                }
            } else if (!(tile instanceof EnergyStorageTile) && !(tile instanceof TileBaseConductor)) // Another mod's energy source
            // But don't use other mods methods to connect Beam Receivers to GC's own wires or machines
            {
                float availableToSend = EnergyUtil.otherModsEnergyExtract(tile, this.facing, this.maxRate, true);
                if (availableToSend > 0F) {
                    float transmitted = this.getTarget().receiveEnergyGC(new EnergySourceWireless(Lists.newArrayList((ILaserNode) this)), availableToSend, false);
                    EnergyUtil.otherModsEnergyExtract(tile, this.facing, transmitted, false);
                }
            }
        } else if (this.modeReceive == ReceiverMode.RECEIVE.ordinal() && this.storage.getEnergyStoredGC() > 0) {
            // One Beam Receiver might be powered by multiple transmitters - allow for 5 at maximum transfer rate
            float maxTransfer = Math.min(this.storage.getEnergyStoredGC(), maxRate * 5);
            if (maxTransfer < 0.01F) // Stop updating this when de minimis energy remains
            {
                this.storage.extractEnergyGCnoMax(maxTransfer, false);
            } else {
                TileEntity tileAdj = this.getAttachedTile();
                if (tileAdj instanceof TileBaseUniversalElectrical) {
                    TileBaseUniversalElectrical electricalTile = (TileBaseUniversalElectrical) tileAdj;
                    EnergySourceAdjacent source = new EnergySourceAdjacent(this.facing.getOpposite());
                    this.storage.extractEnergyGCnoMax(electricalTile.receiveEnergyGC(source, maxTransfer, false), false);
                } else if (!(tileAdj instanceof EnergyStorageTile) && !(tileAdj instanceof TileBaseConductor)) // Dont use other mods methods to connect Beam Receivers to GC's own wires or machines
                {
                    float otherModTransferred = EnergyUtil.otherModsEnergyTransfer(tileAdj, this.facing, maxTransfer, false);
                    if (otherModTransferred > 0F) {
                        this.storage.extractEnergyGCnoMax(otherModTransferred, false);
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILaserNode(micdoodle8.mods.galacticraft.api.power.ILaserNode) EnergySourceWireless(micdoodle8.mods.galacticraft.api.power.EnergySource.EnergySourceWireless) EnergySourceAdjacent(micdoodle8.mods.galacticraft.api.power.EnergySource.EnergySourceAdjacent)

Aggregations

EnergySourceAdjacent (micdoodle8.mods.galacticraft.api.power.EnergySource.EnergySourceAdjacent)1 EnergySourceWireless (micdoodle8.mods.galacticraft.api.power.EnergySource.EnergySourceWireless)1 ILaserNode (micdoodle8.mods.galacticraft.api.power.ILaserNode)1 TileEntity (net.minecraft.tileentity.TileEntity)1