From b04c93c4e2537345bc38a3e3fef1bad88dca9e75 Mon Sep 17 00:00:00 2001 From: asiekierka Date: Sun, 22 Feb 2015 22:27:10 +0100 Subject: [PATCH] temporaily restore docking station support for an early 6.4.0 release --- .../robots/RobotStationPluggable.java | 26 ++++++++++++++- .../buildcraft/robots/ai/AIRobotRecharge.java | 8 ----- .../transport/PipeTransportPower.java | 32 +++++++++++++------ 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/common/buildcraft/robots/RobotStationPluggable.java b/common/buildcraft/robots/RobotStationPluggable.java index 42ce289c..e083afd1 100644 --- a/common/buildcraft/robots/RobotStationPluggable.java +++ b/common/buildcraft/robots/RobotStationPluggable.java @@ -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; + } } diff --git a/common/buildcraft/robots/ai/AIRobotRecharge.java b/common/buildcraft/robots/ai/AIRobotRecharge.java index f2c03f70..f04e00e7 100755 --- a/common/buildcraft/robots/ai/AIRobotRecharge.java +++ b/common/buildcraft/robots/ai/AIRobotRecharge.java @@ -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(); } diff --git a/common/buildcraft/transport/PipeTransportPower.java b/common/buildcraft/transport/PipeTransportPower.java index feb2b510..8ad89ad3 100644 --- a/common/buildcraft/transport/PipeTransportPower.java +++ b/common/buildcraft/transport/PipeTransportPower.java @@ -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;