From 7730649ab33322a9e96c5419172ebb633a004309 Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Mon, 16 Dec 2013 18:39:58 -0500 Subject: [PATCH] Pushing this before I forget - lots of printlns! --- common/mekanism/common/EnergyNetwork.java | 56 +++++++++++++------ .../common/multipart/PartUniversalCable.java | 10 +++- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/common/mekanism/common/EnergyNetwork.java b/common/mekanism/common/EnergyNetwork.java index d6502552d..5feafadf2 100644 --- a/common/mekanism/common/EnergyNetwork.java +++ b/common/mekanism/common/EnergyNetwork.java @@ -2,6 +2,7 @@ package mekanism.common; import ic2.api.energy.tile.IEnergySink; +import java.text.DecimalFormat; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -53,6 +54,11 @@ public class EnergyNetwork extends DynamicNetwork register(); } + public static double round(double d) + { + return Math.round(d * 100)/100; + } + public EnergyNetwork(Set networks) { for(EnergyNetwork net : networks) @@ -67,6 +73,7 @@ public class EnergyNetwork extends DynamicNetwork lastPowerScale = net.lastPowerScale; } + System.out.println("ADDING " + net.electricityStored); electricityStored += net.electricityStored; addAllTransmitters(net.transmitters); @@ -96,22 +103,31 @@ public class EnergyNetwork extends DynamicNetwork @Override public void onNetworksCreated(List networks) { - double[] caps = new double[networks.size()]; - double cap = 0; - - for(EnergyNetwork network : networks) + if(FMLCommonHandler.instance().getEffectiveSide().isServer()) { - caps[networks.indexOf(network)] = network.getCapacity(); - cap += network.getCapacity(); - } - - electricityStored = Math.min(cap, electricityStored); - - double[] percent = ListUtils.percent(caps); - - for(EnergyNetwork network : networks) - { - network.electricityStored = percent[networks.indexOf(network)]*electricityStored; + System.out.println("--start--"); + double[] caps = new double[networks.size()]; + double cap = 0; + + for(EnergyNetwork network : networks) + { + caps[networks.indexOf(network)] = network.getCapacity(); + cap += network.getCapacity(); + } + + System.out.println("capping at: " + cap); + electricityStored = Math.min(cap, electricityStored); + + double[] percent = ListUtils.percent(caps); + + for(EnergyNetwork network : networks) + { + System.out.println(electricityStored + " " + percent[networks.indexOf(network)]); + System.out.println("Setting to " + percent[networks.indexOf(network)]*electricityStored); + network.electricityStored = percent[networks.indexOf(network)]*electricityStored; + } + + System.out.println("--end--"); } } @@ -425,7 +441,13 @@ public class EnergyNetwork extends DynamicNetwork if(electricityStored > 0) { - electricityStored -= (electricityStored - tickEmit(electricityStored)); + double emitted = electricityStored - tickEmit(electricityStored); + electricityStored -= emitted; + + if(emitted > 0) + { + System.out.println(emitted); + } } } } @@ -455,6 +477,7 @@ public class EnergyNetwork extends DynamicNetwork network.joulesTransmitted = joulesTransmitted; network.lastPowerScale = lastPowerScale; network.electricityStored += electricityStored; + System.out.println("VAR ADDING " + electricityStored); return network; } @@ -467,6 +490,7 @@ public class EnergyNetwork extends DynamicNetwork network.joulesTransmitted = joulesTransmitted; network.lastPowerScale = lastPowerScale; network.electricityStored += electricityStored; + System.out.println("COLLECTION Adding " + electricityStored); return network; } diff --git a/common/mekanism/common/multipart/PartUniversalCable.java b/common/mekanism/common/multipart/PartUniversalCable.java index af096d240..9505d90af 100644 --- a/common/mekanism/common/multipart/PartUniversalCable.java +++ b/common/mekanism/common/multipart/PartUniversalCable.java @@ -35,6 +35,7 @@ public class PartUniversalCable extends PartTransmitter implement public double currentPower = 0; public double cacheEnergy = 0; + public double lastWrite = 0; @Override public void update() @@ -51,6 +52,7 @@ public class PartUniversalCable extends PartTransmitter implement else { if(cacheEnergy > 0) { + System.out.println("More cache " + cacheEnergy); getTransmitterNetwork().electricityStored += cacheEnergy; cacheEnergy = 0; } @@ -74,9 +76,10 @@ public class PartUniversalCable extends PartTransmitter implement double remains = getTransmitterNetwork().electricityStored%getTransmitterNetwork().getMeanCapacity(); double toSave = (getTransmitterNetwork().electricityStored-remains)/getTransmitterNetwork().getMeanCapacity(); - toSave += remains; + toSave = EnergyNetwork.round(toSave + remains); + System.out.println("SAVING " + toSave); - getTransmitterNetwork().electricityStored -= toSave; + lastWrite = toSave; nbtTags.setDouble("cacheEnergy", toSave); } @@ -96,6 +99,7 @@ public class PartUniversalCable extends PartTransmitter implement @Override public void preSingleMerge(EnergyNetwork network) { + System.out.println("Cache " + cacheEnergy); network.electricityStored += cacheEnergy; cacheEnergy = 0; } @@ -193,6 +197,8 @@ public class PartUniversalCable extends PartTransmitter implement { Mekanism.ic2Registered.remove(Object3D.get(tile())); MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile)tile())); + + getTransmitterNetwork().electricityStored -= lastWrite; } }