Search in sources :

Example 6 with TileBaseConductor

use of micdoodle8.mods.galacticraft.core.energy.tile.TileBaseConductor 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

BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)5 TileEntity (net.minecraft.tileentity.TileEntity)5 TileBaseConductor (micdoodle8.mods.galacticraft.core.energy.tile.TileBaseConductor)3 EnumFacing (net.minecraft.util.EnumFacing)3 IGridNetwork (micdoodle8.mods.galacticraft.api.transmission.grid.IGridNetwork)2 INetworkProvider (micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider)2 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)2 WorldProvider (net.minecraft.world.WorldProvider)2 GameProfile (com.mojang.authlib.GameProfile)1 Property (com.mojang.authlib.properties.Property)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 IOException (java.io.IOException)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 CelestialBody (micdoodle8.mods.galacticraft.api.galaxies.CelestialBody)1 Satellite (micdoodle8.mods.galacticraft.api.galaxies.Satellite)1 SolarSystem (micdoodle8.mods.galacticraft.api.galaxies.SolarSystem)1 EnumExtendedInventorySlot (micdoodle8.mods.galacticraft.api.item.EnumExtendedInventorySlot)1 EnergySourceAdjacent (micdoodle8.mods.galacticraft.api.power.EnergySource.EnergySourceAdjacent)1 EnergySourceWireless (micdoodle8.mods.galacticraft.api.power.EnergySource.EnergySourceWireless)1