Pushing this before I forget - lots of printlns!

This commit is contained in:
Aidan Brady 2013-12-16 18:39:58 -05:00
parent bdf4efecda
commit 7730649ab3
2 changed files with 48 additions and 18 deletions

View file

@ -2,6 +2,7 @@ package mekanism.common;
import ic2.api.energy.tile.IEnergySink; import ic2.api.energy.tile.IEnergySink;
import java.text.DecimalFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -53,6 +54,11 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
register(); register();
} }
public static double round(double d)
{
return Math.round(d * 100)/100;
}
public EnergyNetwork(Set<EnergyNetwork> networks) public EnergyNetwork(Set<EnergyNetwork> networks)
{ {
for(EnergyNetwork net : networks) for(EnergyNetwork net : networks)
@ -67,6 +73,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
lastPowerScale = net.lastPowerScale; lastPowerScale = net.lastPowerScale;
} }
System.out.println("ADDING " + net.electricityStored);
electricityStored += net.electricityStored; electricityStored += net.electricityStored;
addAllTransmitters(net.transmitters); addAllTransmitters(net.transmitters);
@ -96,22 +103,31 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
@Override @Override
public void onNetworksCreated(List<EnergyNetwork> networks) public void onNetworksCreated(List<EnergyNetwork> networks)
{ {
double[] caps = new double[networks.size()]; if(FMLCommonHandler.instance().getEffectiveSide().isServer())
double cap = 0;
for(EnergyNetwork network : networks)
{ {
caps[networks.indexOf(network)] = network.getCapacity(); System.out.println("--start--");
cap += network.getCapacity(); double[] caps = new double[networks.size()];
} double cap = 0;
electricityStored = Math.min(cap, electricityStored); for(EnergyNetwork network : networks)
{
double[] percent = ListUtils.percent(caps); caps[networks.indexOf(network)] = network.getCapacity();
cap += network.getCapacity();
for(EnergyNetwork network : networks) }
{
network.electricityStored = percent[networks.indexOf(network)]*electricityStored; 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<TileEntity, EnergyNetwork>
if(electricityStored > 0) 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<TileEntity, EnergyNetwork>
network.joulesTransmitted = joulesTransmitted; network.joulesTransmitted = joulesTransmitted;
network.lastPowerScale = lastPowerScale; network.lastPowerScale = lastPowerScale;
network.electricityStored += electricityStored; network.electricityStored += electricityStored;
System.out.println("VAR ADDING " + electricityStored);
return network; return network;
} }
@ -467,6 +490,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
network.joulesTransmitted = joulesTransmitted; network.joulesTransmitted = joulesTransmitted;
network.lastPowerScale = lastPowerScale; network.lastPowerScale = lastPowerScale;
network.electricityStored += electricityStored; network.electricityStored += electricityStored;
System.out.println("COLLECTION Adding " + electricityStored);
return network; return network;
} }

View file

@ -35,6 +35,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
public double currentPower = 0; public double currentPower = 0;
public double cacheEnergy = 0; public double cacheEnergy = 0;
public double lastWrite = 0;
@Override @Override
public void update() public void update()
@ -51,6 +52,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
else { else {
if(cacheEnergy > 0) if(cacheEnergy > 0)
{ {
System.out.println("More cache " + cacheEnergy);
getTransmitterNetwork().electricityStored += cacheEnergy; getTransmitterNetwork().electricityStored += cacheEnergy;
cacheEnergy = 0; cacheEnergy = 0;
} }
@ -74,9 +76,10 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
double remains = getTransmitterNetwork().electricityStored%getTransmitterNetwork().getMeanCapacity(); double remains = getTransmitterNetwork().electricityStored%getTransmitterNetwork().getMeanCapacity();
double toSave = (getTransmitterNetwork().electricityStored-remains)/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); nbtTags.setDouble("cacheEnergy", toSave);
} }
@ -96,6 +99,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
@Override @Override
public void preSingleMerge(EnergyNetwork network) public void preSingleMerge(EnergyNetwork network)
{ {
System.out.println("Cache " + cacheEnergy);
network.electricityStored += cacheEnergy; network.electricityStored += cacheEnergy;
cacheEnergy = 0; cacheEnergy = 0;
} }
@ -193,6 +197,8 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
{ {
Mekanism.ic2Registered.remove(Object3D.get(tile())); Mekanism.ic2Registered.remove(Object3D.get(tile()));
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile)tile())); MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile)tile()));
getTransmitterNetwork().electricityStored -= lastWrite;
} }
} }