Cleaned up some code.

This commit is contained in:
CovertJaguar 2013-07-04 00:30:15 -07:00
parent 71c79606c0
commit 599afc578e
2 changed files with 30 additions and 20 deletions

View file

@ -10,7 +10,6 @@ package buildcraft.api.power;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.api.core.SafeTimeTracker;
import java.util.EnumSet;
public final class PowerHandler {

View file

@ -146,7 +146,12 @@ public class PipeTransportPower extends PipeTransport {
if (j != i && powerQuery[j] > 0) {
float watts = 0.0F;
if (tiles[j] instanceof TileGenericPipe) {
PowerReceiver prov = getReceiverOnSide(ForgeDirection.VALID_DIRECTIONS[j]);
if (prov != null && prov.powerRequest() > 0) {
watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
watts = prov.receiveEnergy(Type.PIPE, watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
internalPower[i] -= watts;
} else if (tiles[j] instanceof TileGenericPipe) {
watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
TileGenericPipe nearbyTile = (TileGenericPipe) tiles[j];
@ -154,15 +159,6 @@ public class PipeTransportPower extends PipeTransport {
watts = nearbyTransport.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), watts);
internalPower[i] -= watts;
} else if (tiles[j] instanceof IPowerReceptor) {
IPowerReceptor pow = (IPowerReceptor) tiles[j];
PowerReceiver prov = pow.getPowerReceiver(ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
if (prov != null && prov.getType().canReceiveFromPipes() && prov.powerRequest() > 0) {
watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
watts = prov.receiveEnergy(Type.PIPE, watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
internalPower[i] -= watts;
}
}
displayPower[j] += watts;
@ -188,18 +184,15 @@ public class PipeTransportPower extends PipeTransport {
overload = OVERLOAD_TICKS;
}
// Compute the tiles requesting energy that are not pipes
// Compute the tiles requesting energy that are not power pipes
for (int i = 0; i < 6; ++i) {
if (tiles[i] instanceof IPowerReceptor && !(tiles[i] instanceof TileGenericPipe)) {
IPowerReceptor receptor = (IPowerReceptor) tiles[i];
PowerReceiver prov = receptor.getPowerReceiver(ForgeDirection.VALID_DIRECTIONS[i].getOpposite());
if (prov != null && prov.getType().canReceiveFromPipes()) {
float request = prov.powerRequest();
PowerReceiver prov = getReceiverOnSide(ForgeDirection.VALID_DIRECTIONS[i]);
if (prov != null) {
float request = prov.powerRequest();
if (request > 0) {
requestEnergy(ForgeDirection.VALID_DIRECTIONS[i], request);
}
if (request > 0) {
requestEnergy(ForgeDirection.VALID_DIRECTIONS[i], request);
}
}
}
@ -256,6 +249,19 @@ public class PipeTransportPower extends PipeTransport {
}
private PowerReceiver getReceiverOnSide(ForgeDirection side) {
TileEntity tile = tiles[side.ordinal()];
if (!(tile instanceof IPowerReceptor))
return null;
IPowerReceptor receptor = (IPowerReceptor) tile;
PowerReceiver receiver = receptor.getPowerReceiver(side.getOpposite());
if (receiver == null)
return null;
if (!receiver.getType().canReceiveFromPipes())
return null;
return receiver;
}
public boolean isOverloaded() {
return overload >= OVERLOAD_TICKS;
}
@ -284,6 +290,11 @@ public class PipeTransportPower extends PipeTransport {
}
}
/**
* Do NOT ever call this from outside Buildcraft unless you are a pipe mod.
* It is NOT part of the API. All power input MUST go through designated
* input pipes, such as Wooden Power Pipes.
*/
public float receiveEnergy(ForgeDirection from, float val) {
step();
if (this.container.pipe instanceof IPipeTransportPowerHook) {