temporaily restore docking station support for an early 6.4.0 release

This commit is contained in:
asiekierka 2015-02-22 22:27:10 +01:00
parent e2ae3a349a
commit b04c93c4e2
3 changed files with 48 additions and 18 deletions

View file

@ -9,6 +9,7 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection;
import cofh.api.energy.IEnergyReceiver;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.render.ITextureStates;
import buildcraft.api.transport.IPipe;
@ -20,7 +21,7 @@ import buildcraft.core.utils.MatrixTranformations;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.TileGenericPipe;
public class RobotStationPluggable extends PipePluggable implements IPipePluggableItem {
public class RobotStationPluggable extends PipePluggable implements IPipePluggableItem, IEnergyReceiver {
public class RobotStationPluggableRenderer implements IPipePluggableRenderer {
private float zFightOffset = 1 / 4096.0F;
@ -251,4 +252,27 @@ public class RobotStationPluggable extends PipePluggable implements IPipePluggab
public PipePluggable createPipePluggable(IPipe pipe, ForgeDirection side, ItemStack stack) {
return new RobotStationPluggable();
}
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
if (station != null && station.isTaken()) {
return station.robotTaking().getBattery().receiveEnergy(maxReceive, simulate);
}
return 0;
}
@Override
public int getEnergyStored(ForgeDirection from) {
return 0;
}
@Override
public int getMaxEnergyStored(ForgeDirection from) {
return 0;
}
@Override
public boolean canConnectEnergy(ForgeDirection from) {
return true;
}
}

View file

@ -37,14 +37,6 @@ public class AIRobotRecharge extends AIRobot {
@Override
public void update() {
PipeTransportPower powerProvider = (PipeTransportPower) ((DockingStation) robot.getDockingStation()).getPipe().pipe.transport;
int amount = robot.getBattery().receiveEnergy(1000, true);
powerProvider.requestEnergy(robot.getDockingStation().side(), amount);
robot.getBattery().receiveEnergy(powerProvider.consumePower(robot.getDockingStation().side(), amount), false);
if (robot.getEnergy() >= EntityRobotBase.MAX_ENERGY) {
terminate();
}

View file

@ -175,6 +175,17 @@ public class PipeTransportPower extends PipeTransport {
}
}
private Object getEnergyProvider(int side) {
ForgeDirection fs = ForgeDirection.getOrientation(side);
if (container.hasPipePluggable(fs)) {
Object pp = container.getPipePluggable(fs);
if (pp instanceof IEnergyReceiver) {
return pp;
}
}
return tiles[side];
}
@Override
public void updateEntity() {
if (container.getWorldObj().isRemote) {
@ -206,31 +217,34 @@ public class PipeTransportPower extends PipeTransport {
if (internalPower[i] > 0) {
float totalPowerQuery = 0;
for (int j = 0; j < 6; ++j) {
if (j != i && powerQuery[j] > 0)
if (tiles[j] instanceof TileGenericPipe || tiles[j] instanceof IEnergyReceiver || tiles[j] instanceof IEnergyHandler) {
if (j != i && powerQuery[j] > 0) {
Object ep = getEnergyProvider(j);
if (ep instanceof TileGenericPipe || ep instanceof IEnergyReceiver || ep instanceof IEnergyHandler) {
totalPowerQuery += powerQuery[j];
}
}
}
for (int j = 0; j < 6; ++j) {
if (j != i && powerQuery[j] > 0) {
Object ep = getEnergyProvider(j);
int watts = (int) Math.floor((internalPower[i] * powerQuery[j]) / totalPowerQuery);
if (tiles[j] instanceof IPipeTile) {
Pipe<?> nearbyPipe = (Pipe<?>) ((IPipeTile) tiles[j]).getPipe();
if (ep instanceof IPipeTile) {
Pipe<?> nearbyPipe = (Pipe<?>) ((IPipeTile) ep).getPipe();
PipeTransportPower nearbyTransport = (PipeTransportPower) nearbyPipe.transport;
watts = nearbyTransport.receiveEnergy(
ForgeDirection.VALID_DIRECTIONS[j].getOpposite(),
watts);
internalPower[i] -= watts;
} else if (tiles[j] instanceof IEnergyHandler) {
IEnergyHandler handler = (IEnergyHandler) tiles[j];
} else if (ep instanceof IEnergyHandler) {
IEnergyHandler handler = (IEnergyHandler) ep;
if (handler.canConnectEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite())) {
watts = handler.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite(),
watts, false);
internalPower[i] -= watts;
}
} else if (tiles[j] instanceof IEnergyReceiver) {
IEnergyReceiver handler = (IEnergyReceiver) tiles[j];
} else if (ep instanceof IEnergyReceiver) {
IEnergyReceiver handler = (IEnergyReceiver) ep;
if (handler.canConnectEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite())) {
watts = handler.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite(),
watts, false);
@ -265,7 +279,7 @@ public class PipeTransportPower extends PipeTransport {
continue;
}
TileEntity tile = tiles [dir.ordinal()];
Object tile = getEnergyProvider(dir.ordinal());
if (tile instanceof IPipeTile && ((Pipe<?>) ((IPipeTile) tile).getPipe()).transport instanceof PipeTransportPower) {
continue;