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; package resonantinduction.battery;
import java.util.Iterator; import java.util.Arrays;
import universalelectricity.api.net.IConnector;
import calclavia.lib.multiblock.structure.Structure; import calclavia.lib.multiblock.structure.Structure;
public class BatteryStructure extends Structure<TileBattery> public class BatteryStructure extends Structure<TileBattery>
{ {
public void redistribute() public void redistribute(TileBattery... exclusion)
{ {
long totalEnergy = 0; long totalEnergy = 0;
@ -16,12 +15,18 @@ public class BatteryStructure extends Structure<TileBattery>
totalEnergy += battery.getEnergy(null); totalEnergy += battery.getEnergy(null);
} }
long totalPerBattery = totalEnergy / this.get().size(); int amountOfNodes = this.get().size() - exclusion.length;
long totalPerBatteryRemainder = totalPerBattery + totalEnergy % this.get().size();
if (totalEnergy > 0 && amountOfNodes > 0)
{
long totalPerBattery = totalEnergy / amountOfNodes;
long totalPerBatteryRemainder = totalPerBattery + totalEnergy % amountOfNodes;
TileBattery firstNode = this.getFirstNode(); TileBattery firstNode = this.getFirstNode();
for (TileBattery battery : this.get()) for (TileBattery battery : this.get())
{
if (!Arrays.asList(exclusion).contains(battery))
{ {
if (battery == firstNode) if (battery == firstNode)
{ {
@ -33,6 +38,8 @@ public class BatteryStructure extends Structure<TileBattery>
} }
} }
} }
}
}
@Override @Override
public Structure getNew() public Structure getNew()

View file

@ -32,10 +32,6 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
@Override @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) 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; return true;
} }

View file

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