Search in sources :

Example 1 with EnergyStorageTile

use of micdoodle8.mods.galacticraft.core.energy.tile.EnergyStorageTile in project Galacticraft by micdoodle8.

the class TileEntityBeamReceiver method getAttachedTile.

public TileEntity getAttachedTile() {
    if (this.facing == null) {
        return null;
    }
    TileEntity tile = new BlockVec3(this).getTileEntityOnSide(this.worldObj, this.facing);
    if (tile == null || tile.isInvalid()) {
        this.setFacing(null);
    }
    if (tile instanceof IConductor) {
        this.setFacing(null);
        return null;
    }
    if (tile instanceof EnergyStorageTile) {
        EnergyStorage attachedStorage = ((EnergyStorageTile) tile).storage;
        this.storage.setCapacity(attachedStorage.getCapacityGC() - attachedStorage.getEnergyStoredGC());
        this.storage.setMaxExtract(attachedStorage.getMaxExtract());
        this.storage.setMaxReceive(attachedStorage.getMaxReceive());
    }
    return tile;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IConductor(micdoodle8.mods.galacticraft.api.transmission.tile.IConductor) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 2 with EnergyStorageTile

use of micdoodle8.mods.galacticraft.core.energy.tile.EnergyStorageTile in project Galacticraft by micdoodle8.

the class BlockBeamReceiver method getMetadataFromAngle.

private int getMetadataFromAngle(World world, BlockPos pos, EnumFacing side) {
    EnumFacing direction = side.getOpposite();
    TileEntity tileAt = world.getTileEntity(pos.add(direction.getFrontOffsetX(), direction.getFrontOffsetY(), direction.getFrontOffsetZ()));
    if (tileAt instanceof EnergyStorageTile) {
        if (((EnergyStorageTile) tileAt).getModeFromDirection(direction.getOpposite()) != null) {
            return direction.ordinal();
        } else {
            return -1;
        }
    }
    if (EnergyUtil.otherModCanReceive(tileAt, direction.getOpposite())) {
        return direction.ordinal();
    }
    for (EnumFacing adjacentDir : EnumFacing.VALUES) {
        if (adjacentDir == direction) {
            continue;
        }
        tileAt = world.getTileEntity(pos.add(adjacentDir.getFrontOffsetX(), adjacentDir.getFrontOffsetY(), adjacentDir.getFrontOffsetZ()));
        if (tileAt instanceof IConductor) {
            continue;
        }
        if (tileAt instanceof EnergyStorageTile && ((EnergyStorageTile) tileAt).getModeFromDirection(adjacentDir.getOpposite()) != null) {
            return adjacentDir.ordinal();
        }
        if (EnergyUtil.otherModCanReceive(tileAt, adjacentDir.getOpposite())) {
            return adjacentDir.ordinal();
        }
    }
    return -1;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IConductor(micdoodle8.mods.galacticraft.api.transmission.tile.IConductor) EnumFacing(net.minecraft.util.EnumFacing) EnergyStorageTile(micdoodle8.mods.galacticraft.core.energy.tile.EnergyStorageTile)

Example 3 with EnergyStorageTile

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

TileEntity (net.minecraft.tileentity.TileEntity)3 IConductor (micdoodle8.mods.galacticraft.api.transmission.tile.IConductor)2 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 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)1 EnergyStorageTile (micdoodle8.mods.galacticraft.core.energy.tile.EnergyStorageTile)1 EnumFacing (net.minecraft.util.EnumFacing)1