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);
}
}
}
}
}
}
Aggregations