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 java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@ -53,6 +54,11 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
register();
}
public static double round(double d)
{
return Math.round(d * 100)/100;
}
public EnergyNetwork(Set<EnergyNetwork> networks)
{
for(EnergyNetwork net : networks)
@ -67,6 +73,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
lastPowerScale = net.lastPowerScale;
}
System.out.println("ADDING " + net.electricityStored);
electricityStored += net.electricityStored;
addAllTransmitters(net.transmitters);
@ -96,22 +103,31 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
@Override
public void onNetworksCreated(List<EnergyNetwork> 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<TileEntity, EnergyNetwork>
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.lastPowerScale = lastPowerScale;
network.electricityStored += electricityStored;
System.out.println("VAR ADDING " + electricityStored);
return network;
}
@ -467,6 +490,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
network.joulesTransmitted = joulesTransmitted;
network.lastPowerScale = lastPowerScale;
network.electricityStored += electricityStored;
System.out.println("COLLECTION Adding " + electricityStored);
return network;
}

View file

@ -35,6 +35,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> 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<EnergyNetwork> 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<EnergyNetwork> 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<EnergyNetwork> 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<EnergyNetwork> implement
{
Mekanism.ic2Registered.remove(Object3D.get(tile()));
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile)tile()));
getTransmitterNetwork().electricityStored -= lastWrite;
}
}