From a3c6b9dac2e5173cd8312f189459ee973968ce01 Mon Sep 17 00:00:00 2001 From: "Aidan C. Brady" Date: Sat, 9 Aug 2014 13:28:40 -0400 Subject: [PATCH] Fixed cable functionality --- .../java/mekanism/common/EnergyNetwork.java | 6 +-- .../java/mekanism/common/util/CableUtils.java | 42 +++++++++---------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/main/java/mekanism/common/EnergyNetwork.java b/src/main/java/mekanism/common/EnergyNetwork.java index 7348cd443..2cfd5c4e7 100644 --- a/src/main/java/mekanism/common/EnergyNetwork.java +++ b/src/main/java/mekanism/common/EnergyNetwork.java @@ -143,7 +143,7 @@ public class EnergyNetwork extends DynamicNetwork tryAgain = false; double prev = sent; - sent += doEmit(energyToSend-sent); + sent += doEmit(energyToSend-sent, tryAgain); if(energyToSend-sent > 0 && sent-prev > 0) { @@ -165,7 +165,7 @@ public class EnergyNetwork extends DynamicNetwork /** * @return sent */ - public synchronized double doEmit(double energyToSend) + public synchronized double doEmit(double energyToSend, boolean tryAgain) { double sent = 0; @@ -210,7 +210,7 @@ public class EnergyNetwork extends DynamicNetwork toSend = Math.min(toSend, ((IEnergySink)acceptor).getDemandedEnergy()*Mekanism.FROM_IC2); sent += (toSend - (((IEnergySink)acceptor).injectEnergy(side.getOpposite(), toSend*Mekanism.TO_IC2, 0)*Mekanism.FROM_IC2)); } - else if(MekanismUtils.useBuildCraft() && MjAPI.getMjBattery(acceptor, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite()) != null) + else if(MekanismUtils.useBuildCraft() && MjAPI.getMjBattery(acceptor, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite()) != null && !tryAgain) { IBatteryObject battery = MjAPI.getMjBattery(acceptor, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite()); double toSend = battery.addEnergy(Math.min(battery.getEnergyRequested(), currentSending*Mekanism.TO_BC)); diff --git a/src/main/java/mekanism/common/util/CableUtils.java b/src/main/java/mekanism/common/util/CableUtils.java index a676801f8..fd1d76871 100644 --- a/src/main/java/mekanism/common/util/CableUtils.java +++ b/src/main/java/mekanism/common/util/CableUtils.java @@ -218,9 +218,9 @@ public final class CableUtils { if(!emitter.getWorldObj().isRemote && MekanismUtils.canFunction(emitter)) { - double sendingEnergy = Math.min(emitter.getEnergy(), emitter.getMaxOutput()); + double energyToSend = Math.min(emitter.getEnergy(), emitter.getMaxOutput()); - if(sendingEnergy > 0) + if(energyToSend > 0) { List outputtingSides = new ArrayList(); boolean[] connectable = getConnections(emitter, emitter.getOutputtingSides()); @@ -236,19 +236,19 @@ public final class CableUtils if(outputtingSides.size() > 0) { double sent = 0; - - boolean cont = false; + boolean tryAgain = false; do { - cont = false; + tryAgain = false; + double prev = sent; - sent += emit_do(emitter, outputtingSides, sendingEnergy-sent); + sent += emit_do(emitter, outputtingSides, energyToSend-sent, tryAgain); - if(sendingEnergy-sent > 0 && sent-prev > 0) + if(energyToSend-sent > 0 && sent-prev > 0) { - cont = true; + tryAgain = true; } - } while(cont); + } while(tryAgain); emitter.setEnergy(emitter.getEnergy() - sent); } @@ -256,7 +256,7 @@ public final class CableUtils } } - private static double emit_do(TileEntityElectricBlock emitter, List outputtingSides, double totalToSend) + private static double emit_do(TileEntityElectricBlock emitter, List outputtingSides, double totalToSend, boolean tryAgain) { double remains = totalToSend%outputtingSides.size(); double splitSend = (totalToSend-remains)/outputtingSides.size(); @@ -271,7 +271,7 @@ public final class CableUtils remains = 0; double prev = sent; - sent += emit_do_do(emitter, tileEntity, side, toSend); + sent += emit_do_do(emitter, tileEntity, side, toSend, tryAgain); if(sent-prev == 0) { @@ -287,7 +287,7 @@ public final class CableUtils return sent; } - private static double emit_do_do(TileEntityElectricBlock from, TileEntity tileEntity, ForgeDirection side, double sendingEnergy) + private static double emit_do_do(TileEntityElectricBlock from, TileEntity tileEntity, ForgeDirection side, double currentSending, boolean tryAgain) { double sent = 0; @@ -297,8 +297,7 @@ public final class CableUtils if(acceptor.canReceiveEnergy(side.getOpposite())) { - double prev = sent; - sent += acceptor.transferEnergyToAcceptor(side.getOpposite(), sendingEnergy); + sent += acceptor.transferEnergyToAcceptor(side.getOpposite(), currentSending); } } else if(MekanismUtils.useRF() && tileEntity instanceof IEnergyHandler) @@ -307,7 +306,7 @@ public final class CableUtils if(handler.canConnectEnergy(side.getOpposite())) { - int used = handler.receiveEnergy(side.getOpposite(), (int)Math.round(sendingEnergy*Mekanism.TO_TE), false); + int used = handler.receiveEnergy(side.getOpposite(), (int)Math.round(currentSending*Mekanism.TO_TE), false); sent += used*Mekanism.FROM_TE; } } @@ -315,17 +314,16 @@ public final class CableUtils { if(((IEnergySink)tileEntity).acceptsEnergyFrom(from, side.getOpposite())) { - double toSend = Math.min(sendingEnergy, Math.min(EnergyNet.instance.getPowerFromTier(((IEnergySink) tileEntity).getSinkTier()), ((IEnergySink)tileEntity).getDemandedEnergy())*Mekanism.FROM_IC2); - double rejects = ((IEnergySink)tileEntity).injectEnergy(side.getOpposite(), toSend*Mekanism.TO_IC2, 0)*Mekanism.FROM_IC2; - sent += (toSend - rejects); + double toSend = Math.min(currentSending, EnergyNet.instance.getPowerFromTier(((IEnergySink)tileEntity).getSinkTier())*Mekanism.FROM_IC2); + toSend = Math.min(toSend, ((IEnergySink)tileEntity).getDemandedEnergy()*Mekanism.FROM_IC2); + sent += (toSend - (((IEnergySink)tileEntity).injectEnergy(side.getOpposite(), toSend*Mekanism.TO_IC2, 0)*Mekanism.FROM_IC2)); } } - else if(MekanismUtils.useBuildCraft() && MjAPI.getMjBattery(tileEntity, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite()) != null) + else if(MekanismUtils.useBuildCraft() && MjAPI.getMjBattery(tileEntity, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite()) != null && !tryAgain) { IBatteryObject battery = MjAPI.getMjBattery(tileEntity, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite()); - double transferEnergy = Math.min(sendingEnergy, battery.getEnergyRequested()*Mekanism.FROM_BC); - double used = battery.addEnergy(transferEnergy*Mekanism.TO_BC); - sent += used*Mekanism.FROM_BC; + double toSend = battery.addEnergy(Math.min(battery.getEnergyRequested(), currentSending*Mekanism.TO_BC)); + sent += toSend*Mekanism.FROM_BC; } return sent;