use of micdoodle8.mods.galacticraft.api.power.ILaserNode in project Galacticraft by micdoodle8.
the class TileEntityBeamOutput method initiateReflector.
public void initiateReflector() {
this.nodeList.clear();
int chunkXMin = this.getPos().getX() - 15 >> 4;
int chunkZMin = this.getPos().getZ() - 15 >> 4;
int chunkXMax = this.getPos().getX() + 15 >> 4;
int chunkZMax = this.getPos().getZ() + 15 >> 4;
for (int cX = chunkXMin; cX <= chunkXMax; cX++) {
for (int cZ = chunkZMin; cZ <= chunkZMax; cZ++) {
if (this.worldObj.getChunkProvider().chunkExists(cX, cZ)) {
Chunk chunk = this.worldObj.getChunkFromChunkCoords(cX, cZ);
for (Object obj : chunk.getTileEntityMap().values()) {
if (obj != this && obj instanceof ILaserNode) {
BlockVec3 deltaPos = new BlockVec3(this).subtract(new BlockVec3(((ILaserNode) obj).getTile()));
if (deltaPos.x < 16 && deltaPos.y < 16 && deltaPos.z < 16) {
ILaserNode laserNode = (ILaserNode) obj;
if (this.canConnectTo(laserNode) && laserNode.canConnectTo(this)) {
this.addNode(laserNode);
laserNode.addNode(this);
}
}
}
}
}
}
}
this.setTarget(this.nodeList.peekFirst());
}
use of micdoodle8.mods.galacticraft.api.power.ILaserNode in project Galacticraft by micdoodle8.
the class TileEntityBeamOutput method addNode.
@Override
public void addNode(ILaserNode node) {
int index = -1;
for (int i = 0; i < this.nodeList.size(); i++) {
if (new BlockVec3(this.nodeList.get(i).getTile()).equals(new BlockVec3(node.getTile()))) {
index = i;
break;
}
}
if (index != -1) {
this.nodeList.set(index, node);
return;
}
if (this.nodeList.isEmpty()) {
this.nodeList.add(node);
} else {
int nodeCompare = this.nodeList.get(0).compareTo(node, new BlockVec3(this));
if (nodeCompare <= 0) {
this.nodeList.addFirst(node);
return;
}
nodeCompare = this.nodeList.get(this.nodeList.size() - 1).compareTo(node, new BlockVec3(this));
if (nodeCompare >= 0) {
this.nodeList.addLast(node);
return;
}
index = 1;
while (index < this.nodeList.size()) {
index++;
}
this.nodeList.add(index, node);
}
}
use of micdoodle8.mods.galacticraft.api.power.ILaserNode in project Galacticraft by micdoodle8.
the class TileEntityBeamOutput method update.
@Override
public void update() {
if (this.preLoadTarget != null) {
TileEntity tileAtTarget = this.worldObj.getTileEntity(this.preLoadTarget);
if (tileAtTarget != null && tileAtTarget instanceof ILaserNode) {
this.setTarget((ILaserNode) tileAtTarget);
this.preLoadTarget = null;
}
}
super.update();
if (!this.targetVec.equals(this.lastTargetVec)) {
this.markDirty();
}
this.lastTargetVec = this.targetVec;
if (this.worldObj.isRemote) {
this.updateOrientation();
} else if (this.targetVec.getX() == -1 && this.targetVec.getY() == -1 && this.targetVec.getZ() == -1) {
this.initiateReflector();
}
}
use of micdoodle8.mods.galacticraft.api.power.ILaserNode 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