Minor battery fixes

This commit is contained in:
Calclavia 2014-01-03 23:48:47 +08:00
parent 59bf99c105
commit f6a9cbd5a0
3 changed files with 24 additions and 20 deletions

View file

@ -1,13 +1,12 @@
package resonantinduction.battery;
import java.util.Iterator;
import java.util.Arrays;
import universalelectricity.api.net.IConnector;
import calclavia.lib.multiblock.structure.Structure;
public class BatteryStructure extends Structure<TileBattery>
{
public void redistribute()
public void redistribute(TileBattery... exclusion)
{
long totalEnergy = 0;
@ -15,21 +14,29 @@ public class BatteryStructure extends Structure<TileBattery>
{
totalEnergy += battery.getEnergy(null);
}
int amountOfNodes = this.get().size() - exclusion.length;
long totalPerBattery = totalEnergy / this.get().size();
long totalPerBatteryRemainder = totalPerBattery + totalEnergy % this.get().size();
TileBattery firstNode = this.getFirstNode();
for (TileBattery battery : this.get())
if (totalEnergy > 0 && amountOfNodes > 0)
{
if (battery == firstNode)
long totalPerBattery = totalEnergy / amountOfNodes;
long totalPerBatteryRemainder = totalPerBattery + totalEnergy % amountOfNodes;
TileBattery firstNode = this.getFirstNode();
for (TileBattery battery : this.get())
{
battery.setEnergy(null, totalPerBatteryRemainder);
}
else
{
battery.setEnergy(null, totalPerBattery);
if (!Arrays.asList(exclusion).contains(battery))
{
if (battery == firstNode)
{
battery.setEnergy(null, totalPerBatteryRemainder);
}
else
{
battery.setEnergy(null, totalPerBattery);
}
}
}
}
}

View file

@ -32,10 +32,6 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
if (!world.isRemote)
{
System.out.println(((TileBattery) world.getBlockTileEntity(x, y, z)).getNetwork().hashCode());
}
return true;
}

View file

@ -75,7 +75,7 @@ public class TileBattery extends TileElectrical implements IConnector<BatteryStr
if (!this.worldObj.isRemote)
{
if (this.getNetwork().getFirstNode() == this)
if (this.ticks % 10 == 0 && this.getNetwork().getFirstNode() == this)
{
this.getNetwork().redistribute();
}
@ -146,6 +146,7 @@ public class TileBattery extends TileElectrical implements IConnector<BatteryStr
@Override
public void invalidate()
{
this.getNetwork().redistribute(this);
this.getNetwork().split(this);
super.invalidate();
}